~drizzle-trunk/drizzle/development

1273.13.5 by Brian Aker
Additional definitions.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 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
1273.14.5 by Monty Taylor
Merged trunk.
21
#include "config.h"
22
1273.13.50 by Brian Aker
Additional plugins.
23
#include "plugin/status_dictionary/dictionary.h"
24
1273.13.22 by Brian Aker
Added status bits. Variables next!
25
#include <drizzled/pthread_globals.h>
26
#include <drizzled/internal/m_string.h>
27
#include <drizzled/definitions.h>
28
29
#include <vector>
30
#include <string>
31
#include <sstream>
1273.13.5 by Brian Aker
Additional definitions.
32
33
using namespace std;
34
using namespace drizzled;
35
1273.13.24 by Brian Aker
Updating style, simplified code.
36
StateTool::StateTool(const char *arg, bool global) :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
37
  plugin::TableFunction("DATA_DICTIONARY", arg),
1273.13.24 by Brian Aker
Updating style, simplified code.
38
  option_type(global ? OPT_GLOBAL : OPT_SESSION)
1273.13.22 by Brian Aker
Added status bits. Variables next!
39
{
40
  add_field("VARIABLE_NAME");
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
41
  add_field("VARIABLE_VALUE", 1024);
1273.13.22 by Brian Aker
Added status bits. Variables next!
42
}
43
1273.13.24 by Brian Aker
Updating style, simplified code.
44
StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
45
                                drizzle_show_var *variables_args,
46
                                bool status_arg) :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
47
  plugin::TableFunction::Generator(arg),
1273.13.24 by Brian Aker
Updating style, simplified code.
48
  option_type(option_arg),
49
  has_status(status_arg),
1273.13.22 by Brian Aker
Added status bits. Variables next!
50
  variables(variables_args)
51
{
1273.13.24 by Brian Aker
Updating style, simplified code.
52
  if (not has_status)
1273.13.23 by Brian Aker
Variables support.
53
  {
54
    status_ptr= NULL;
1273.13.24 by Brian Aker
Updating style, simplified code.
55
    pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1273.13.23 by Brian Aker
Variables support.
56
  }
1273.13.24 by Brian Aker
Updating style, simplified code.
57
  else if (option_type == OPT_GLOBAL  && has_status)
1273.13.23 by Brian Aker
Variables support.
58
  {
59
    status_ptr= &status;
1273.13.24 by Brian Aker
Updating style, simplified code.
60
    pthread_mutex_lock(&LOCK_status);
61
    calc_sum_of_all_status(&status);
1273.13.23 by Brian Aker
Variables support.
62
  }
63
  else
64
  {
65
    Session *session= current_session;
66
    status_ptr= &session->status_var;
67
  }
1273.13.22 by Brian Aker
Added status bits. Variables next!
68
}
69
1273.13.24 by Brian Aker
Updating style, simplified code.
70
StateTool::Generator::~Generator()
1273.13.22 by Brian Aker
Added status bits. Variables next!
71
{
1273.13.24 by Brian Aker
Updating style, simplified code.
72
  if (not has_status)
73
  {
74
    pthread_rwlock_unlock(&LOCK_system_variables_hash);
75
  }
76
  else if (option_type == OPT_GLOBAL)
77
  {
78
    pthread_mutex_unlock(&LOCK_status);
79
  }
1273.13.22 by Brian Aker
Added status bits. Variables next!
80
}
81
1273.13.24 by Brian Aker
Updating style, simplified code.
82
bool StateTool::Generator::populate()
1273.13.22 by Brian Aker
Added status bits. Variables next!
83
{
84
  while (variables && variables->name)
85
  {
86
    drizzle_show_var *var;
87
    MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
88
    char * const buff= (char *) &buff_data;
89
90
    /*
91
      if var->type is SHOW_FUNC, call the function.
92
      Repeat as necessary, if new var is again SHOW_FUNC
93
    */
94
    {
95
      drizzle_show_var tmp;
96
97
      for (var= variables; var->type == SHOW_FUNC; var= &tmp)
98
        ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
99
    }
100
1273.13.59 by Brian Aker
Updates for VARIABLES
101
    if (isWild(variables->name))
102
    {
103
      variables++;
104
      continue;
105
    }
1273.13.76 by Brian Aker
Remove dead SHOW_ARRAY type.
106
107
    fill(variables->name, var->value, var->type);
1273.13.22 by Brian Aker
Added status bits. Variables next!
108
109
    variables++;
110
111
    return true;
112
  }
113
114
  return false;
115
}
1273.13.24 by Brian Aker
Updating style, simplified code.
116
117
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
118
extern drizzled::KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
119
void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
1273.13.22 by Brian Aker
Added status bits. Variables next!
120
{
121
  Session *session= current_session;
122
  struct system_status_var *status_var;
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
123
  std::ostringstream oss;
124
125
126
  std::string return_value;
1273.13.22 by Brian Aker
Added status bits. Variables next!
127
128
  /* Scope represents if the status should be session or global */
129
  status_var= getStatus();
130
1273.13.24 by Brian Aker
Updating style, simplified code.
131
  pthread_mutex_lock(&LOCK_global_system_variables);
132
1273.13.22 by Brian Aker
Added status bits. Variables next!
133
  if (show_type == SHOW_SYS)
134
  {
135
    show_type= ((sys_var*) value)->show_type();
136
    value= (char*) ((sys_var*) value)->value_ptr(session, option_type,
137
                                                 &null_lex_str);
138
  }
139
140
  /*
141
    note that value may be == buff. All SHOW_xxx code below
142
    should still work in this case
143
  */
144
  switch (show_type) {
145
  case SHOW_DOUBLE_STATUS:
146
    value= ((char *) status_var + (ulong) value);
147
    /* fall through */
148
  case SHOW_DOUBLE:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
149
    oss.precision(6);
150
    oss << *(double *) value;
151
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
152
    break;
153
  case SHOW_LONG_STATUS:
154
    value= ((char *) status_var + (ulong) value);
155
    /* fall through */
156
  case SHOW_LONG:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
157
    oss << *(int64_t*) value;
158
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
159
    break;
160
  case SHOW_LONGLONG_STATUS:
161
    value= ((char *) status_var + (uint64_t) value);
162
    /* fall through */
163
  case SHOW_LONGLONG:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
164
    oss << *(int64_t*) value;
165
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
166
    break;
167
  case SHOW_SIZE:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
168
    oss << *(size_t*) value;
169
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
170
    break;
171
  case SHOW_HA_ROWS:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
172
    oss << (int64_t) *(ha_rows*) value;
173
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
174
    break;
175
  case SHOW_BOOL:
176
  case SHOW_MY_BOOL:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
177
    return_value= *(bool*) value ? "ON" : "OFF";
1273.13.22 by Brian Aker
Added status bits. Variables next!
178
    break;
179
  case SHOW_INT:
180
  case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
181
    oss << (long) *(uint32_t*) value;
182
    return_value= oss.str();
1273.13.22 by Brian Aker
Added status bits. Variables next!
183
    break;
184
  case SHOW_CHAR:
185
    {
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
186
      if (value)
187
        return_value= value;
1273.13.22 by Brian Aker
Added status bits. Variables next!
188
      break;
189
    }
190
  case SHOW_CHAR_PTR:
191
    {
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
192
      if (*(char**) value)
193
        return_value= *(char**) value;
194
1273.13.22 by Brian Aker
Added status bits. Variables next!
195
      break;
196
    }
197
  case SHOW_KEY_CACHE_LONG:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
198
    value= (char*) dflt_key_cache + (unsigned long)value;
199
    oss << *(long*) value;
200
    return_value= oss.str();
201
    break;
1273.13.22 by Brian Aker
Added status bits. Variables next!
202
  case SHOW_KEY_CACHE_LONGLONG:
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
203
    value= (char*) dflt_key_cache + (unsigned long)value;
204
    oss << *(int64_t*) value;
205
    return_value= oss.str();
206
    break;
1273.13.22 by Brian Aker
Added status bits. Variables next!
207
  case SHOW_UNDEF:
208
    break;                                        // Return empty string
209
  case SHOW_SYS:                                  // Cannot happen
210
  default:
211
    assert(0);
212
    break;
213
  }
1273.13.24 by Brian Aker
Updating style, simplified code.
214
  pthread_mutex_unlock(&LOCK_global_system_variables);
1273.13.22 by Brian Aker
Added status bits. Variables next!
215
  push(name);
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
216
  if (return_value.length())
217
    push(return_value);
1273.13.46 by Brian Aker
Fixes valgrind issue with status variables.
218
  else 
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
219
    push(" ");
1273.13.5 by Brian Aker
Additional definitions.
220
}