~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/transaction_log/module.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 * in truncating the log file. 
62
62
 */
63
63
static bool sysvar_transaction_log_truncate_debug= false;
 
64
/**
 
65
 * The name of the main transaction log file on disk.  With no prefix,
 
66
 * this goes into Drizzle's $datadir.
 
67
 */
64
68
static const char DEFAULT_LOG_FILE_PATH[]= "transaction.log"; /* In datadir... */
65
69
/** 
66
70
 * Transaction Log plugin system variable - Should we write a CRC32 checksum for 
76
80
 * TransactionLog::SYNC_METHOD_EVERY_SECOND == 2  ... sync at most once a second
77
81
 */
78
82
static uint32_t sysvar_transaction_log_sync_method= 0;
 
83
/**
 
84
 * Transaction Log plugin system variable - Number of slots to create
 
85
 * for managing write buffers
 
86
 */
 
87
static uint32_t sysvar_transaction_log_num_write_buffers= 8;
 
88
/**
 
89
 * Transaction Log plugin system variable - The name of the replicator plugin
 
90
 * to pair the transaction log's applier with.  Defaults to "default"
 
91
 */
 
92
static char *sysvar_transaction_log_use_replicator= NULL;
 
93
static const char DEFAULT_USE_REPLICATOR[]= "default";
79
94
 
80
95
/** DATA_DICTIONARY views */
81
96
static TransactionLogTool *transaction_log_tool;
93
108
extern plugin::Create_function<PrintTransactionMessageFunction> *print_transaction_message_func_factory;
94
109
extern plugin::Create_function<HexdumpTransactionMessageFunction> *hexdump_transaction_message_func_factory;
95
110
 
96
 
static int init(drizzled::plugin::Registry &registry)
 
111
static int init(drizzled::plugin::Context &context)
97
112
{
98
113
  /* Create and initialize the transaction log itself */
99
114
  if (sysvar_transaction_log_enabled)
100
115
  {
101
116
    transaction_log= new (nothrow) TransactionLog(string(sysvar_transaction_log_file),
102
 
                                                  sysvar_transaction_log_sync_method);
 
117
                                                  sysvar_transaction_log_sync_method,
 
118
                                                  sysvar_transaction_log_checksum_enabled);
103
119
 
104
120
    if (transaction_log == NULL)
105
121
    {
117
133
        return 1;
118
134
      }
119
135
    }
 
136
 
 
137
    /* Create and initialize the transaction log index */
 
138
    transaction_log_index= new (nothrow) TransactionLogIndex(*transaction_log);
 
139
    if (transaction_log_index == NULL)
 
140
    {
 
141
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogIndex instance.  Got error: %s\n"), 
 
142
                    strerror(errno));
 
143
      return 1;
 
144
    }
 
145
    else
 
146
    {
 
147
      /* Check to see if the index was not created properly */
 
148
      if (transaction_log_index->hasError())
 
149
      {
 
150
        errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize the Transaction Log Index.  Got error: %s\n"), 
 
151
                      transaction_log_index->getErrorMessage().c_str());
 
152
        return 1;
 
153
      }
 
154
    }
 
155
 
120
156
    /* Create the applier plugin and register it */
121
157
    transaction_log_applier= new (nothrow) TransactionLogApplier("transaction_log_applier",
122
 
                                                                 *transaction_log, 
123
 
                                                                 sysvar_transaction_log_checksum_enabled);
 
158
                                                                 transaction_log, 
 
159
                                                                 transaction_log_index, 
 
160
                                                                 sysvar_transaction_log_num_write_buffers);
124
161
    if (transaction_log_applier == NULL)
125
162
    {
126
163
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to allocate the TransactionLogApplier instance.  Got error: %s\n"), 
127
164
                    strerror(errno));
128
165
      return 1;
129
166
    }
130
 
    registry.add(transaction_log_applier);
 
167
    context.add(transaction_log_applier);
 
168
    ReplicationServices &replication_services= ReplicationServices::singleton();
 
169
    string replicator_name(sysvar_transaction_log_use_replicator);
 
170
    replication_services.attachApplier(transaction_log_applier, replicator_name);
131
171
 
132
172
    /* Setup DATA_DICTIONARY views */
133
173
 
134
174
    transaction_log_tool= new (nothrow) TransactionLogTool;
135
 
    registry.add(transaction_log_tool);
 
175
    context.add(transaction_log_tool);
136
176
    transaction_log_entries_tool= new (nothrow) TransactionLogEntriesTool;
137
 
    registry.add(transaction_log_entries_tool);
 
177
    context.add(transaction_log_entries_tool);
138
178
    transaction_log_transactions_tool= new (nothrow) TransactionLogTransactionsTool;
139
 
    registry.add(transaction_log_transactions_tool);
 
179
    context.add(transaction_log_transactions_tool);
140
180
 
141
181
    /* Setup the module's UDFs */
142
182
    print_transaction_message_func_factory=
143
183
      new plugin::Create_function<PrintTransactionMessageFunction>("print_transaction_message");
144
 
    registry.add(print_transaction_message_func_factory);
 
184
    context.add(print_transaction_message_func_factory);
145
185
 
146
186
    hexdump_transaction_message_func_factory=
147
187
      new plugin::Create_function<HexdumpTransactionMessageFunction>("hexdump_transaction_message");
148
 
    registry.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
 
    }
 
188
    context.add(hexdump_transaction_message_func_factory);
168
189
 
169
190
    /* 
170
191
     * Setup the background worker thread which maintains
176
197
  return 0;
177
198
}
178
199
 
179
 
static int deinit(drizzled::plugin::Registry &registry)
180
 
{
181
 
  /* Cleanup the transaction log itself */
182
 
  if (transaction_log)
183
 
  {
184
 
    registry.remove(transaction_log_applier);
185
 
    delete transaction_log;
186
 
    delete transaction_log_index;
187
 
 
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;
195
 
 
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;
201
 
  }
202
 
 
203
 
  return 0;
204
 
}
205
200
 
206
201
static void set_truncate_debug(Session *,
207
202
                               drizzle_sys_var *, 
238
233
                           set_truncate_debug, /* update func */
239
234
                           false /* default */);
240
235
 
241
 
static DRIZZLE_SYSVAR_STR(log_file,
 
236
static DRIZZLE_SYSVAR_STR(file,
242
237
                          sysvar_transaction_log_file,
243
238
                          PLUGIN_VAR_READONLY,
244
239
                          N_("Path to the file to use for transaction log"),
246
241
                          NULL, /* update func*/
247
242
                          DEFAULT_LOG_FILE_PATH /* default */);
248
243
 
 
244
static DRIZZLE_SYSVAR_STR(use_replicator,
 
245
                          sysvar_transaction_log_use_replicator,
 
246
                          PLUGIN_VAR_READONLY,
 
247
                          N_("Name of the replicator plugin to use (default='default_replicator')"),
 
248
                          NULL, /* check func */
 
249
                          NULL, /* update func*/
 
250
                          DEFAULT_USE_REPLICATOR /* default */);
 
251
 
249
252
static DRIZZLE_SYSVAR_BOOL(enable_checksum,
250
253
                           sysvar_transaction_log_checksum_enabled,
251
254
                           PLUGIN_VAR_NOCMDARG,
267
270
                           2,
268
271
                           0);
269
272
 
 
273
static DRIZZLE_SYSVAR_UINT(num_write_buffers,
 
274
                           sysvar_transaction_log_num_write_buffers,
 
275
                           PLUGIN_VAR_OPCMDARG,
 
276
                           N_("Number of slots for in-memory write buffers (default=8)."),
 
277
                           NULL, /* check func */
 
278
                           NULL, /* update func */
 
279
                           8, /* default */
 
280
                           4,
 
281
                           8192,
 
282
                           0);
 
283
 
270
284
static drizzle_sys_var* sys_variables[]= {
271
285
  DRIZZLE_SYSVAR(enable),
272
286
  DRIZZLE_SYSVAR(truncate_debug),
273
 
  DRIZZLE_SYSVAR(log_file),
 
287
  DRIZZLE_SYSVAR(file),
274
288
  DRIZZLE_SYSVAR(enable_checksum),
275
289
  DRIZZLE_SYSVAR(sync_method),
 
290
  DRIZZLE_SYSVAR(num_write_buffers),
 
291
  DRIZZLE_SYSVAR(use_replicator),
276
292
  NULL
277
293
};
278
294
 
279
 
DRIZZLE_PLUGIN(init, deinit, sys_variables);
 
295
DRIZZLE_PLUGIN(init, sys_variables);