~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/module.cc

  • Committer: Andrew Hutchings
  • Date: 2010-11-09 13:38:01 UTC
  • mto: (1919.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 1920.
  • Revision ID: andrew@linuxjedi.co.uk-20101109133801-byjzsao76346395x
Add FLUSH GLOBAL STATUS; command
Clears the global status variables for the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
static bool sysvar_transaction_log_enabled= false;
64
64
 
65
65
/** Transaction Log plugin system variable - The path to the log file used */
66
 
static string sysvar_transaction_log_file;
 
66
static char* sysvar_transaction_log_file= (char *)DEFAULT_LOG_FILE_PATH;
67
67
 
68
68
/** 
69
69
 * Transaction Log plugin system variable - A debugging variable to assist 
83
83
 * TransactionLog::FLUSH_FREQUENCY_EVERY_WRITE == 1   ... sync on every write
84
84
 * TransactionLog::FLUSH_FREQUENCY_EVERY_SECOND == 2  ... sync at most once a second
85
85
 */
86
 
typedef constrained_check<uint32_t, 2, 0> flush_constraint;
87
 
static flush_constraint sysvar_transaction_log_flush_frequency;
 
86
static uint32_t sysvar_transaction_log_flush_frequency= 0;
88
87
/**
89
88
 * Transaction Log plugin system variable - Number of slots to create
90
89
 * for managing write buffers
91
90
 */
92
 
typedef constrained_check<uint32_t, 8192, 4> write_buffers_constraint;
93
 
static write_buffers_constraint sysvar_transaction_log_num_write_buffers;
 
91
static uint32_t sysvar_transaction_log_num_write_buffers= 8;
94
92
/**
95
93
 * Transaction Log plugin system variable - The name of the replicator plugin
96
94
 * to pair the transaction log's applier with.  Defaults to "default"
97
95
 */
98
96
static const char DEFAULT_USE_REPLICATOR[]= "default";
99
 
static string sysvar_transaction_log_use_replicator;
 
97
static char *sysvar_transaction_log_use_replicator= (char *)DEFAULT_USE_REPLICATOR;
100
98
 
101
99
/** DATA_DICTIONARY views */
102
100
static TransactionLogTool *transaction_log_tool;
121
119
  {
122
120
    (void) close(log_file);
123
121
  }
124
 
}
125
122
 
126
 
static void set_truncate_debug(Session *, sql_var_t)
127
 
{
128
 
  if (transaction_log)
129
 
  {
130
 
    if (sysvar_transaction_log_truncate_debug)
131
 
    {
132
 
      transaction_log->truncate();
133
 
      transaction_log_index->clear();
134
 
      sysvar_transaction_log_truncate_debug= false;
135
 
    }
136
 
  }
 
123
  /* These get strdup'd below */
 
124
  free(sysvar_transaction_log_file);
 
125
  free(sysvar_transaction_log_use_replicator);
137
126
}
138
127
 
139
128
static int init(drizzled::module::Context &context)
140
129
{
141
 
  context.registerVariable(new sys_var_bool_ptr_readonly("enable",
142
 
                                                         &sysvar_transaction_log_enabled));
143
 
  context.registerVariable(new sys_var_bool_ptr("truncate-debug",
144
 
                                                &sysvar_transaction_log_truncate_debug,
145
 
                                                set_truncate_debug));
146
 
 
147
 
  context.registerVariable(new sys_var_const_string("file",
148
 
                                                    sysvar_transaction_log_file));
149
 
  context.registerVariable(new sys_var_const_string("use-replicator",
150
 
                                                    sysvar_transaction_log_use_replicator));
151
 
  context.registerVariable(new sys_var_bool_ptr_readonly("enable-checksum",
152
 
                                                         &sysvar_transaction_log_checksum_enabled));
153
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush-frequency", sysvar_transaction_log_flush_frequency));
154
 
 
155
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("num-write-buffers",
156
 
                                                                            sysvar_transaction_log_num_write_buffers));
 
130
  const module::option_map &vm= context.getOptions();
 
131
 
 
132
  if (vm.count("flush-frequency"))
 
133
  {
 
134
    if (sysvar_transaction_log_flush_frequency > 2)
 
135
    {
 
136
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for sync-method\n"));
 
137
      exit(-1);
 
138
    }
 
139
  }
 
140
 
 
141
  if (vm.count("num-write-buffers"))
 
142
  {
 
143
    if (sysvar_transaction_log_num_write_buffers < 4 || sysvar_transaction_log_num_write_buffers > 8192)
 
144
    {
 
145
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for num-write-buffers\n"));
 
146
      exit(-1);
 
147
    }
 
148
  }
157
149
 
158
150
 
159
151
  /* Create and initialize the transaction log itself */
160
152
  if (sysvar_transaction_log_enabled)
161
153
  {
 
154
    if (vm.count("file"))
 
155
    {
 
156
      sysvar_transaction_log_file= strdup(vm["file"].as<string>().c_str());
 
157
    }
 
158
    else
 
159
    {
 
160
      sysvar_transaction_log_file= strdup(DEFAULT_LOG_FILE_PATH);
 
161
    }
162
162
  
163
 
    transaction_log= new (nothrow) TransactionLog(sysvar_transaction_log_file,
164
 
                                                  static_cast<int>(sysvar_transaction_log_flush_frequency),
 
163
    if (vm.count("use-replicator"))
 
164
    {
 
165
      sysvar_transaction_log_use_replicator= strdup(vm["use-replicator"].as<string>().c_str());
 
166
    }
 
167
    else
 
168
    {
 
169
      sysvar_transaction_log_use_replicator= strdup(DEFAULT_USE_REPLICATOR);
 
170
    }
 
171
    transaction_log= new (nothrow) TransactionLog(string(sysvar_transaction_log_file),
 
172
                                                  sysvar_transaction_log_flush_frequency,
165
173
                                                  sysvar_transaction_log_checksum_enabled);
166
174
 
167
175
    if (transaction_log == NULL)
208
216
    transaction_log_applier= new (nothrow) TransactionLogApplier("transaction_log_applier",
209
217
                                                                 transaction_log, 
210
218
                                                                 transaction_log_index, 
211
 
                                                                 static_cast<uint32_t>(sysvar_transaction_log_num_write_buffers));
 
219
                                                                 sysvar_transaction_log_num_write_buffers);
212
220
    if (transaction_log_applier == NULL)
213
221
    {
214
222
      char errmsg[STRERROR_MAX];
219
227
    }
220
228
    context.add(transaction_log_applier);
221
229
    ReplicationServices &replication_services= ReplicationServices::singleton();
222
 
    replication_services.attachApplier(transaction_log_applier,
223
 
                                       sysvar_transaction_log_use_replicator);
 
230
    string replicator_name(sysvar_transaction_log_use_replicator);
 
231
    replication_services.attachApplier(transaction_log_applier, replicator_name);
224
232
 
225
233
    /* Setup DATA_DICTIONARY views */
226
234
 
251
259
}
252
260
 
253
261
 
 
262
static void set_truncate_debug(Session *,
 
263
                               drizzle_sys_var *, 
 
264
                               void *, 
 
265
                               const void *save)
 
266
{
 
267
  /* 
 
268
   * The const void * save comes directly from the check function, 
 
269
   * which should simply return the result from the set statement. 
 
270
   */
 
271
  if (transaction_log)
 
272
  {
 
273
    if (*(bool *)save != false)
 
274
    {
 
275
      transaction_log->truncate();
 
276
      transaction_log_index->clear();
 
277
    }
 
278
  }
 
279
}
 
280
 
 
281
static DRIZZLE_SYSVAR_BOOL(enable,
 
282
                           sysvar_transaction_log_enabled,
 
283
                           PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
284
                           N_("Enable transaction log"),
 
285
                           NULL, /* check func */
 
286
                           NULL, /* update func */
 
287
                           false /* default */);
 
288
 
 
289
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
 
290
                           sysvar_transaction_log_truncate_debug,
 
291
                           PLUGIN_VAR_NOCMDARG,
 
292
                           N_("DEBUGGING - Truncate transaction log"),
 
293
                           NULL, /* check func */
 
294
                           set_truncate_debug, /* update func */
 
295
                           false /* default */);
 
296
 
 
297
static DRIZZLE_SYSVAR_STR(file,
 
298
                          sysvar_transaction_log_file,
 
299
                          PLUGIN_VAR_READONLY,
 
300
                          N_("Path to the file to use for transaction log"),
 
301
                          NULL, /* check func */
 
302
                          NULL, /* update func*/
 
303
                          DEFAULT_LOG_FILE_PATH /* default */);
 
304
 
 
305
static DRIZZLE_SYSVAR_STR(use_replicator,
 
306
                          sysvar_transaction_log_use_replicator,
 
307
                          PLUGIN_VAR_READONLY,
 
308
                          N_("Name of the replicator plugin to use (default='default_replicator')"),
 
309
                          NULL, /* check func */
 
310
                          NULL, /* update func*/
 
311
                          DEFAULT_USE_REPLICATOR /* default */);
 
312
 
 
313
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
 
314
                           sysvar_transaction_log_checksum_enabled,
 
315
                           PLUGIN_VAR_NOCMDARG,
 
316
                           N_("Enable CRC32 Checksumming of each written transaction log entry"),
 
317
                           NULL, /* check func */
 
318
                           NULL, /* update func */
 
319
                           false /* default */);
 
320
 
 
321
static DRIZZLE_SYSVAR_UINT(flush_frequency,
 
322
                           sysvar_transaction_log_flush_frequency,
 
323
                           PLUGIN_VAR_OPCMDARG,
 
324
                           N_("0 == rely on operating system to sync log file (default), "
 
325
                              "1 == sync file at each transaction write, "
 
326
                              "2 == sync log file once per second"),
 
327
                           NULL, /* check func */
 
328
                           NULL, /* update func */
 
329
                           0, /* default */
 
330
                           0,
 
331
                           2,
 
332
                           0);
 
333
 
 
334
static DRIZZLE_SYSVAR_UINT(num_write_buffers,
 
335
                           sysvar_transaction_log_num_write_buffers,
 
336
                           PLUGIN_VAR_OPCMDARG,
 
337
                           N_("Number of slots for in-memory write buffers (default=8)."),
 
338
                           NULL, /* check func */
 
339
                           NULL, /* update func */
 
340
                           8, /* default */
 
341
                           4,
 
342
                           8192,
 
343
                           0);
 
344
 
254
345
static void init_options(drizzled::module::option_context &context)
255
346
{
256
347
  context("truncate-debug",
263
354
          po::value<bool>(&sysvar_transaction_log_enabled)->default_value(false)->zero_tokens(),
264
355
          N_("Enable transaction log"));
265
356
  context("file",
266
 
          po::value<string>(&sysvar_transaction_log_file)->default_value(DEFAULT_LOG_FILE_PATH),
 
357
          po::value<string>(),
267
358
          N_("Path to the file to use for transaction log"));
268
359
  context("use-replicator",
269
 
          po::value<string>(&sysvar_transaction_log_use_replicator)->default_value(DEFAULT_USE_REPLICATOR),
 
360
          po::value<string>(),
270
361
          N_("Name of the replicator plugin to use (default='default_replicator')")); 
271
362
  context("flush-frequency",
272
 
          po::value<flush_constraint>(&sysvar_transaction_log_flush_frequency)->default_value(0),
 
363
          po::value<uint32_t>(&sysvar_transaction_log_flush_frequency)->default_value(0),
273
364
          N_("0 == rely on operating system to sync log file (default), 1 == sync file at each transaction write, 2 == sync log file once per second"));
274
365
  context("num-write-buffers",
275
 
          po::value<write_buffers_constraint>(&sysvar_transaction_log_num_write_buffers)->default_value(8),
 
366
          po::value<uint32_t>(&sysvar_transaction_log_num_write_buffers)->default_value(8),
276
367
          N_("Number of slots for in-memory write buffers (default=8)."));
277
368
}
278
369
 
279
 
DRIZZLE_PLUGIN(init, NULL, init_options);
 
370
static drizzle_sys_var* sys_variables[]= {
 
371
  DRIZZLE_SYSVAR(enable),
 
372
  DRIZZLE_SYSVAR(truncate_debug),
 
373
  DRIZZLE_SYSVAR(file),
 
374
  DRIZZLE_SYSVAR(enable_checksum),
 
375
  DRIZZLE_SYSVAR(flush_frequency),
 
376
  DRIZZLE_SYSVAR(num_write_buffers),
 
377
  DRIZZLE_SYSVAR(use_replicator),
 
378
  NULL
 
379
};
 
380
 
 
381
DRIZZLE_PLUGIN(init, sys_variables, init_options);