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::Context &context)
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
context.add(transaction_log_applier);
132
/* Setup DATA_DICTIONARY views */
134
transaction_log_tool= new (nothrow) TransactionLogTool;
135
context.add(transaction_log_tool);
136
transaction_log_entries_tool= new (nothrow) TransactionLogEntriesTool;
137
context.add(transaction_log_entries_tool);
138
transaction_log_transactions_tool= new (nothrow) TransactionLogTransactionsTool;
139
context.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
context.add(print_transaction_message_func_factory);
146
hexdump_transaction_message_func_factory=
147
new plugin::Create_function<HexdumpTransactionMessageFunction>("hexdump_transaction_message");
148
context.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 */
180
static void set_truncate_debug(Session *,
186
* The const void * save comes directly from the check function,
187
* which should simply return the result from the set statement.
191
if (*(bool *)save != false)
193
transaction_log->truncate();
194
transaction_log_index->clear();
199
static DRIZZLE_SYSVAR_BOOL(enable,
200
sysvar_transaction_log_enabled,
202
N_("Enable transaction log"),
203
NULL, /* check func */
204
NULL, /* update func */
205
false /* default */);
207
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
208
sysvar_transaction_log_truncate_debug,
210
N_("DEBUGGING - Truncate transaction log"),
211
NULL, /* check func */
212
set_truncate_debug, /* update func */
213
false /* default */);
215
static DRIZZLE_SYSVAR_STR(log_file,
216
sysvar_transaction_log_file,
218
N_("Path to the file to use for transaction log"),
219
NULL, /* check func */
220
NULL, /* update func*/
221
DEFAULT_LOG_FILE_PATH /* default */);
223
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
224
sysvar_transaction_log_checksum_enabled,
226
N_("Enable CRC32 Checksumming of each written transaction log entry"),
227
NULL, /* check func */
228
NULL, /* update func */
229
false /* default */);
231
static DRIZZLE_SYSVAR_UINT(sync_method,
232
sysvar_transaction_log_sync_method,
234
N_("0 == rely on operating system to sync log file (default), "
235
"1 == sync file at each transaction write, "
236
"2 == sync log file once per second"),
237
NULL, /* check func */
238
NULL, /* update func */
244
static drizzle_sys_var* sys_variables[]= {
245
DRIZZLE_SYSVAR(enable),
246
DRIZZLE_SYSVAR(truncate_debug),
247
DRIZZLE_SYSVAR(log_file),
248
DRIZZLE_SYSVAR(enable_checksum),
249
DRIZZLE_SYSVAR(sync_method),
253
DRIZZLE_PLUGIN(init, sys_variables);