1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
* proceslist I_S table methods.
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
#include "drizzled/plugin/client.h"
30
#include "drizzled/session_list.h"
31
#include "drizzled/pthread_globals.h"
32
#include "drizzled/internal/my_sys.h"
34
#include "helper_methods.h"
35
#include "processlist.h"
39
#define LIST_PROCESS_HOST_LEN 64
41
using namespace drizzled;
45
* Vectors of columns for the processlist I_S table.
47
static vector<const plugin::ColumnInfo *> *columns= NULL;
50
* Methods for the processlist I_S table.
52
static plugin::InfoSchemaMethods *methods= NULL;
55
* processlist I_S table.
57
static plugin::InfoSchemaTable *pl_table= NULL;
60
* Populate the vectors of columns for the I_S table.
62
* @return a pointer to a std::vector of Columns.
64
vector<const plugin::ColumnInfo *> *ProcessListIS::createColumns()
68
columns= new vector<const plugin::ColumnInfo *>;
72
clearColumns(*columns);
76
* Create each column for the PROCESSLIST table.
78
columns->push_back(new plugin::ColumnInfo("ID",
80
DRIZZLE_TYPE_LONGLONG,
85
columns->push_back(new plugin::ColumnInfo("USER",
92
columns->push_back(new plugin::ColumnInfo("HOST",
93
LIST_PROCESS_HOST_LEN,
99
columns->push_back(new plugin::ColumnInfo("DB",
101
DRIZZLE_TYPE_VARCHAR,
106
columns->push_back(new plugin::ColumnInfo("COMMAND",
108
DRIZZLE_TYPE_VARCHAR,
113
columns->push_back(new plugin::ColumnInfo("TIME",
115
DRIZZLE_TYPE_LONGLONG,
120
columns->push_back(new plugin::ColumnInfo("STATE",
122
DRIZZLE_TYPE_VARCHAR,
127
columns->push_back(new plugin::ColumnInfo("INFO",
129
DRIZZLE_TYPE_VARCHAR,
138
* Initialize the I_S table.
140
* @return a pointer to an I_S table
142
plugin::InfoSchemaTable *ProcessListIS::getTable()
144
columns= createColumns();
148
methods= new ProcessListISMethods();
151
if (pl_table == NULL)
153
pl_table= new plugin::InfoSchemaTable("OLD_PROCESSLIST",
155
-1, -1, false, false, 0,
163
* Delete memory allocated for the table, columns and methods.
165
void ProcessListIS::cleanup()
167
clearColumns(*columns);
173
int ProcessListISMethods::fillTable(Session* session,
175
plugin::InfoSchemaTable *schema_table)
177
const CHARSET_INFO * const cs= system_charset_info;
178
time_t now= time(NULL);
181
if (now == (time_t)-1)
184
pthread_mutex_lock(&LOCK_thread_count);
186
if (! session->killed)
190
for (vector<Session*>::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it)
193
Security_context *tmp_sctx= &tmp->security_ctx;
194
struct st_my_thread_var *mysys_var;
197
if (! tmp->client->isConnected())
200
table->restoreRecordAsDefault();
201
table->setWriteSet(0);
202
table->setWriteSet(1);
203
table->setWriteSet(2);
204
table->setWriteSet(3);
205
table->setWriteSet(4);
206
table->setWriteSet(5);
207
table->setWriteSet(6);
208
table->setWriteSet(7);
210
table->field[0]->store((int64_t) tmp->thread_id, true);
212
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
213
table->field[1]->store(val, strlen(val), cs);
215
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
217
if (! tmp->db.empty())
219
table->field[3]->store(tmp->db.c_str(), tmp->db.length(), cs);
220
table->field[3]->set_notnull();
223
if ((mysys_var= tmp->mysys_var))
224
pthread_mutex_lock(&mysys_var->mutex);
226
if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
227
table->field[4]->store(val, strlen(val), cs);
229
table->field[4]->store(command_name[tmp->command].str,
230
command_name[tmp->command].length, cs);
232
table->field[5]->store((uint32_t)(tmp->start_time ?
233
now - tmp->start_time : 0), true);
235
val= (char*) (tmp->client->isWriting() ?
237
tmp->client->isReading() ?
238
(tmp->command == COM_SLEEP ?
239
NULL : "Reading from net") :
240
tmp->get_proc_info() ? tmp->get_proc_info() :
242
tmp->mysys_var->current_cond ?
243
"Waiting on cond" : NULL);
246
table->field[6]->store(val, strlen(val), cs);
247
table->field[6]->set_notnull();
251
pthread_mutex_unlock(&mysys_var->mutex);
253
length= strlen(tmp->process_list_info);
257
table->field[7]->store(tmp->process_list_info, length, cs);
258
table->field[7]->set_notnull();
261
schema_table->addRow(table->record[0], table->s->reclength);
265
pthread_mutex_unlock(&LOCK_thread_count);