~eday/drizzle/eday-dev

« back to all changes in this revision

Viewing changes to plugin/transaction_log/transaction_log.cc

  • Committer: Eric Day
  • Date: 2010-01-07 20:02:38 UTC
  • mfrom: (971.3.291 staging)
  • Revision ID: eday@oddments.org-20100107200238-uqw8v6kv9pl7nny5
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 * this for all the glue code of the module.
71
71
 */
72
72
 
73
 
#include <drizzled/server_includes.h>
 
73
#include "config.h"
74
74
#include "transaction_log.h"
75
75
#include "transaction_log_index.h"
76
76
#include "info_schema.h"
78
78
#include "hexdump_transaction_message.h"
79
79
#include "background_worker.h"
80
80
 
 
81
#include <sys/stat.h>
 
82
#include <fcntl.h>
81
83
#include <unistd.h>
82
84
 
83
85
#include <vector>
84
86
#include <string>
85
87
 
86
 
#include <mysys/my_sys.h> /* for my_sync */
 
88
#include "drizzled/internal/my_sys.h" /* for my_sync */
87
89
 
88
90
#include <drizzled/session.h>
89
91
#include <drizzled/set_var.h>
115
117
 * each written Transaction message?
116
118
 */
117
119
static bool sysvar_transaction_log_checksum_enabled= false;
 
120
/**
 
121
 * Numeric option controlling the sync/flush behaviour of the transaction
 
122
 * log.  Options are:
 
123
 *
 
124
 * TransactionLog::SYNC_METHOD_OS == 0            ... let OS do sync'ing
 
125
 * TransactionLog::SYNC_METHOD_EVERY_WRITE == 1   ... sync on every write
 
126
 * TransactionLog::SYNC_METHOD_EVERY_SECOND == 2  ... sync at most once a second
 
127
 */
 
128
static uint32_t sysvar_transaction_log_sync_method= 0;
118
129
 
119
130
/** Views defined in info_schema.cc */
120
131
extern plugin::InfoSchemaTable *transaction_log_view;
188
199
                      message and trailing checksum to */
189
200
  uint8_t *orig_buffer;
190
201
 
191
 
  int error_code;
192
202
  size_t message_byte_length= to_apply.ByteSize();
193
203
  ssize_t written;
194
204
  off_t cur_offset;
287
297
  }
288
298
  free(orig_buffer);
289
299
 
290
 
  error_code= my_sync(log_file, 0);
 
300
  int error_code= syncLogFile();
291
301
 
292
302
  transaction_log_index->addEntry(TransactionLogEntry(ReplicationServices::TRANSACTION,
293
303
                                                     cur_offset,
303
313
  }
304
314
}
305
315
 
 
316
int TransactionLog::syncLogFile()
 
317
{
 
318
  switch (sysvar_transaction_log_sync_method)
 
319
  {
 
320
  case SYNC_METHOD_EVERY_WRITE:
 
321
    return my_sync(log_file, 0);
 
322
  case SYNC_METHOD_EVERY_SECOND:
 
323
    {
 
324
      time_t now_time= time(NULL);
 
325
      if (last_sync_time <= (now_time - 1))
 
326
      {
 
327
        last_sync_time= now_time;
 
328
        return my_sync(log_file, 0);
 
329
      }
 
330
      return 0;
 
331
    }
 
332
  case SYNC_METHOD_OS:
 
333
  default:
 
334
    return 0;
 
335
  }
 
336
}
 
337
 
306
338
const string &TransactionLog::getLogFilename()
307
339
{
308
340
  return log_file_name;
489
521
}
490
522
 
491
523
static DRIZZLE_SYSVAR_BOOL(enable,
492
 
                          sysvar_transaction_log_enabled,
493
 
                          PLUGIN_VAR_NOCMDARG,
494
 
                          N_("Enable transaction log"),
495
 
                          NULL, /* check func */
496
 
                          NULL, /* update func */
497
 
                          false /* default */);
 
524
                           sysvar_transaction_log_enabled,
 
525
                           PLUGIN_VAR_NOCMDARG,
 
526
                           N_("Enable transaction log"),
 
527
                           NULL, /* check func */
 
528
                           NULL, /* update func */
 
529
                           false /* default */);
498
530
 
499
531
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
500
 
                          sysvar_transaction_log_truncate_debug,
501
 
                          PLUGIN_VAR_NOCMDARG,
502
 
                          N_("DEBUGGING - Truncate transaction log"),
503
 
                          NULL, /* check func */
504
 
                          set_truncate_debug, /* update func */
505
 
                          false /* default */);
 
532
                           sysvar_transaction_log_truncate_debug,
 
533
                           PLUGIN_VAR_NOCMDARG,
 
534
                           N_("DEBUGGING - Truncate transaction log"),
 
535
                           NULL, /* check func */
 
536
                           set_truncate_debug, /* update func */
 
537
                           false /* default */);
506
538
 
507
539
static DRIZZLE_SYSVAR_STR(log_file,
508
540
                          sysvar_transaction_log_file,
509
541
                          PLUGIN_VAR_READONLY,
510
 
                          N_("Path to the file to use for transaction log."),
 
542
                          N_("Path to the file to use for transaction log"),
511
543
                          NULL, /* check func */
512
544
                          NULL, /* update func*/
513
545
                          DEFAULT_LOG_FILE_PATH /* default */);
514
546
 
515
547
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
516
 
                          sysvar_transaction_log_checksum_enabled,
517
 
                          PLUGIN_VAR_NOCMDARG,
518
 
                          N_("Enable CRC32 Checksumming"),
519
 
                          NULL, /* check func */
520
 
                          NULL, /* update func */
521
 
                          false /* default */);
 
548
                           sysvar_transaction_log_checksum_enabled,
 
549
                           PLUGIN_VAR_NOCMDARG,
 
550
                           N_("Enable CRC32 Checksumming of each written transaction log entry"),
 
551
                           NULL, /* check func */
 
552
                           NULL, /* update func */
 
553
                           false /* default */);
 
554
 
 
555
static DRIZZLE_SYSVAR_UINT(sync_method,
 
556
                           sysvar_transaction_log_sync_method,
 
557
                           PLUGIN_VAR_OPCMDARG,
 
558
                           N_("0 == rely on operating system to sync log file (default), "
 
559
                              "1 == sync file at each transaction write, "
 
560
                              "2 == sync log file once per second"),
 
561
                           NULL, /* check func */
 
562
                           NULL, /* update func */
 
563
                           0, /* default */
 
564
                           0,
 
565
                           2,
 
566
                           0);
522
567
 
523
568
static drizzle_sys_var* system_variables[]= {
524
569
  DRIZZLE_SYSVAR(enable),
525
570
  DRIZZLE_SYSVAR(truncate_debug),
526
571
  DRIZZLE_SYSVAR(log_file),
527
572
  DRIZZLE_SYSVAR(enable_checksum),
 
573
  DRIZZLE_SYSVAR(sync_method),
528
574
  NULL
529
575
};
530
576
 
531
 
DRIZZLE_DECLARE_PLUGIN
532
 
{
533
 
  "transaction_log",
534
 
  "0.1",
535
 
  "Jay Pipes",
536
 
  N_("Transaction Message Log"),
537
 
  PLUGIN_LICENSE_GPL,
538
 
  init, /* Plugin Init */
539
 
  deinit, /* Plugin Deinit */
540
 
  NULL, /* status variables */
541
 
  system_variables, /* system variables */
542
 
  NULL    /* config options */
543
 
}
544
 
DRIZZLE_DECLARE_PLUGIN_END;
 
577
DRIZZLE_PLUGIN(init, deinit, NULL, system_variables);