~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/module.cc

  • Committer: Brian Aker
  • Date: 2010-02-11 22:56:25 UTC
  • Revision ID: brian@gaz-20100211225625-63v3e79p78blva2u
Remove WEIGHT_STRING() from parser (where it does not belong). If someone
wants to they can reimplement this as a straight function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems
5
 
 *  Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
6
 
 *
7
 
 *  Authors:
8
 
 *
9
 
 *  Jay Pipes <jaypipes@gmail.com.com>
10
 
 *
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.
15
 
 *
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.
20
 
 *
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
24
 
 */
25
 
 
26
 
/**
27
 
 * @file
28
 
 *
29
 
 * Transaction log module initialization and plugin
30
 
 * registration.
31
 
 */
32
 
 
33
 
#include "config.h"
34
 
 
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"
42
 
 
43
 
#include <drizzled/plugin/plugin.h>
44
 
#include <drizzled/session.h>
45
 
#include <drizzled/set_var.h>
46
 
#include <drizzled/gettext.h>
47
 
 
48
 
using namespace std;
49
 
using namespace drizzled;
50
 
 
51
 
/** 
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
54
 
 * disabling.
55
 
 */
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;
59
 
/** 
60
 
 * Transaction Log plugin system variable - A debugging variable to assist 
61
 
 * in truncating the log file. 
62
 
 */
63
 
static bool sysvar_transaction_log_truncate_debug= false;
64
 
static const char DEFAULT_LOG_FILE_PATH[]= "transaction.log"; /* In datadir... */
65
 
/** 
66
 
 * Transaction Log plugin system variable - Should we write a CRC32 checksum for 
67
 
 * each written Transaction message?
68
 
 */
69
 
static bool sysvar_transaction_log_checksum_enabled= false;
70
 
/**
71
 
 * Numeric option controlling the sync/flush behaviour of the transaction
72
 
 * log.  Options are:
73
 
 *
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
77
 
 */
78
 
static uint32_t sysvar_transaction_log_sync_method= 0;
79
 
 
80
 
/** DATA_DICTIONARY views */
81
 
static TransactionLogTool *transaction_log_tool;
82
 
static TransactionLogEntriesTool *transaction_log_entries_tool;
83
 
static TransactionLogTransactionsTool *transaction_log_transactions_tool;
84
 
 
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;
91
 
 
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;
95
 
 
96
 
static int init(drizzled::plugin::Context &context)
97
 
{
98
 
  /* Create and initialize the transaction log itself */
99
 
  if (sysvar_transaction_log_enabled)
100
 
  {
101
 
    transaction_log= new (nothrow) TransactionLog(string(sysvar_transaction_log_file),
102
 
                                                  sysvar_transaction_log_sync_method);
103
 
 
104
 
    if (transaction_log == NULL)
105
 
    {
106
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLog instance.  Got error: %s\n"), 
107
 
                    strerror(errno));
108
 
      return 1;
109
 
    }
110
 
    else
111
 
    {
112
 
      /* Check to see if the log was not created properly */
113
 
      if (transaction_log->hasError())
114
 
      {
115
 
        errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize the Transaction Log.  Got error: %s\n"), 
116
 
                      transaction_log->getErrorMessage().c_str());
117
 
        return 1;
118
 
      }
119
 
    }
120
 
    /* Create the applier plugin and register it */
121
 
    transaction_log_applier= new (nothrow) TransactionLogApplier("transaction_log_applier",
122
 
                                                                 *transaction_log, 
123
 
                                                                 sysvar_transaction_log_checksum_enabled);
124
 
    if (transaction_log_applier == NULL)
125
 
    {
126
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogApplier instance.  Got error: %s\n"), 
127
 
                    strerror(errno));
128
 
      return 1;
129
 
    }
130
 
    context.add(transaction_log_applier);
131
 
 
132
 
    /* Setup DATA_DICTIONARY views */
133
 
 
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);
140
 
 
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);
145
 
 
146
 
    hexdump_transaction_message_func_factory=
147
 
      new plugin::Create_function<HexdumpTransactionMessageFunction>("hexdump_transaction_message");
148
 
    context.add(hexdump_transaction_message_func_factory);
149
 
 
150
 
    /* Create and initialize the transaction log index */
151
 
    transaction_log_index= new (nothrow) TransactionLogIndex(*transaction_log);
152
 
    if (transaction_log_index == NULL)
153
 
    {
154
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogIndex instance.  Got error: %s\n"), 
155
 
                    strerror(errno));
156
 
      return 1;
157
 
    }
158
 
    else
159
 
    {
160
 
      /* Check to see if the index was not created properly */
161
 
      if (transaction_log_index->hasError())
162
 
      {
163
 
        errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize the Transaction Log Index.  Got error: %s\n"), 
164
 
                      transaction_log_index->getErrorMessage().c_str());
165
 
        return 1;
166
 
      }
167
 
    }
168
 
 
169
 
    /* 
170
 
     * Setup the background worker thread which maintains
171
 
     * summary information about the transaction log.
172
 
     */
173
 
    if (initTransactionLogBackgroundWorker())
174
 
      return 1; /* Error message output handled in function above */
175
 
  }
176
 
  return 0;
177
 
}
178
 
 
179
 
 
180
 
static void set_truncate_debug(Session *,
181
 
                               drizzle_sys_var *, 
182
 
                               void *, 
183
 
                               const void *save)
184
 
{
185
 
  /* 
186
 
   * The const void * save comes directly from the check function, 
187
 
   * which should simply return the result from the set statement. 
188
 
   */
189
 
  if (transaction_log)
190
 
  {
191
 
    if (*(bool *)save != false)
192
 
    {
193
 
      transaction_log->truncate();
194
 
      transaction_log_index->clear();
195
 
    }
196
 
  }
197
 
}
198
 
 
199
 
static DRIZZLE_SYSVAR_BOOL(enable,
200
 
                           sysvar_transaction_log_enabled,
201
 
                           PLUGIN_VAR_NOCMDARG,
202
 
                           N_("Enable transaction log"),
203
 
                           NULL, /* check func */
204
 
                           NULL, /* update func */
205
 
                           false /* default */);
206
 
 
207
 
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
208
 
                           sysvar_transaction_log_truncate_debug,
209
 
                           PLUGIN_VAR_NOCMDARG,
210
 
                           N_("DEBUGGING - Truncate transaction log"),
211
 
                           NULL, /* check func */
212
 
                           set_truncate_debug, /* update func */
213
 
                           false /* default */);
214
 
 
215
 
static DRIZZLE_SYSVAR_STR(log_file,
216
 
                          sysvar_transaction_log_file,
217
 
                          PLUGIN_VAR_READONLY,
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 */);
222
 
 
223
 
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
224
 
                           sysvar_transaction_log_checksum_enabled,
225
 
                           PLUGIN_VAR_NOCMDARG,
226
 
                           N_("Enable CRC32 Checksumming of each written transaction log entry"),
227
 
                           NULL, /* check func */
228
 
                           NULL, /* update func */
229
 
                           false /* default */);
230
 
 
231
 
static DRIZZLE_SYSVAR_UINT(sync_method,
232
 
                           sysvar_transaction_log_sync_method,
233
 
                           PLUGIN_VAR_OPCMDARG,
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 */
239
 
                           0, /* default */
240
 
                           0,
241
 
                           2,
242
 
                           0);
243
 
 
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),
250
 
  NULL
251
 
};
252
 
 
253
 
DRIZZLE_PLUGIN(init, sys_variables);