27
27
* THE POSSIBILITY OF SUCH DAMAGE.
31
#include <drizzled/show.h>
32
#include <drizzled/gettext.h>
33
#include <boost/program_options.hpp>
34
#include <drizzled/module/option_map.h>
31
#include "drizzled/show.h"
32
#include "drizzled/gettext.h"
33
#include "drizzled/plugin/info_schema_table.h"
35
35
#include "stats_table.h"
36
36
#include "analysis_table.h"
37
37
#include "sysvar_holder.h"
42
namespace po=boost::program_options;
44
namespace drizzle_plugin
49
* DATA_DICTIONARY tables.
51
static AnalysisTableTool *analysis_table_tool;
53
static StatsTableTool *stats_table_tool;
43
using namespace drizzled;
46
* Vectors of columns for I_S tables.
48
static vector<const plugin::ColumnInfo *> memcached_stats_columns;
49
static vector<const plugin::ColumnInfo *> memcached_analysis_columns;
52
* Methods for I_S tables.
54
static plugin::InfoSchemaMethods *memcached_stats_methods= NULL;
55
static plugin::InfoSchemaMethods *memcached_analysis_methods= NULL;
60
static plugin::InfoSchemaTable *memcached_stats_table= NULL;
61
static plugin::InfoSchemaTable *memcached_analysis_table= NULL;
56
64
* System variable related variables.
58
static std::string sysvar_memcached_servers;
66
static char *sysvar_memcached_servers= NULL;
69
* Populate the vectors of columns for each I_S table.
71
* @return false on success; true on failure.
73
static bool initColumns()
75
if (createMemcachedStatsColumns(memcached_stats_columns))
80
if (createMemcachedAnalysisColumns(memcached_analysis_columns))
89
* Clear the vectors of columns for each I_S table.
91
static void cleanupColumns()
93
clearMemcachedColumns(memcached_stats_columns);
94
clearMemcachedColumns(memcached_analysis_columns);
98
* Initialize the methods for each I_S table.
100
* @return false on success; true on failure
102
static bool initMethods()
104
memcached_stats_methods= new(std::nothrow)
105
MemcachedStatsISMethods();
106
if (! memcached_stats_methods)
111
memcached_analysis_methods= new(std::nothrow)
112
MemcachedAnalysisISMethods();
113
if (! memcached_analysis_methods)
122
* Delete memory allocated for the I_S table methods.
124
static void cleanupMethods()
126
delete memcached_stats_methods;
127
delete memcached_analysis_methods;
131
* Initialize the I_S tables related to memcached.
133
* @return false on success; true on failure
135
static bool initMemcachedTables()
137
memcached_stats_table= new(std::nothrow) plugin::InfoSchemaTable("MEMCACHED_STATS",
138
memcached_stats_columns,
139
-1, -1, false, false, 0,
140
memcached_stats_methods,
142
if (! memcached_stats_table)
147
memcached_analysis_table=
148
new(std::nothrow) plugin::InfoSchemaTable("MEMCACHED_ANALYSIS",
149
memcached_analysis_columns,
150
-1, -1, false, false, 0,
151
memcached_analysis_methods,
153
if (! memcached_analysis_table)
162
* Delete memory allocated for the I_S tables.
164
static void cleanupMemcachedTables()
166
delete memcached_stats_table;
167
delete memcached_analysis_table;
61
171
* Initialize the memcached stats plugin.
63
173
* @param[in] registry the drizzled::plugin::Registry singleton
64
174
* @return false on success; true on failure.
66
static int init(drizzled::module::Context &context)
176
static int init(plugin::Registry ®istry)
68
const drizzled::module::option_map &vm= context.getOptions();
188
if (initMemcachedTables())
193
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
194
sysvar_holder.setServersString(sysvar_memcached_servers);
70
196
/* we are good to go */
71
stats_table_tool= new StatsTableTool;
72
context.add(stats_table_tool);
74
analysis_table_tool= new AnalysisTableTool;
75
context.add(analysis_table_tool);
77
context.registerVariable(new sys_var_std_string("servers",
78
sysvar_memcached_servers));
83
static void init_options(drizzled::module::option_context &context)
86
po::value<std::string>()->default_value(""),
87
_("List of memcached servers."));
90
} /* namespace drizzle_plugin */
197
registry.add(memcached_stats_table);
198
registry.add(memcached_analysis_table);
204
* Clean up the memcached stats plugin.
206
* @param[in] registry the drizzled::plugin::Registry singleton
207
* @return false on success; true on failure
209
static int deinit(plugin::Registry ®istry)
211
registry.remove(memcached_stats_table);
212
registry.remove(memcached_analysis_table);
216
cleanupMemcachedTables();
221
static int check_memc_servers(Session *,
224
drizzle_value *value)
226
char buff[STRING_BUFFER_USUAL_SIZE];
227
int len= sizeof(buff);
228
const char *input= value->val_str(value, buff, &len);
232
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
233
sysvar_holder.setServersStringVar(input);
234
*(bool *) save= (bool) true;
238
*(bool *) save= (bool) false;
242
static void set_memc_servers(Session *,
247
if (*(bool *) save != false)
249
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
250
sysvar_holder.updateServersSysvar((const char **) var_ptr);
254
static DRIZZLE_SYSVAR_STR(servers,
255
sysvar_memcached_servers,
257
N_("List of memcached servers."),
258
check_memc_servers, /* check func */
259
set_memc_servers, /* update func */
260
""); /* default value */
262
static drizzle_sys_var *system_variables[]=
264
DRIZZLE_SYSVAR(servers),
92
268
DRIZZLE_DECLARE_PLUGIN
97
273
"Padraig O'Sullivan",
98
274
N_("Memcached Stats as I_S tables"),
99
275
PLUGIN_LICENSE_BSD,
100
drizzle_plugin::init, /* Plugin Init */
102
drizzle_plugin::init_options /* config options */
276
init, /* Plugin Init */
277
deinit, /* Plugin Deinit */
278
NULL, /* status variables */
279
system_variables, /* system variables */
280
NULL /* config options */
104
282
DRIZZLE_DECLARE_PLUGIN_END;