1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
5
* Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
9
* Jay Pipes <jaypipes@gmail.com.com>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
* Transaction log module initialization and plugin
35
#include "transaction_log.h"
36
#include "transaction_log_applier.h"
37
#include "transaction_log_index.h"
38
#include "data_dictionary_schema.h"
39
#include "print_transaction_message.h"
40
#include "hexdump_transaction_message.h"
41
#include "background_worker.h"
43
#include <drizzled/plugin/plugin.h>
44
#include <drizzled/session.h>
45
#include <drizzled/set_var.h>
46
#include <drizzled/gettext.h>
49
using namespace drizzled;
52
* Transaction Log plugin system variable - Is the log enabled? Only used on init().
53
* The enable() and disable() methods of the TransactionLog class control online
56
static bool sysvar_transaction_log_enabled= false;
57
/** Transaction Log plugin system variable - The path to the log file used */
58
static char* sysvar_transaction_log_file= NULL;
60
* Transaction Log plugin system variable - A debugging variable to assist
61
* in truncating the log file.
63
static bool sysvar_transaction_log_truncate_debug= false;
64
static const char DEFAULT_LOG_FILE_PATH[]= "transaction.log"; /* In datadir... */
66
* Transaction Log plugin system variable - Should we write a CRC32 checksum for
67
* each written Transaction message?
69
static bool sysvar_transaction_log_checksum_enabled= false;
71
* Numeric option controlling the sync/flush behaviour of the transaction
74
* TransactionLog::SYNC_METHOD_OS == 0 ... let OS do sync'ing
75
* TransactionLog::SYNC_METHOD_EVERY_WRITE == 1 ... sync on every write
76
* TransactionLog::SYNC_METHOD_EVERY_SECOND == 2 ... sync at most once a second
78
static uint32_t sysvar_transaction_log_sync_method= 0;
80
/** DATA_DICTIONARY views */
81
static TransactionLogTool *transaction_log_tool;
82
static TransactionLogEntriesTool *transaction_log_entries_tool;
83
static TransactionLogTransactionsTool *transaction_log_transactions_tool;
85
/** Index defined in transaction_log_index.cc */
86
extern TransactionLogIndex *transaction_log_index;
87
/** Transaction Log descriptor defined in transaction_log.cc */
88
extern TransactionLog *transaction_log;
89
/** Transaction Log descriptor defined in transaction_log.cc */
90
extern TransactionLogApplier *transaction_log_applier;
92
/** Defined in print_transaction_message.cc */
93
extern plugin::Create_function<PrintTransactionMessageFunction> *print_transaction_message_func_factory;
94
extern plugin::Create_function<HexdumpTransactionMessageFunction> *hexdump_transaction_message_func_factory;
96
static int init(drizzled::plugin::Registry ®istry)
98
/* Create and initialize the transaction log itself */
99
if (sysvar_transaction_log_enabled)
101
transaction_log= new (nothrow) TransactionLog(string(sysvar_transaction_log_file),
102
sysvar_transaction_log_sync_method);
104
if (transaction_log == NULL)
106
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLog instance. Got error: %s\n"),
112
/* Check to see if the log was not created properly */
113
if (transaction_log->hasError())
115
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize the Transaction Log. Got error: %s\n"),
116
transaction_log->getErrorMessage().c_str());
120
/* Create the applier plugin and register it */
121
transaction_log_applier= new (nothrow) TransactionLogApplier("transaction_log_applier",
123
sysvar_transaction_log_checksum_enabled);
124
if (transaction_log_applier == NULL)
126
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogApplier instance. Got error: %s\n"),
130
registry.add(transaction_log_applier);
132
/* Setup DATA_DICTIONARY views */
134
transaction_log_tool= new (nothrow) TransactionLogTool;
135
registry.add(transaction_log_tool);
136
transaction_log_entries_tool= new (nothrow) TransactionLogEntriesTool;
137
registry.add(transaction_log_entries_tool);
138
transaction_log_transactions_tool= new (nothrow) TransactionLogTransactionsTool;
139
registry.add(transaction_log_transactions_tool);
141
/* Setup the module's UDFs */
142
print_transaction_message_func_factory=
143
new plugin::Create_function<PrintTransactionMessageFunction>("print_transaction_message");
144
registry.add(print_transaction_message_func_factory);
146
hexdump_transaction_message_func_factory=
147
new plugin::Create_function<HexdumpTransactionMessageFunction>("hexdump_transaction_message");
148
registry.add(hexdump_transaction_message_func_factory);
150
/* Create and initialize the transaction log index */
151
transaction_log_index= new (nothrow) TransactionLogIndex(*transaction_log);
152
if (transaction_log_index == NULL)
154
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogIndex instance. Got error: %s\n"),
160
/* Check to see if the index was not created properly */
161
if (transaction_log_index->hasError())
163
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize the Transaction Log Index. Got error: %s\n"),
164
transaction_log_index->getErrorMessage().c_str());
170
* Setup the background worker thread which maintains
171
* summary information about the transaction log.
173
if (initTransactionLogBackgroundWorker())
174
return 1; /* Error message output handled in function above */
179
static int deinit(drizzled::plugin::Registry ®istry)
181
/* Cleanup the transaction log itself */
184
registry.remove(transaction_log_applier);
185
delete transaction_log;
186
delete transaction_log_index;
188
/* Cleanup the DATA_DICTIONARY views */
189
registry.remove(transaction_log_tool);
190
delete transaction_log_tool;
191
registry.remove(transaction_log_entries_tool);
192
delete transaction_log_entries_tool;
193
registry.remove(transaction_log_transactions_tool);
194
delete transaction_log_transactions_tool;
196
/* Cleanup module UDFs */
197
registry.remove(print_transaction_message_func_factory);
198
delete print_transaction_message_func_factory;
199
registry.remove(hexdump_transaction_message_func_factory);
200
delete hexdump_transaction_message_func_factory;
206
static void set_truncate_debug(Session *,
212
* The const void * save comes directly from the check function,
213
* which should simply return the result from the set statement.
216
if (*(bool *)save != false)
217
transaction_log->truncate();
220
static DRIZZLE_SYSVAR_BOOL(enable,
221
sysvar_transaction_log_enabled,
223
N_("Enable transaction log"),
224
NULL, /* check func */
225
NULL, /* update func */
226
false /* default */);
228
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
229
sysvar_transaction_log_truncate_debug,
231
N_("DEBUGGING - Truncate transaction log"),
232
NULL, /* check func */
233
set_truncate_debug, /* update func */
234
false /* default */);
236
static DRIZZLE_SYSVAR_STR(log_file,
237
sysvar_transaction_log_file,
239
N_("Path to the file to use for transaction log"),
240
NULL, /* check func */
241
NULL, /* update func*/
242
DEFAULT_LOG_FILE_PATH /* default */);
244
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
245
sysvar_transaction_log_checksum_enabled,
247
N_("Enable CRC32 Checksumming of each written transaction log entry"),
248
NULL, /* check func */
249
NULL, /* update func */
250
false /* default */);
252
static DRIZZLE_SYSVAR_UINT(sync_method,
253
sysvar_transaction_log_sync_method,
255
N_("0 == rely on operating system to sync log file (default), "
256
"1 == sync file at each transaction write, "
257
"2 == sync log file once per second"),
258
NULL, /* check func */
259
NULL, /* update func */
265
static drizzle_sys_var* sys_variables[]= {
266
DRIZZLE_SYSVAR(enable),
267
DRIZZLE_SYSVAR(truncate_debug),
268
DRIZZLE_SYSVAR(log_file),
269
DRIZZLE_SYSVAR(enable_checksum),
270
DRIZZLE_SYSVAR(sync_method),
274
DRIZZLE_PLUGIN(init, deinit, sys_variables);