~drizzle-trunk/drizzle/development

1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
1
/*
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
2
 * Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *   * Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
11
 *     this list of conditions and the following disclaimer in the documentation
12
 *     and/or other materials provided with the distribution.
13
 *   * Neither the name of Joseph Daly nor the names of its contributors
14
 *     may be used to endorse or promote products derived from this software
15
 *     without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
1561.3.24 by Joe Daly
update comments in various files
30
/**
31
 * @details
32
 *
33
 * This class defines the "show status" and "show global status" 
34
 * DATA_DICTIONARY tables:
35
 * 
36
 * drizzle> describe SESSION_STATUS;
37
 * +----------------+---------+-------+---------+-----------------+-----------+
38
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
39
 * +----------------+---------+-------+---------+-----------------+-----------+
40
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           | 
41
 * | VARIABLE_VALUE | VARCHAR | FALSE |         | FALSE           |           | 
42
 * +----------------+---------+-------+---------+-----------------+-----------+
43
 *
44
 * drizzle> describe GLOBAL_STATUS;
45
 * +----------------+---------+-------+---------+-----------------+-----------+
46
 * | Field          | Type    | Null  | Default | Default_is_NULL | On_Update |
47
 * +----------------+---------+-------+---------+-----------------+-----------+
48
 * | VARIABLE_NAME  | VARCHAR | FALSE |         | FALSE           |           | 
49
 * | VARIABLE_VALUE | VARCHAR | FALSE |         | FALSE           |           | 
50
 * +----------------+---------+-------+---------+-----------------+-----------+
51
 *
52
 */
53
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
54
#include <config.h>
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
55
56
#include "status_tool.h"
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
57
#include <drizzled/status_helper.h>
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
58
59
#include <vector>
60
#include <sstream>
61
62
using namespace drizzled;
63
using namespace plugin;
64
using namespace std;
65
66
67
class ShowVarCmpFunctor 
68
{
69
  public:
70
  ShowVarCmpFunctor() { }
71
  inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
72
  {
73
    int val= strcmp(var1->name, var2->name);
74
    return (val < 0);
75
  }
76
};
77
78
StatusTool::StatusTool(LoggingStats *in_logging_stats, bool inIsLocal) :
79
  TableFunction("DATA_DICTIONARY", inIsLocal ? "SESSION_STATUS" : "GLOBAL_STATUS"),
80
  outer_logging_stats(in_logging_stats),
81
  isLocal(inIsLocal)
82
{
83
  add_field("VARIABLE_NAME");
84
  add_field("VARIABLE_VALUE", 1024);
85
86
  drizzle_show_var *var= NULL;
87
  uint32_t count= 0;
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
88
  std::vector<drizzle_show_var *>::iterator all_status_vars_iterator= all_status_vars.begin();
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
89
  while (true)
90
  {
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
91
    var= &StatusHelper::status_vars_defs[count];
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
92
    if ((var == NULL) || (var->name == NULL))
93
    {
94
      break;
95
    }
96
    all_status_vars_iterator= all_status_vars.insert(all_status_vars_iterator, var);
97
    ++count;
98
  }
99
  sort(all_status_vars.begin(), all_status_vars.end(), ShowVarCmpFunctor());
100
}
101
102
StatusTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats,
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
103
                                 std::vector<drizzle_show_var *> *in_all_status_vars, 
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
104
                                 bool inIsLocal) :
105
  TableFunction::Generator(arg),
106
  logging_stats(in_logging_stats),
107
  isLocal(inIsLocal)   
108
{
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
109
  all_status_vars_it= in_all_status_vars->begin();
110
  all_status_vars_end= in_all_status_vars->end();
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
111
112
  status_var_to_display= NULL;
113
  if (isLocal)
114
  {
1561.3.22 by Joe Daly
merge trunk, and remove current_session reference in status_tool.cc
115
    ScoreboardSlot *scoreboard_slot= logging_stats->getCurrentScoreboard()->findOurScoreboardSlot(&getSession());
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
116
117
    if (scoreboard_slot != NULL)
118
    {
1625.2.4 by Joe Daly
fix/add a test, also fix a problem where the scoreboard was being summed up while checking the status of a session, only the global variables should be summed
119
      /* A copy of the current status vars for a particular session */ 
1625.2.1 by Joe Daly
initial user stats impl
120
      status_var_to_display= new StatusVars(*scoreboard_slot->getStatusVars());
1625.2.4 by Joe Daly
fix/add a test, also fix a problem where the scoreboard was being summed up while checking the status of a session, only the global variables should be summed
121
122
      /* Sum the current scoreboard this will give us a value for any variables that have global meaning */
123
      StatusVars current_scoreboard_status_vars;
1625.2.1 by Joe Daly
initial user stats impl
124
      CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
1625.2.4 by Joe Daly
fix/add a test, also fix a problem where the scoreboard was being summed up while checking the status of a session, only the global variables should be summed
125
      cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), &current_scoreboard_status_vars, NULL);
126
127
      /* Copy the above to get a value for any variables that have global meaning */  
1625.2.1 by Joe Daly
initial user stats impl
128
      status_var_to_display->copyGlobalVariables(logging_stats->getCumulativeStats()->getGlobalStatusVars());
1625.2.4 by Joe Daly
fix/add a test, also fix a problem where the scoreboard was being summed up while checking the status of a session, only the global variables should be summed
129
      status_var_to_display->copyGlobalVariables(&current_scoreboard_status_vars); 
1561.3.11 by Joe Daly
get tests working
130
    } 
131
    else 
132
    {
133
      status_var_to_display= NULL;
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
134
    }
135
  }
136
  else // global status 
137
  {
138
    status_var_to_display= new StatusVars();
139
    CumulativeStats *cumulativeStats= logging_stats->getCumulativeStats();
1616.2.1 by Joe Daly
update GLOBAL_STATEMENTS logic it was not including a sum of the current scoreboard only sessions that had terminated
140
    cumulativeStats->sumCurrentScoreboard(logging_stats->getCurrentScoreboard(), status_var_to_display, NULL);
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
141
    status_var_to_display->merge(logging_stats->getCumulativeStats()->getGlobalStatusVars());
142
  }
143
}
144
145
StatusTool::Generator::~Generator()
146
{
1625.2.4 by Joe Daly
fix/add a test, also fix a problem where the scoreboard was being summed up while checking the status of a session, only the global variables should be summed
147
  delete status_var_to_display;
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
148
}
149
150
bool StatusTool::Generator::populate()
151
{
1561.3.11 by Joe Daly
get tests working
152
  if (status_var_to_display == NULL)
153
  {
154
    return false;
155
  }
156
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
157
  while (all_status_vars_it != all_status_vars_end)
158
  {
159
    drizzle_show_var *variables= *all_status_vars_it;
160
161
    if ((variables == NULL) || (variables->name == NULL))
162
    {
163
      return false;
164
    }
165
166
    drizzle_show_var *var;
167
    MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
168
    char * const buff= (char *) &buff_data;
169
170
    /*
171
      if var->type is SHOW_FUNC, call the function.
172
      Repeat as necessary, if new var is again SHOW_FUNC
173
    */
174
    {
175
      drizzle_show_var tmp;
176
177
      for (var= variables; var->type == SHOW_FUNC; var= &tmp)
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
178
        ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
179
    }
180
181
    if (isWild(variables->name))
182
    {
1561.3.11 by Joe Daly
get tests working
183
      ++all_status_vars_it;
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
184
      continue;
185
    }
186
187
    fill(variables->name, var->value, var->type);
188
189
    ++all_status_vars_it;
190
191
    return true;
192
  }
193
194
  return false;
195
}
196
197
void StatusTool::Generator::fill(const string &name, char *value, SHOW_TYPE show_type)
198
{
199
  struct system_status_var *status_var;
200
  ostringstream oss;
201
  string return_value;
202
203
  status_var= status_var_to_display->getStatusVarCounters();
204
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
205
  return_value= StatusHelper::fillHelper(status_var, value, show_type);
1561.3.5 by Joe Daly
remove old SESSION_STATUS tables, add new ones
206
207
  push(name);
208
  if (return_value.length())
209
  {
210
    push(return_value);
211
  }
212
  else
213
  {
214
    push(" ");
215
  }
216
}