~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * Copyright (C) 2009, Padraig O'Sullivan
 
2
 * Copyright (c) 2009, Padraig O'Sullivan
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
27
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
28
 */
29
29
 
30
 
#include <config.h>
31
 
#include <drizzled/show.h>
32
 
#include <drizzled/gettext.h>
33
 
#include <boost/program_options.hpp>
34
 
#include <drizzled/module/option_map.h>
 
30
#include "config.h"
 
31
#include "drizzled/show.h"
 
32
#include "drizzled/gettext.h"
 
33
#include "drizzled/plugin/info_schema_table.h"
 
34
 
35
35
#include "stats_table.h"
36
36
#include "analysis_table.h"
37
37
#include "sysvar_holder.h"
39
39
#include <string>
40
40
#include <map>
41
41
 
42
 
namespace po=boost::program_options;
43
 
 
44
 
namespace drizzle_plugin
45
 
{
46
 
 
47
 
 
48
 
/*
49
 
 * DATA_DICTIONARY tables.
50
 
 */
51
 
static AnalysisTableTool *analysis_table_tool; 
52
 
 
53
 
static StatsTableTool *stats_table_tool;
 
42
using namespace std;
 
43
using namespace drizzled;
 
44
 
 
45
/*
 
46
 * Vectors of columns for I_S tables.
 
47
 */
 
48
static vector<const plugin::ColumnInfo *> memcached_stats_columns;
 
49
static vector<const plugin::ColumnInfo *> memcached_analysis_columns;
 
50
 
 
51
/*
 
52
 * Methods for I_S tables.
 
53
 */
 
54
static plugin::InfoSchemaMethods *memcached_stats_methods= NULL;
 
55
static plugin::InfoSchemaMethods *memcached_analysis_methods= NULL;
 
56
 
 
57
/*
 
58
 * I_S tables.
 
59
 */
 
60
static plugin::InfoSchemaTable *memcached_stats_table= NULL;
 
61
static plugin::InfoSchemaTable *memcached_analysis_table= NULL;
54
62
 
55
63
/*
56
64
 * System variable related variables.
57
65
 */
58
 
static std::string sysvar_memcached_servers;
 
66
static char *sysvar_memcached_servers= NULL;
 
67
 
 
68
/**
 
69
 * Populate the vectors of columns for each I_S table.
 
70
 *
 
71
 * @return false on success; true on failure.
 
72
 */
 
73
static bool initColumns()
 
74
{
 
75
  if (createMemcachedStatsColumns(memcached_stats_columns))
 
76
  {
 
77
    return true;
 
78
  }
 
79
 
 
80
  if (createMemcachedAnalysisColumns(memcached_analysis_columns))
 
81
  {
 
82
    return true;
 
83
  }
 
84
 
 
85
  return false;
 
86
}
 
87
 
 
88
/**
 
89
 * Clear the vectors of columns for each I_S table.
 
90
 */
 
91
static void cleanupColumns()
 
92
{
 
93
  clearMemcachedColumns(memcached_stats_columns);
 
94
  clearMemcachedColumns(memcached_analysis_columns);
 
95
}
 
96
 
 
97
/**
 
98
 * Initialize the methods for each I_S table.
 
99
 *
 
100
 * @return false on success; true on failure
 
101
 */
 
102
static bool initMethods()
 
103
{
 
104
  memcached_stats_methods= new(std::nothrow) 
 
105
    MemcachedStatsISMethods();
 
106
  if (! memcached_stats_methods)
 
107
  {
 
108
    return true;
 
109
  }
 
110
 
 
111
  memcached_analysis_methods= new(std::nothrow) 
 
112
    MemcachedAnalysisISMethods();
 
113
  if (! memcached_analysis_methods)
 
114
  {
 
115
    return true;
 
116
  }
 
117
 
 
118
  return false;
 
119
}
 
120
 
 
121
/**
 
122
 * Delete memory allocated for the I_S table methods.
 
123
 */
 
124
static void cleanupMethods()
 
125
{
 
126
  delete memcached_stats_methods;
 
127
  delete memcached_analysis_methods;
 
128
}
 
129
 
 
130
/**
 
131
 * Initialize the I_S tables related to memcached.
 
132
 *
 
133
 * @return false on success; true on failure
 
134
 */
 
135
static bool initMemcachedTables()
 
136
{
 
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,
 
141
                                                           "MEMCACHED_STATS");
 
142
  if (! memcached_stats_table)
 
143
  {
 
144
    return true;
 
145
  }
 
146
 
 
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,
 
152
                                      "MEMCACHED_STATS");
 
153
  if (! memcached_analysis_table)
 
154
  {
 
155
    return true;
 
156
  }
 
157
 
 
158
  return false;
 
159
}
 
160
 
 
161
/**
 
162
 * Delete memory allocated for the I_S tables.
 
163
 */
 
164
static void cleanupMemcachedTables()
 
165
{
 
166
  delete memcached_stats_table;
 
167
  delete memcached_analysis_table;
 
168
}
59
169
 
60
170
/**
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.
65
175
 */
66
 
static int init(drizzled::module::Context &context)
 
176
static int init(plugin::Registry &registry)
67
177
{
68
 
  const drizzled::module::option_map &vm= context.getOptions();
 
178
  if (initMethods())
 
179
  {
 
180
    return 1;
 
181
  }
 
182
 
 
183
  if (initColumns())
 
184
  {
 
185
    return 1;
 
186
  }
 
187
 
 
188
  if (initMemcachedTables())
 
189
  {
 
190
    return 1;
 
191
  }
 
192
 
 
193
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
194
  sysvar_holder.setServersString(sysvar_memcached_servers);
69
195
 
70
196
  /* we are good to go */
71
 
  stats_table_tool= new StatsTableTool; 
72
 
  context.add(stats_table_tool);
73
 
 
74
 
  analysis_table_tool= new AnalysisTableTool;
75
 
  context.add(analysis_table_tool);
76
 
 
77
 
  context.registerVariable(new sys_var_std_string("servers",
78
 
                                                  sysvar_memcached_servers));
79
 
                          
80
 
  return 0;
81
 
}
82
 
 
83
 
static void init_options(drizzled::module::option_context &context)
84
 
{
85
 
  context("servers",
86
 
          po::value<std::string>()->default_value(""),
87
 
          _("List of memcached servers."));
88
 
}
89
 
 
90
 
} /* namespace drizzle_plugin */
 
197
  registry.add(memcached_stats_table);
 
198
  registry.add(memcached_analysis_table);
 
199
 
 
200
  return 0;
 
201
}
 
202
 
 
203
/**
 
204
 * Clean up the memcached stats plugin.
 
205
 *
 
206
 * @param[in] registry the drizzled::plugin::Registry singleton
 
207
 * @return false on success; true on failure
 
208
 */
 
209
static int deinit(plugin::Registry &registry)
 
210
{
 
211
  registry.remove(memcached_stats_table);
 
212
  registry.remove(memcached_analysis_table);
 
213
 
 
214
  cleanupMethods();
 
215
  cleanupColumns();
 
216
  cleanupMemcachedTables();
 
217
 
 
218
  return 0;
 
219
}
 
220
 
 
221
static int check_memc_servers(Session *,
 
222
                              drizzle_sys_var *,
 
223
                              void *save,
 
224
                              drizzle_value *value)
 
225
{
 
226
  char buff[STRING_BUFFER_USUAL_SIZE];
 
227
  int len= sizeof(buff);
 
228
  const char *input= value->val_str(value, buff, &len);
 
229
 
 
230
  if (input)
 
231
  {
 
232
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
233
    sysvar_holder.setServersStringVar(input);
 
234
    *(bool *) save= (bool) true;
 
235
    return 0;
 
236
  }
 
237
 
 
238
  *(bool *) save= (bool) false;
 
239
  return 1;
 
240
}
 
241
 
 
242
static void set_memc_servers(Session *,
 
243
                             drizzle_sys_var *,
 
244
                             void *var_ptr,
 
245
                             const void *save)
 
246
{
 
247
  if (*(bool *) save != false)
 
248
  {
 
249
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
250
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
 
251
  }
 
252
}
 
253
 
 
254
static DRIZZLE_SYSVAR_STR(servers,
 
255
                          sysvar_memcached_servers,
 
256
                          PLUGIN_VAR_OPCMDARG,
 
257
                          N_("List of memcached servers."),
 
258
                          check_memc_servers, /* check func */
 
259
                          set_memc_servers, /* update func */
 
260
                          ""); /* default value */
 
261
 
 
262
static drizzle_sys_var *system_variables[]=
 
263
{
 
264
  DRIZZLE_SYSVAR(servers),
 
265
  NULL
 
266
};
91
267
 
92
268
DRIZZLE_DECLARE_PLUGIN
93
269
{
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      */
101
 
  NULL, /* depends */
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   */
103
281
}
104
282
DRIZZLE_DECLARE_PLUGIN_END;