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
22
* @file Implementation of the I_S tables.
25
#include <drizzled/server_includes.h>
26
#include <drizzled/session.h>
27
#include <drizzled/show.h>
29
#include "info_schema_plugin.h"
31
#define LIST_PROCESS_HOST_LEN 64
35
int ProcessListISMethods::fillTable(Session* session, TableList* tables, COND*)
37
Table *table= tables->table;
38
const CHARSET_INFO * const cs= system_charset_info;
39
time_t now= time(NULL);
42
if (now == (time_t)-1)
45
pthread_mutex_lock(&LOCK_thread_count);
51
for (vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it)
54
Security_context *tmp_sctx= &tmp->security_ctx;
55
struct st_my_thread_var *mysys_var;
58
if (! tmp->protocol->isConnected())
61
table->restoreRecordAsDefault();
63
table->field[0]->store((int64_t) tmp->thread_id, true);
65
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
66
table->field[1]->store(val, strlen(val), cs);
68
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
72
table->field[3]->store(tmp->db, strlen(tmp->db), cs);
73
table->field[3]->set_notnull();
76
if ((mysys_var= tmp->mysys_var))
77
pthread_mutex_lock(&mysys_var->mutex);
79
if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
80
table->field[4]->store(val, strlen(val), cs);
82
table->field[4]->store(command_name[tmp->command].str,
83
command_name[tmp->command].length, cs);
85
table->field[5]->store((uint32_t)(tmp->start_time ?
86
now - tmp->start_time : 0), true);
88
val= (char*) (tmp->protocol->isWriting() ?
90
tmp->protocol->isReading() ?
91
(tmp->command == COM_SLEEP ?
92
NULL : "Reading from net") :
93
tmp->get_proc_info() ? tmp->get_proc_info() :
95
tmp->mysys_var->current_cond ?
96
"Waiting on cond" : NULL);
99
table->field[6]->store(val, strlen(val), cs);
100
table->field[6]->set_notnull();
104
pthread_mutex_unlock(&mysys_var->mutex);
106
length= strlen(tmp->process_list_info);
110
table->field[7]->store(tmp->process_list_info, length, cs);
111
table->field[7]->set_notnull();
114
if (schema_table_store_record(session, table))
116
pthread_mutex_unlock(&LOCK_thread_count);
122
pthread_mutex_unlock(&LOCK_thread_count);
127
* The various fields for the PROCESSLIST I_S table.
129
static FieldInfo processlist_fields_info[]=
131
FieldInfo("ID", 4, DRIZZLE_TYPE_LONGLONG,
132
0, 0, "Id", SKIP_OPEN_TABLE),
133
FieldInfo("USER", 16, DRIZZLE_TYPE_VARCHAR,
134
0, 0, "User", SKIP_OPEN_TABLE),
135
FieldInfo("HOST", LIST_PROCESS_HOST_LEN, DRIZZLE_TYPE_VARCHAR,
136
0, 0, "Host", SKIP_OPEN_TABLE),
137
FieldInfo("DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR,
138
0, 1, "Db", SKIP_OPEN_TABLE),
139
FieldInfo("COMMAND", 16, DRIZZLE_TYPE_VARCHAR,
140
0, 0, "Command", SKIP_OPEN_TABLE),
141
FieldInfo("TIME", 7, DRIZZLE_TYPE_LONGLONG,
142
0, 0, "Time", SKIP_OPEN_TABLE),
143
FieldInfo("STATE", 64, DRIZZLE_TYPE_VARCHAR,
144
0, 1, "State", SKIP_OPEN_TABLE),
145
FieldInfo("INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR,
146
0, 1, "Info", SKIP_OPEN_TABLE),
151
* List of methods for various I_S tables.
153
static InfoSchemaMethods *processlist_methods= NULL;
156
* List of I_S tables.
158
static InfoSchemaTable *processlist_table= NULL;
161
* Initialize the methods for each I_S table.
163
* @return false on success; true on failure
165
bool initTableMethods()
167
processlist_methods= new ProcessListISMethods();
173
* Delete memory allocated for the I_S table methods.
175
void cleanupTableMethods()
177
delete processlist_methods;
181
* Initialize the I_S tables.
183
* @return false on success; true on failure
188
processlist_table= new InfoSchemaTable("PROCESSLIST",
189
processlist_fields_info,
190
-1, -1, false, false, 0,
191
processlist_methods);
197
* Delete memory allocated for the I_S tables.
201
delete processlist_table;
205
* Initialize the I_S plugin.
207
* @param[in] registry the PluginRegistry singleton
208
* @return 0 on success; 1 on failure.
210
int infoSchemaInit(PluginRegistry& registry)
212
if (initTableMethods())
222
registry.add(processlist_table);
228
* Clean up the I_S plugin.
230
* @param[in] registry the PluginRegistry singleton
231
* @return 0 on success; 1 on failure
233
int infoSchemaDone(PluginRegistry& registry)
235
registry.remove(processlist_table);
237
cleanupTableMethods();
243
drizzle_declare_plugin(info_schema)
247
"Padraig O'Sullivan",
256
drizzle_declare_plugin_end;