~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/status.cc

Blackhole, CSV, Pool of Threads,Single Thread, Multi Thread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
/**
 
22
 * @file 
 
23
 *   status I_S table methods.
 
24
 */
 
25
 
 
26
#include "drizzled/server_includes.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/show.h"
 
29
#include "drizzled/tztime.h"
 
30
 
 
31
#include "helper_methods.h"
 
32
#include "status.h"
 
33
 
 
34
#include <vector>
 
35
 
 
36
using namespace drizzled;
 
37
using namespace std;
 
38
 
 
39
/*
 
40
 * Vectors of columns for the status I_S tables.
 
41
 */
 
42
vector<const plugin::ColumnInfo *> *status_columns= NULL;
 
43
 
 
44
/*
 
45
 * Methods for the status related I_S tables.
 
46
 */
 
47
static plugin::InfoSchemaMethods *methods= NULL;
 
48
 
 
49
/*
 
50
 * status I_S tables.
 
51
 */
 
52
static plugin::InfoSchemaTable *glob_status_table= NULL;
 
53
static plugin::InfoSchemaTable *sess_status_table= NULL;
 
54
static plugin::InfoSchemaTable *status_table= NULL;
 
55
 
 
56
/**
 
57
 * Populate the vectors of columns for the I_S table.
 
58
 *
 
59
 * @return a pointer to a std::vector of Columns.
 
60
 */
 
61
vector<const plugin::ColumnInfo *> *GlobalStatusIS::createColumns()
 
62
{
 
63
  if (status_columns == NULL)
 
64
  {
 
65
    status_columns= new vector<const plugin::ColumnInfo *>;
 
66
  }
 
67
  else
 
68
  {
 
69
    clearColumns(*status_columns);
 
70
  }
 
71
 
 
72
  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_NAME",
 
73
                                                   64,
 
74
                                                   DRIZZLE_TYPE_VARCHAR,
 
75
                                                   0,
 
76
                                                   0,
 
77
                                                   "Variable_name"));
 
78
 
 
79
  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_VALUE",
 
80
                                                   16300,
 
81
                                                   DRIZZLE_TYPE_VARCHAR,
 
82
                                                   0,
 
83
                                                   1,
 
84
                                                   "Value"));
 
85
 
 
86
  return status_columns;
 
87
}
 
88
 
 
89
/**
 
90
 * Initialize the I_S table.
 
91
 *
 
92
 * @return a pointer to an I_S table
 
93
 */
 
94
plugin::InfoSchemaTable *GlobalStatusIS::getTable()
 
95
{
 
96
  status_columns= createColumns();
 
97
 
 
98
  if (methods == NULL)
 
99
  {
 
100
    methods= new StatusISMethods();
 
101
  }
 
102
 
 
103
  if (glob_status_table == NULL)
 
104
  {
 
105
    glob_status_table= new plugin::InfoSchemaTable("GLOBAL_STATUS",
 
106
                                                   *status_columns,
 
107
                                                   -1, -1, false, false,
 
108
                                                   0, 
 
109
                                                   methods);
 
110
  }
 
111
 
 
112
  return glob_status_table;
 
113
}
 
114
 
 
115
/**
 
116
 * Delete memory allocated for the table, columns and methods.
 
117
 */
 
118
void GlobalStatusIS::cleanup()
 
119
{
 
120
  clearColumns(*status_columns);
 
121
  delete glob_status_table;
 
122
  delete methods;
 
123
  delete status_columns;
 
124
}
 
125
 
 
126
/**
 
127
 * Initialize the I_S table.
 
128
 *
 
129
 * @return a pointer to an I_S table
 
130
 */
 
131
plugin::InfoSchemaTable *SessionStatusIS::getTable()
 
132
{
 
133
  if (sess_status_table == NULL)
 
134
  {
 
135
    sess_status_table= new plugin::InfoSchemaTable("SESSION_STATUS",
 
136
                                                   *status_columns,
 
137
                                                   -1, -1, false, false,
 
138
                                                   0, 
 
139
                                                   methods);
 
140
  }
 
141
 
 
142
  return sess_status_table;
 
143
}
 
144
 
 
145
/**
 
146
 * Delete memory allocated for the table, columns and methods.
 
147
 */
 
148
void SessionStatusIS::cleanup()
 
149
{
 
150
  delete sess_status_table;
 
151
}
 
152
 
 
153
/**
 
154
 * Initialize the I_S table.
 
155
 *
 
156
 * @return a pointer to an I_S table
 
157
 */
 
158
plugin::InfoSchemaTable *StatusIS::getTable()
 
159
{
 
160
  if (status_table == NULL)
 
161
  {
 
162
    status_table= new plugin::InfoSchemaTable("STATUS",
 
163
                                              *status_columns,
 
164
                                              -1, -1, true, false, 0,
 
165
                                              methods);
 
166
  }
 
167
 
 
168
  return status_table;
 
169
}
 
170
 
 
171
/**
 
172
 * Delete memory allocated for the table, columns and methods.
 
173
 */
 
174
void StatusIS::cleanup()
 
175
{
 
176
  delete status_table;
 
177
}
 
178
 
 
179
int StatusISMethods::fillTable(Session *session, 
 
180
                               Table *table,
 
181
                               plugin::InfoSchemaTable *schema_table)
 
182
{
 
183
  LEX *lex= session->lex;
 
184
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
185
  int res= 0;
 
186
  STATUS_VAR *tmp1, tmp;
 
187
  const string schema_table_name= schema_table->getTableName();
 
188
  enum enum_var_type option_type;
 
189
  bool upper_case_names= (schema_table_name.compare("STATUS") != 0);
 
190
 
 
191
  if (schema_table_name.compare("STATUS") == 0)
 
192
  {
 
193
    option_type= lex->option_type;
 
194
    if (option_type == OPT_GLOBAL)
 
195
    {
 
196
      tmp1= &tmp;
 
197
    }
 
198
    else
 
199
    {
 
200
      tmp1= session->initial_status_var;
 
201
    }
 
202
  }
 
203
  else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
 
204
  {
 
205
    option_type= OPT_GLOBAL;
 
206
    tmp1= &tmp;
 
207
  }
 
208
  else
 
209
  {
 
210
    option_type= OPT_SESSION;
 
211
    tmp1= &session->status_var;
 
212
  }
 
213
 
 
214
  pthread_mutex_lock(&LOCK_status);
 
215
  if (option_type == OPT_GLOBAL)
 
216
  {
 
217
    calc_sum_of_all_status(&tmp);
 
218
  }
 
219
  res= show_status_array(session, wild,
 
220
                         getFrontOfStatusVars(),
 
221
                         option_type, tmp1, "", table,
 
222
                         upper_case_names,
 
223
                         schema_table);
 
224
  pthread_mutex_unlock(&LOCK_status);
 
225
  return res;
 
226
}
 
227