~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/command_log/command_log.cc

  • Committer: Brian Aker
  • Date: 2009-10-12 22:46:41 UTC
  • mfrom: (1130.2.27 plugin-base-class)
  • Revision ID: brian@gaz-20091012224641-gjo56i190y8c98xg
Merge Monty, default class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
 */
102
102
static bool sysvar_command_log_checksum_enabled= false;
103
103
 
104
 
CommandLog::CommandLog(const char *in_log_file_path, bool in_do_checksum)
 
104
CommandLog::CommandLog(string name_arg,
 
105
                       const char *in_log_file_path, bool in_do_checksum)
105
106
  : 
106
 
    plugin::CommandApplier(),
 
107
    plugin::CommandApplier(name_arg),
107
108
    state(OFFLINE),
108
109
    log_file_path(in_log_file_path)
109
110
{
110
 
  is_enabled= true; /* If constructed, the plugin is enabled until taken offline with disable() */
111
 
  is_active= false;
112
111
  do_checksum= in_do_checksum; /* Have to do here, not in initialization list b/c atomic<> */
113
112
 
114
113
  /* Setup our log file and determine the next write offset... */
118
117
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to open command log file %s.  Got error: %s\n"), 
119
118
                  log_file_path, 
120
119
                  strerror(errno));
121
 
    is_active= false;
 
120
    deactivate();
122
121
    return;
123
122
  }
124
123
 
129
128
  log_offset= lseek(log_file, 0, SEEK_END);
130
129
 
131
130
  state= ONLINE;
132
 
  is_active= true;
133
131
}
134
132
 
135
133
CommandLog::~CommandLog()
141
139
  }
142
140
}
143
141
 
144
 
bool CommandLog::isActive()
145
 
{
146
 
  return is_enabled && is_active;
147
 
}
148
 
 
149
142
void CommandLog::apply(const message::Command &to_apply)
150
143
{
151
144
  /* 
211
204
     * the original offset where an error occurred.
212
205
     */
213
206
    log_offset= cur_offset;
214
 
    is_active= false;
 
207
    deactivate();
215
208
    return;
216
209
  }
217
210
 
253
246
     * the original offset where an error occurred.
254
247
     */
255
248
    log_offset= cur_offset;
256
 
    is_active= false;
 
249
    deactivate();
257
250
  }
258
251
 
259
252
  cur_offset+= static_cast<off_t>(written);
305
298
     * the original offset where an error occurred.
306
299
     */
307
300
    log_offset= cur_offset;
308
 
    is_active= false;
 
301
    deactivate();
309
302
    return;
310
303
  }
311
304
}
312
305
 
313
306
void CommandLog::truncate()
314
307
{
315
 
  bool orig_is_enabled= is_enabled;
316
 
  is_enabled= false;
 
308
  bool orig_is_active= isActive();
 
309
  deactivate();
317
310
  
318
311
  /* 
319
312
   * Wait a short amount of time before truncating.  This just prevents error messages
320
 
   * from being produced during a call to apply().  Setting is_enabled to false above
 
313
   * from being produced during a call to apply().  Calling disable() above
321
314
   * means that once the current caller to apply() is done, no other calls are made to
322
 
   * apply() before is_enabled is reset to its original state
 
315
   * apply() before enable is reset to its original state
323
316
   *
324
317
   * @note
325
318
   *
334
327
  }
335
328
  while (result == -1 && errno == EINTR);
336
329
 
337
 
  is_enabled= orig_is_enabled;
 
330
  if (orig_is_active)
 
331
    activate();
338
332
}
339
333
 
340
334
bool CommandLog::findLogFilenameContainingTransactionId(const ReplicationServices::GlobalTransactionId&,
355
349
{
356
350
  if (sysvar_command_log_enabled)
357
351
  {
358
 
    command_log= new CommandLog(sysvar_command_log_file, 
 
352
    command_log= new CommandLog("command_log",
 
353
                                sysvar_command_log_file, 
359
354
                                sysvar_command_log_checksum_enabled);
360
355
    registry.add(command_log);
361
356
  }