~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    Abort logging when we get an error in reading or writing log files
25
25
*/
26
26
 
27
 
#include "mysql_priv.h"
 
27
#include <drizzled/server_includes.h>
28
28
#include "sql_repl.h"
29
29
#include "rpl_filter.h"
30
30
#include "rpl_rli.h"
31
31
 
32
 
#include <my_dir.h>
 
32
#include <mysys/my_dir.h>
33
33
#include <stdarg.h>
34
 
#include <m_ctype.h>                            // For test_if_number
35
34
 
36
 
#include <mysql/plugin.h>
 
35
#include <drizzled/plugin.h>
 
36
#include <drizzled/drizzled_error_messages.h>
 
37
#include <libdrizzle/gettext.h>
37
38
 
38
39
/* max size of the log message */
39
40
#define MAX_LOG_BUFFER_SIZE 1024
45
46
 
46
47
LOGGER logger;
47
48
 
48
 
MYSQL_BIN_LOG mysql_bin_log;
 
49
DRIZZLE_BIN_LOG mysql_bin_log;
49
50
ulong sync_binlog_counter= 0;
50
51
 
51
52
static bool test_if_number(const char *str,
58
59
static int binlog_rollback(handlerton *hton, THD *thd, bool all);
59
60
static int binlog_prepare(handlerton *hton, THD *thd, bool all);
60
61
 
61
 
/**
62
 
  Silence all errors and warnings reported when performing a write
63
 
  to a log table.
64
 
  Errors and warnings are not reported to the client or SQL exception
65
 
  handlers, so that the presence of logging does not interfere and affect
66
 
  the logic of an application.
67
 
*/
68
 
class Silence_log_table_errors : public Internal_error_handler
69
 
{
70
 
  char m_message[MYSQL_ERRMSG_SIZE];
71
 
public:
72
 
  Silence_log_table_errors()
73
 
  {
74
 
    m_message[0]= '\0';
75
 
  }
76
 
 
77
 
  virtual ~Silence_log_table_errors() {}
78
 
 
79
 
  virtual bool handle_error(uint sql_errno, const char *message,
80
 
                            MYSQL_ERROR::enum_warning_level level,
81
 
                            THD *thd);
82
 
  const char *message() const { return m_message; }
83
 
};
84
 
 
85
 
bool
86
 
Silence_log_table_errors::handle_error(uint /* sql_errno */,
87
 
                                       const char *message_arg,
88
 
                                       MYSQL_ERROR::enum_warning_level /* level */,
89
 
                                       THD * /* thd */)
90
 
{
91
 
  strmake(m_message, message_arg, sizeof(m_message)-1);
92
 
  return TRUE;
93
 
}
94
 
 
95
62
 
96
63
sql_print_message_func sql_print_message_handlers[3] =
97
64
{
130
97
  {
131
98
    if (m_mutex)
132
99
      pthread_mutex_unlock(m_mutex);
133
 
#ifndef DBUG_OFF
134
100
    m_mutex= 0;
135
 
#endif
136
101
  }
137
102
 
138
103
private:
156
121
 
157
122
  ~binlog_trx_data()
158
123
  {
159
 
    DBUG_ASSERT(pending() == NULL);
 
124
    assert(pending() == NULL);
160
125
    close_cached_file(&trans_log);
161
126
  }
162
127
 
175
140
   */
176
141
  void truncate(my_off_t pos)
177
142
  {
178
 
    DBUG_PRINT("info", ("truncating to position %lu", (ulong) pos));
179
 
    DBUG_PRINT("info", ("before_stmt_pos=%lu", (ulong) pos));
180
143
    delete pending();
181
144
    set_pending(0);
182
145
    reinit_io_cache(&trans_log, WRITE_CACHE, pos, 0, 0);
241
204
 
242
205
 
243
206
/* Check if a given table is opened log table */
244
 
int check_if_log_table(uint db_len, const char *db, uint table_name_len,
245
 
                       const char *table_name, uint check_if_opened)
 
207
int check_if_log_table(uint32_t db_len __attribute__((unused)),
 
208
                       const char *db __attribute__((unused)),
 
209
                       uint32_t table_name_len __attribute__((unused)),
 
210
                       const char *table_name __attribute__((unused)),
 
211
                       uint32_t check_if_opened __attribute__((unused)))
246
212
{
247
213
  return 0;
248
214
}
249
215
 
250
 
/* log event handlers */
251
 
 
252
 
bool Log_to_file_event_handler::
253
 
  log_error(enum loglevel level, const char *format,
254
 
            va_list args)
255
 
{
256
 
  return vprint_msg_to_log(level, format, args);
257
 
}
258
 
 
259
 
void Log_to_file_event_handler::init_pthread_objects()
260
 
{
261
 
  mysql_log.init_pthread_objects();
262
 
  mysql_slow_log.init_pthread_objects();
263
 
}
264
 
 
265
 
 
266
 
/** Wrapper around MYSQL_LOG::write() for slow log. */
267
 
 
268
 
bool Log_to_file_event_handler::
269
 
  log_slow(THD *thd, time_t current_time, time_t query_start_arg,
270
 
           const char *user_host, uint user_host_len,
271
 
           ulonglong query_utime, ulonglong lock_utime, bool is_command,
272
 
           const char *sql_text, uint sql_text_len)
273
 
{
274
 
  return mysql_slow_log.write(thd, current_time, query_start_arg,
275
 
                              user_host, user_host_len,
276
 
                              query_utime, lock_utime, is_command,
277
 
                              sql_text, sql_text_len);
278
 
}
279
 
 
280
 
 
281
 
/**
282
 
   Wrapper around MYSQL_LOG::write() for general log. We need it since we
283
 
   want all log event handlers to have the same signature.
284
 
*/
285
 
 
286
 
bool Log_to_file_event_handler::
287
 
  log_general(THD *thd, time_t event_time, const char *user_host,
288
 
              uint user_host_len, int thread_id,
289
 
              const char *command_type, uint command_type_len,
290
 
              const char *sql_text, uint sql_text_len,
291
 
              CHARSET_INFO *client_cs)
292
 
{
293
 
  return mysql_log.write(event_time, user_host, user_host_len,
294
 
                         thread_id, command_type, command_type_len,
295
 
                         sql_text, sql_text_len);
296
 
}
297
 
 
298
 
 
299
 
bool Log_to_file_event_handler::init()
300
 
{
301
 
  if (!is_initialized)
302
 
  {
303
 
    if (opt_slow_log)
304
 
      mysql_slow_log.open_slow_log(sys_var_slow_log_path.value);
305
 
 
306
 
    if (opt_log)
307
 
      mysql_log.open_query_log(sys_var_general_log_path.value);
308
 
 
309
 
    is_initialized= TRUE;
310
 
  }
311
 
 
312
 
  return FALSE;
313
 
}
314
 
 
315
 
 
316
 
void Log_to_file_event_handler::cleanup()
317
 
{
318
 
  mysql_log.cleanup();
319
 
  mysql_slow_log.cleanup();
320
 
}
321
 
 
322
 
void Log_to_file_event_handler::flush()
323
 
{
324
 
  /* reopen log files */
325
 
  if (opt_log)
326
 
    mysql_log.reopen_file();
327
 
  if (opt_slow_log)
328
 
    mysql_slow_log.reopen_file();
329
 
}
330
 
 
331
216
/*
332
217
  Log error with all enabled log event handlers
333
218
 
347
232
bool LOGGER::error_log_print(enum loglevel level, const char *format,
348
233
                             va_list args)
349
234
{
350
 
  bool error= FALSE;
 
235
  bool error= false;
351
236
  Log_event_handler **current_handler;
352
237
 
353
238
  /* currently we don't need locking here as there is no error_log table */
360
245
 
361
246
void LOGGER::cleanup_base()
362
247
{
363
 
  DBUG_ASSERT(inited == 1);
 
248
  assert(inited == 1);
364
249
  rwlock_destroy(&LOCK_logger);
365
 
  if (file_log_handler)
366
 
    file_log_handler->cleanup();
367
250
}
368
251
 
369
252
 
370
253
void LOGGER::cleanup_end()
371
254
{
372
 
  DBUG_ASSERT(inited == 1);
373
 
  if (file_log_handler)
374
 
    delete file_log_handler;
 
255
  assert(inited == 1);
375
256
}
376
257
 
377
258
 
381
262
*/
382
263
void LOGGER::init_base()
383
264
{
384
 
  DBUG_ASSERT(inited == 0);
 
265
  assert(inited == 0);
385
266
  inited= 1;
386
267
 
387
 
  /*
388
 
    Here we create file log handler. We don't do it for the table log handler
389
 
    here as it cannot be created so early. The reason is THD initialization,
390
 
    which depends on the system variables (parsed later).
391
 
  */
392
 
  if (!file_log_handler)
393
 
    file_log_handler= new Log_to_file_event_handler;
394
 
 
395
268
  /* by default we use traditional error log */
396
269
  init_error_log(LOG_FILE);
397
270
 
398
 
  file_log_handler->init_pthread_objects();
399
271
  my_rwlock_init(&LOCK_logger, NULL);
400
272
}
401
273
 
402
274
 
403
 
bool LOGGER::flush_logs(THD *thd)
 
275
bool LOGGER::flush_logs(THD *thd __attribute__((unused)))
404
276
{
405
277
  int rc= 0;
406
278
 
410
282
  */
411
283
  logger.lock_exclusive();
412
284
 
413
 
  /* reopen log files */
414
 
  file_log_handler->flush();
415
 
 
416
285
  /* end of log flush */
417
286
  logger.unlock();
418
287
  return rc;
419
288
}
420
289
 
421
 
 
422
 
/*
423
 
  Log slow query with all enabled log event handlers
424
 
 
425
 
  SYNOPSIS
426
 
    slow_log_print()
427
 
 
428
 
    thd                 THD of the query being logged
429
 
    query               The query being logged
430
 
    query_length        The length of the query string
431
 
    current_utime       Current time in microseconds (from undefined start)
432
 
 
433
 
  RETURN
434
 
    FALSE   OK
435
 
    TRUE    error occured
436
 
*/
437
 
 
438
 
bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
439
 
                            ulonglong current_utime)
440
 
 
441
 
{
442
 
  bool error= FALSE;
443
 
  Log_event_handler **current_handler;
444
 
  bool is_command= FALSE;
445
 
  char user_host_buff[MAX_USER_HOST_SIZE];
446
 
  Security_context *sctx= thd->security_ctx;
447
 
  uint user_host_len= 0;
448
 
  ulonglong query_utime, lock_utime;
449
 
 
450
 
  /*
451
 
    Print the message to the buffer if we have slow log enabled
452
 
  */
453
 
 
454
 
  if (*slow_log_handler_list)
455
 
  {
456
 
    time_t current_time;
457
 
 
458
 
    /* do not log slow queries from replication threads */
459
 
    if (thd->slave_thread && !opt_log_slow_slave_statements)
460
 
      return 0;
461
 
 
462
 
    lock_shared();
463
 
    if (!opt_slow_log)
464
 
    {
465
 
      unlock();
466
 
      return 0;
467
 
    }
468
 
 
469
 
    /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
470
 
    user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
471
 
                             sctx->priv_user ? sctx->priv_user : "", "[",
472
 
                             sctx->user ? sctx->user : "", "] @ ",
473
 
                             sctx->host ? sctx->host : "", " [",
474
 
                             sctx->ip ? sctx->ip : "", "]", NullS) -
475
 
                    user_host_buff);
476
 
 
477
 
    current_time= my_time_possible_from_micro(current_utime);
478
 
    if (thd->start_utime)
479
 
    {
480
 
      query_utime= (current_utime - thd->start_utime);
481
 
      lock_utime=  (thd->utime_after_lock - thd->start_utime);
482
 
    }
483
 
    else
484
 
    {
485
 
      query_utime= lock_utime= 0;
486
 
    }
487
 
 
488
 
    if (!query)
489
 
    {
490
 
      is_command= TRUE;
491
 
      query= command_name[thd->command].str;
492
 
      query_length= command_name[thd->command].length;
493
 
    }
494
 
 
495
 
    for (current_handler= slow_log_handler_list; *current_handler ;)
496
 
      error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
497
 
                                            user_host_buff, user_host_len,
498
 
                                            query_utime, lock_utime, is_command,
499
 
                                            query, query_length) || error;
500
 
 
501
 
    unlock();
502
 
  }
503
 
  return error;
504
 
}
505
 
 
506
 
bool LOGGER::general_log_write(THD *thd, enum enum_server_command command,
507
 
                               const char *query, uint query_length)
508
 
{
509
 
  bool error= FALSE;
510
 
  Log_event_handler **current_handler= general_log_handler_list;
511
 
  char user_host_buff[MAX_USER_HOST_SIZE];
512
 
  Security_context *sctx= thd->security_ctx;
513
 
  ulong id;
514
 
  uint user_host_len= 0;
515
 
  time_t current_time;
516
 
 
517
 
  if (thd)
518
 
    id= thd->thread_id;                 /* Normal thread */
519
 
  else
520
 
    id= 0;                              /* Log from connect handler */
521
 
 
522
 
  lock_shared();
523
 
  if (!opt_log)
524
 
  {
525
 
    unlock();
526
 
    return 0;
527
 
  }
528
 
  user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
529
 
                          sctx->priv_user ? sctx->priv_user : "", "[",
530
 
                          sctx->user ? sctx->user : "", "] @ ",
531
 
                          sctx->host ? sctx->host : "", " [",
532
 
                          sctx->ip ? sctx->ip : "", "]", NullS) -
533
 
                                                          user_host_buff;
534
 
 
535
 
  current_time= my_time(0);
536
 
 
537
 
  while (*current_handler)
538
 
    error|= (*current_handler++)->
539
 
      log_general(thd, current_time, user_host_buff,
540
 
                  user_host_len, id,
541
 
                  command_name[(uint) command].str,
542
 
                  command_name[(uint) command].length,
543
 
                  query, query_length,
544
 
                  thd->variables.character_set_client) || error;
545
 
  unlock();
546
 
 
547
 
  return error;
548
 
}
549
 
 
550
 
bool LOGGER::general_log_print(THD *thd, enum enum_server_command command,
551
 
                               const char *format, va_list args)
552
 
{
553
 
  uint message_buff_len= 0;
554
 
  char message_buff[MAX_LOG_BUFFER_SIZE];
555
 
 
556
 
  /* prepare message */
557
 
  if (format)
558
 
    message_buff_len= my_vsnprintf(message_buff, sizeof(message_buff),
559
 
                                   format, args);
560
 
  else
561
 
    message_buff[0]= '\0';
562
 
 
563
 
  return general_log_write(thd, command, message_buff, message_buff_len);
564
 
}
565
 
 
566
 
void LOGGER::init_error_log(uint error_log_printer)
 
290
void LOGGER::init_error_log(uint32_t error_log_printer)
567
291
{
568
292
  if (error_log_printer & LOG_NONE)
569
293
  {
571
295
    return;
572
296
  }
573
297
 
574
 
  switch (error_log_printer) {
575
 
  case LOG_FILE:
576
 
    error_log_handler_list[0]= file_log_handler;
577
 
    error_log_handler_list[1]= 0;
578
 
    break;
579
 
    /* these two are disabled for now */
580
 
  case LOG_TABLE:
581
 
    DBUG_ASSERT(0);
582
 
    break;
583
 
  case LOG_TABLE|LOG_FILE:
584
 
    DBUG_ASSERT(0);
585
 
    break;
586
 
  }
587
 
}
588
 
 
589
 
void LOGGER::init_slow_log(uint slow_log_printer)
590
 
{
591
 
  if (slow_log_printer & LOG_NONE)
592
 
  {
593
 
    slow_log_handler_list[0]= 0;
594
 
    return;
595
 
  }
596
 
 
597
 
  slow_log_handler_list[0]= file_log_handler;
598
 
  slow_log_handler_list[1]= 0;
599
 
}
600
 
 
601
 
void LOGGER::init_general_log(uint general_log_printer)
602
 
{
603
 
  if (general_log_printer & LOG_NONE)
604
 
  {
605
 
    general_log_handler_list[0]= 0;
606
 
    return;
607
 
  }
608
 
 
609
 
  general_log_handler_list[0]= file_log_handler;
610
 
  general_log_handler_list[1]= 0;
611
 
}
612
 
 
613
 
 
614
 
bool LOGGER::activate_log_handler(THD* thd, uint log_type)
615
 
{
616
 
  MYSQL_QUERY_LOG *file_log;
617
 
  bool res= FALSE;
618
 
  lock_exclusive();
619
 
  switch (log_type) {
620
 
  case QUERY_LOG_SLOW:
621
 
    if (!opt_slow_log)
622
 
    {
623
 
      file_log= file_log_handler->get_mysql_slow_log();
624
 
 
625
 
      file_log->open_slow_log(sys_var_slow_log_path.value);
626
 
      init_slow_log(log_output_options);
627
 
      opt_slow_log= TRUE;
628
 
    }
629
 
    break;
630
 
  case QUERY_LOG_GENERAL:
631
 
    if (!opt_log)
632
 
    {
633
 
      file_log= file_log_handler->get_mysql_log();
634
 
 
635
 
      file_log->open_query_log(sys_var_general_log_path.value);
636
 
      init_general_log(log_output_options);
637
 
      opt_log= TRUE;
638
 
    }
639
 
    break;
640
 
  default:
641
 
    DBUG_ASSERT(0);
642
 
  }
643
 
  unlock();
644
 
  return res;
645
 
}
646
 
 
647
 
 
648
 
void LOGGER::deactivate_log_handler(THD *thd, uint log_type)
649
 
{
650
 
  my_bool *tmp_opt= 0;
651
 
  MYSQL_LOG *file_log;
652
 
 
653
 
  switch (log_type) {
654
 
  case QUERY_LOG_SLOW:
655
 
    tmp_opt= &opt_slow_log;
656
 
    file_log= file_log_handler->get_mysql_slow_log();
657
 
    break;
658
 
  case QUERY_LOG_GENERAL:
659
 
    tmp_opt= &opt_log;
660
 
    file_log= file_log_handler->get_mysql_log();
661
 
    break;
662
 
  default:
663
 
    assert(0);                                  // Impossible
664
 
  }
665
 
 
666
 
  if (!(*tmp_opt))
667
 
    return;
668
 
 
669
 
  lock_exclusive();
670
 
  file_log->close(0);
671
 
  *tmp_opt= FALSE;
672
 
  unlock();
673
 
}
674
 
 
675
 
int LOGGER::set_handlers(uint error_log_printer,
676
 
                         uint slow_log_printer,
677
 
                         uint general_log_printer)
 
298
}
 
299
 
 
300
int LOGGER::set_handlers(uint32_t error_log_printer)
678
301
{
679
302
  /* error log table is not supported yet */
680
 
  DBUG_ASSERT(error_log_printer < LOG_TABLE);
681
 
 
682
303
  lock_exclusive();
683
304
 
684
305
  init_error_log(error_log_printer);
685
 
  init_slow_log(slow_log_printer);
686
 
  init_general_log(general_log_printer);
687
 
 
688
306
  unlock();
689
307
 
690
308
  return 0;
709
327
static void
710
328
binlog_trans_log_savepos(THD *thd, my_off_t *pos)
711
329
{
712
 
  DBUG_ENTER("binlog_trans_log_savepos");
713
 
  DBUG_ASSERT(pos != NULL);
 
330
  assert(pos != NULL);
714
331
  if (thd_get_ha_data(thd, binlog_hton) == NULL)
715
332
    thd->binlog_setup_trx_data();
716
333
  binlog_trx_data *const trx_data=
717
334
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
718
 
  DBUG_ASSERT(mysql_bin_log.is_open());
 
335
  assert(mysql_bin_log.is_open());
719
336
  *pos= trx_data->position();
720
 
  DBUG_PRINT("return", ("*pos: %lu", (ulong) *pos));
721
 
  DBUG_VOID_RETURN;
 
337
  return;
722
338
}
723
339
 
724
340
 
740
356
static void
741
357
binlog_trans_log_truncate(THD *thd, my_off_t pos)
742
358
{
743
 
  DBUG_ENTER("binlog_trans_log_truncate");
744
 
  DBUG_PRINT("enter", ("pos: %lu", (ulong) pos));
745
 
 
746
 
  DBUG_ASSERT(thd_get_ha_data(thd, binlog_hton) != NULL);
 
359
  assert(thd_get_ha_data(thd, binlog_hton) != NULL);
747
360
  /* Only true if binlog_trans_log_savepos() wasn't called before */
748
 
  DBUG_ASSERT(pos != ~(my_off_t) 0);
 
361
  assert(pos != ~(my_off_t) 0);
749
362
 
750
363
  binlog_trx_data *const trx_data=
751
364
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
752
365
  trx_data->truncate(pos);
753
 
  DBUG_VOID_RETURN;
 
366
  return;
754
367
}
755
368
 
756
369
 
757
370
/*
758
371
  this function is mostly a placeholder.
759
 
  conceptually, binlog initialization (now mostly done in MYSQL_BIN_LOG::open)
 
372
  conceptually, binlog initialization (now mostly done in DRIZZLE_BIN_LOG::open)
760
373
  should be moved here.
761
374
*/
762
375
 
764
377
{
765
378
  binlog_hton= (handlerton *)p;
766
379
  binlog_hton->state=opt_bin_log ? SHOW_OPTION_YES : SHOW_OPTION_NO;
767
 
  binlog_hton->db_type=DB_TYPE_BINLOG;
768
380
  binlog_hton->savepoint_offset= sizeof(my_off_t);
769
381
  binlog_hton->close_connection= binlog_close_connection;
770
382
  binlog_hton->savepoint_set= binlog_savepoint_set;
773
385
  binlog_hton->rollback= binlog_rollback;
774
386
  binlog_hton->prepare= binlog_prepare;
775
387
  binlog_hton->flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN;
 
388
 
776
389
  return 0;
777
390
}
778
391
 
779
 
static int binlog_close_connection(handlerton *hton, THD *thd)
 
392
static int binlog_close_connection(handlerton *hton __attribute__((unused)),
 
393
                                   THD *thd)
780
394
{
781
395
  binlog_trx_data *const trx_data=
782
396
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
783
 
  DBUG_ASSERT(trx_data->empty());
 
397
  assert(trx_data->empty());
784
398
  thd_set_ha_data(thd, binlog_hton, NULL);
785
399
  trx_data->~binlog_trx_data();
786
 
  my_free((uchar*)trx_data, MYF(0));
 
400
  free((unsigned char*)trx_data);
787
401
  return 0;
788
402
}
789
403
 
814
428
binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
815
429
                 Log_event *end_ev, bool all)
816
430
{
817
 
  DBUG_ENTER("binlog_end_trans");
818
431
  int error=0;
819
432
  IO_CACHE *trans_log= &trx_data->trans_log;
820
 
  DBUG_PRINT("enter", ("transaction: %s  end_ev: 0x%lx",
821
 
                       all ? "all" : "stmt", (long) end_ev));
822
 
  DBUG_PRINT("info", ("thd->options={ %s%s}",
823
 
                      FLAGSTR(thd->options, OPTION_NOT_AUTOCOMMIT),
824
 
                      FLAGSTR(thd->options, OPTION_BEGIN)));
825
433
 
826
434
  /*
827
435
    NULL denotes ROLLBACK with nothing to replicate: i.e., rollback of
841
449
      were, we would have to ensure that we're not ending a statement
842
450
      inside a stored function.
843
451
     */
844
 
    thd->binlog_flush_pending_rows_event(TRUE);
 
452
    thd->binlog_flush_pending_rows_event(true);
845
453
 
846
454
    error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev);
847
455
    trx_data->reset();
871
479
    {
872
480
      trx_data->reset();
873
481
 
874
 
      DBUG_ASSERT(!thd->binlog_get_pending_rows_event());
 
482
      assert(!thd->binlog_get_pending_rows_event());
875
483
      thd->clear_binlog_table_maps();
876
484
    }
877
485
    else                                        // ...statement
885
493
    mysql_bin_log.update_table_map_version();
886
494
  }
887
495
 
888
 
  DBUG_RETURN(error);
 
496
  return(error);
889
497
}
890
498
 
891
 
static int binlog_prepare(handlerton *hton, THD *thd, bool all)
 
499
static int binlog_prepare(handlerton *hton __attribute__((unused)),
 
500
                          THD *thd __attribute__((unused)),
 
501
                          bool all __attribute__((unused)))
892
502
{
893
503
  /*
894
504
    do nothing.
895
505
    just pretend we can do 2pc, so that MySQL won't
896
506
    switch to 1pc.
897
 
    real work will be done in MYSQL_BIN_LOG::log_xid()
 
507
    real work will be done in DRIZZLE_BIN_LOG::log_xid()
898
508
  */
899
509
  return 0;
900
510
}
914
524
 
915
525
  @see handlerton::commit
916
526
*/
917
 
static int binlog_commit(handlerton *hton, THD *thd, bool all)
 
527
static int binlog_commit(handlerton *hton __attribute__((unused)),
 
528
                         THD *thd, bool all)
918
529
{
919
 
  DBUG_ENTER("binlog_commit");
920
530
  binlog_trx_data *const trx_data=
921
531
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
922
532
 
923
533
  if (trx_data->empty())
924
534
  {
925
 
    // we're here because trans_log was flushed in MYSQL_BIN_LOG::log_xid()
 
535
    // we're here because trans_log was flushed in DRIZZLE_BIN_LOG::log_xid()
926
536
    trx_data->reset();
927
 
    DBUG_RETURN(0);
 
537
    return(0);
928
538
  }
929
539
 
930
540
  /*
985
595
 
986
596
    Otherwise, we accumulate the statement
987
597
  */
988
 
  ulonglong const in_transaction=
 
598
  uint64_t const in_transaction=
989
599
    thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
990
 
  DBUG_PRINT("debug",
991
 
             ("all: %d, empty: %s, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
992
 
              all,
993
 
              YESNO(trx_data->empty()),
994
 
              YESNO(in_transaction),
995
 
              YESNO(thd->transaction.all.modified_non_trans_table),
996
 
              YESNO(thd->transaction.stmt.modified_non_trans_table)));
997
600
  if ((in_transaction && (all || (!trx_data->at_least_one_stmt && thd->transaction.stmt.modified_non_trans_table))) || (!in_transaction && !all))
998
601
  {
999
 
    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE);
1000
 
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
 
602
    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), true, false);
 
603
    qev.error_code= 0; // see comment in DRIZZLE_LOG::write(THD, IO_CACHE)
1001
604
    int error= binlog_end_trans(thd, trx_data, &qev, all);
1002
 
    DBUG_RETURN(error);
 
605
    return(error);
1003
606
  }
1004
 
  DBUG_RETURN(0);
 
607
  return(0);
1005
608
}
1006
609
 
1007
610
/**
1019
622
 
1020
623
  @see handlerton::rollback
1021
624
*/
1022
 
static int binlog_rollback(handlerton *hton, THD *thd, bool all)
 
625
static int binlog_rollback(handlerton *hton __attribute__((unused)),
 
626
                           THD *thd, bool all)
1023
627
{
1024
 
  DBUG_ENTER("binlog_rollback");
1025
628
  int error=0;
1026
629
  binlog_trx_data *const trx_data=
1027
630
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
1028
631
 
1029
632
  if (trx_data->empty()) {
1030
633
    trx_data->reset();
1031
 
    DBUG_RETURN(0);
 
634
    return(0);
1032
635
  }
1033
636
 
1034
 
  DBUG_PRINT("debug", ("all: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
1035
 
                       YESNO(all),
1036
 
                       YESNO(thd->transaction.all.modified_non_trans_table),
1037
 
                       YESNO(thd->transaction.stmt.modified_non_trans_table)));
1038
637
  if ((all && thd->transaction.all.modified_non_trans_table) ||
1039
638
      (!all && thd->transaction.stmt.modified_non_trans_table) ||
1040
639
      (thd->options & OPTION_KEEP_LOG))
1047
646
      transactional table in that statement as well, which needs to be
1048
647
      rolled back on the slave.
1049
648
    */
1050
 
    Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE);
1051
 
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
 
649
    Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), true, false);
 
650
    qev.error_code= 0; // see comment in DRIZZLE_LOG::write(THD, IO_CACHE)
1052
651
    error= binlog_end_trans(thd, trx_data, &qev, all);
1053
652
  }
1054
653
  else if ((all && !thd->transaction.all.modified_non_trans_table) ||
1061
660
     */
1062
661
    error= binlog_end_trans(thd, trx_data, 0, all);
1063
662
  }
1064
 
  DBUG_RETURN(error);
 
663
  return(error);
1065
664
}
1066
665
 
1067
666
/**
1088
687
  that case there is no need to have it in the binlog).
1089
688
*/
1090
689
 
1091
 
static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
 
690
static int binlog_savepoint_set(handlerton *hton __attribute__((unused)),
 
691
                                THD *thd, void *sv)
1092
692
{
1093
 
  DBUG_ENTER("binlog_savepoint_set");
1094
 
 
1095
693
  binlog_trans_log_savepos(thd, (my_off_t*) sv);
1096
694
  /* Write it to the binary log */
1097
695
  
1098
696
  int const error=
1099
697
    thd->binlog_query(THD::STMT_QUERY_TYPE,
1100
 
                      thd->query, thd->query_length, TRUE, FALSE);
1101
 
  DBUG_RETURN(error);
 
698
                      thd->query, thd->query_length, true, false);
 
699
  return(error);
1102
700
}
1103
701
 
1104
 
static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
 
702
static int binlog_savepoint_rollback(handlerton *hton __attribute__((unused)),
 
703
                                     THD *thd, void *sv)
1105
704
{
1106
 
  DBUG_ENTER("binlog_savepoint_rollback");
1107
 
 
1108
705
  /*
1109
706
    Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
1110
707
    non-transactional table. Otherwise, truncate the binlog cache starting
1115
712
  {
1116
713
    int error=
1117
714
      thd->binlog_query(THD::STMT_QUERY_TYPE,
1118
 
                        thd->query, thd->query_length, TRUE, FALSE);
1119
 
    DBUG_RETURN(error);
 
715
                        thd->query, thd->query_length, true, false);
 
716
    return(error);
1120
717
  }
1121
718
  binlog_trans_log_truncate(thd, *(my_off_t*)sv);
1122
 
  DBUG_RETURN(0);
 
719
  return(0);
1123
720
}
1124
721
 
1125
722
 
1126
723
int check_binlog_magic(IO_CACHE* log, const char** errmsg)
1127
724
{
1128
725
  char magic[4];
1129
 
  DBUG_ASSERT(my_b_tell(log) == 0);
 
726
  assert(my_b_tell(log) == 0);
1130
727
 
1131
 
  if (my_b_read(log, (uchar*) magic, sizeof(magic)))
 
728
  if (my_b_read(log, (unsigned char*) magic, sizeof(magic)))
1132
729
  {
1133
 
    *errmsg = "I/O error reading the header from the binary log";
 
730
    *errmsg = _("I/O error reading the header from the binary log");
1134
731
    sql_print_error("%s, errno=%d, io cache code=%d", *errmsg, my_errno,
1135
732
                    log->error);
1136
733
    return 1;
1137
734
  }
1138
735
  if (memcmp(magic, BINLOG_MAGIC, sizeof(magic)))
1139
736
  {
1140
 
    *errmsg = "Binlog has bad magic number;  It's not a binary log file that can be used by this version of MySQL";
 
737
    *errmsg = _("Binlog has bad magic number;  It's not a binary log file "
 
738
                "that can be used by this version of Drizzle");
1141
739
    return 1;
1142
740
  }
1143
741
  return 0;
1147
745
File open_binlog(IO_CACHE *log, const char *log_file_name, const char **errmsg)
1148
746
{
1149
747
  File file;
1150
 
  DBUG_ENTER("open_binlog");
1151
748
 
1152
 
  if ((file = my_open(log_file_name, O_RDONLY | O_BINARY | O_SHARE, 
 
749
  if ((file = my_open(log_file_name, O_RDONLY, 
1153
750
                      MYF(MY_WME))) < 0)
1154
751
  {
1155
 
    sql_print_error("Failed to open log (file '%s', errno %d)",
 
752
    sql_print_error(_("Failed to open log (file '%s', errno %d)"),
1156
753
                    log_file_name, my_errno);
1157
 
    *errmsg = "Could not open log file";
 
754
    *errmsg = _("Could not open log file");
1158
755
    goto err;
1159
756
  }
1160
757
  if (init_io_cache(log, file, IO_SIZE*2, READ_CACHE, 0, 0,
1161
758
                    MYF(MY_WME|MY_DONT_CHECK_FILESIZE)))
1162
759
  {
1163
 
    sql_print_error("Failed to create a cache on log (file '%s')",
 
760
    sql_print_error(_("Failed to create a cache on log (file '%s')"),
1164
761
                    log_file_name);
1165
 
    *errmsg = "Could not open log file";
 
762
    *errmsg = _("Could not open log file");
1166
763
    goto err;
1167
764
  }
1168
765
  if (check_binlog_magic(log,errmsg))
1169
766
    goto err;
1170
 
  DBUG_RETURN(file);
 
767
  return(file);
1171
768
 
1172
769
err:
1173
770
  if (file >= 0)
1175
772
    my_close(file,MYF(0));
1176
773
    end_io_cache(log);
1177
774
  }
1178
 
  DBUG_RETURN(-1);
 
775
  return(-1);
1179
776
}
1180
777
 
1181
778
 
1191
788
static int find_uniq_filename(char *name)
1192
789
{
1193
790
  long                  number;
1194
 
  uint                  i;
 
791
  uint32_t                  i;
1195
792
  char                  buff[FN_REFLEN];
1196
793
  struct st_my_dir     *dir_info;
1197
794
  register struct fileinfo *file_info;
1198
795
  ulong                 max_found=0;
1199
796
  size_t                buf_length, length;
1200
797
  char                  *start, *end;
1201
 
  DBUG_ENTER("find_uniq_filename");
1202
798
 
1203
799
  length= dirname_part(buff, name, &buf_length);
1204
800
  start=  name + length;
1205
 
  end=    strend(start);
 
801
  end= strchr(start, '\0');
1206
802
 
1207
803
  *end='.';
1208
804
  length= (size_t) (end-start+1);
1209
805
 
1210
806
  if (!(dir_info = my_dir(buff,MYF(MY_DONT_SORT))))
1211
807
  {                                             // This shouldn't happen
1212
 
    strmov(end,".1");                           // use name+1
1213
 
    DBUG_RETURN(0);
 
808
    my_stpcpy(end,".1");                                // use name+1
 
809
    return(0);
1214
810
  }
1215
811
  file_info= dir_info->dir_entry;
1216
812
  for (i=dir_info->number_off_files ; i-- ; file_info++)
1217
813
  {
1218
 
    if (bcmp((uchar*) file_info->name, (uchar*) start, length) == 0 &&
 
814
    if (memcmp(file_info->name, start, length) == 0 &&
1219
815
        test_if_number(file_info->name+length, &number,0))
1220
816
    {
1221
817
      set_if_bigger(max_found,(ulong) number);
1225
821
 
1226
822
  *end++='.';
1227
823
  sprintf(end,"%06ld",max_found+1);
1228
 
  DBUG_RETURN(0);
 
824
  return(0);
1229
825
}
1230
826
 
1231
827
 
1232
 
void MYSQL_LOG::init(enum_log_type log_type_arg,
 
828
void DRIZZLE_LOG::init(enum_log_type log_type_arg,
1233
829
                     enum cache_type io_cache_type_arg)
1234
830
{
1235
 
  DBUG_ENTER("MYSQL_LOG::init");
1236
831
  log_type= log_type_arg;
1237
832
  io_cache_type= io_cache_type_arg;
1238
 
  DBUG_PRINT("info",("log_type: %d", log_type));
1239
 
  DBUG_VOID_RETURN;
 
833
  return;
1240
834
}
1241
835
 
1242
836
 
1261
855
    1   error
1262
856
*/
1263
857
 
1264
 
bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
 
858
bool DRIZZLE_LOG::open(const char *log_name, enum_log_type log_type_arg,
1265
859
                     const char *new_name, enum cache_type io_cache_type_arg)
1266
860
{
1267
861
  char buff[FN_REFLEN];
1268
862
  File file= -1;
1269
 
  int open_flags= O_CREAT | O_BINARY;
1270
 
  DBUG_ENTER("MYSQL_LOG::open");
1271
 
  DBUG_PRINT("enter", ("log_type: %d", (int) log_type_arg));
 
863
  int open_flags= O_CREAT;
1272
864
 
1273
865
  write_error= 0;
1274
866
 
1281
873
  }
1282
874
 
1283
875
  if (new_name)
1284
 
    strmov(log_file_name, new_name);
 
876
    my_stpcpy(log_file_name, new_name);
1285
877
  else if (generate_new_name(log_file_name, name))
1286
878
    goto err;
1287
879
 
1303
895
  if (log_type == LOG_NORMAL)
1304
896
  {
1305
897
    char *end;
1306
 
    int len=my_snprintf(buff, sizeof(buff), "%s, Version: %s (%s). "
1307
 
                        "started with:\nTCP Port: %d, Named Pipe: %s\n",
1308
 
                        my_progname, server_version, MYSQL_COMPILATION_COMMENT,
1309
 
                        mysqld_port, ""
1310
 
                       );
1311
 
    end= strnmov(buff + len, "Time                 Id Command    Argument\n",
 
898
    int len=snprintf(buff, sizeof(buff), "%s, Version: %s (%s). "
 
899
                     "started with:\nTCP Port: %d, Named Pipe: %s\n",
 
900
                     my_progname, server_version, DRIZZLE_COMPILATION_COMMENT,
 
901
                     mysqld_port, ""
 
902
                     );
 
903
    end= my_stpncpy(buff + len, "Time                 Id Command    Argument\n",
1312
904
                 sizeof(buff) - len);
1313
 
    if (my_b_write(&log_file, (uchar*) buff, (uint) (end-buff)) ||
 
905
    if (my_b_write(&log_file, (unsigned char*) buff, (uint) (end-buff)) ||
1314
906
        flush_io_cache(&log_file))
1315
907
      goto err;
1316
908
  }
1317
909
 
1318
910
  log_state= LOG_OPENED;
1319
 
  DBUG_RETURN(0);
 
911
  return(0);
1320
912
 
1321
913
err:
1322
 
  sql_print_error("Could not use %s for logging (error %d). \
1323
 
Turning logging off for the whole duration of the MySQL server process. \
1324
 
To turn it on again: fix the cause, \
1325
 
shutdown the MySQL server and restart it.", name, errno);
 
914
  sql_print_error(_("Could not use %s for logging (error %d). "
 
915
                    "Turning logging off for the whole duration of the "
 
916
                    "Drizzle server process. "
 
917
                    "To turn it on again: fix the cause, "
 
918
                    "shutdown the Drizzle server and restart it."),
 
919
                    name, errno);
1326
920
  if (file >= 0)
1327
921
    my_close(file, MYF(0));
1328
922
  end_io_cache(&log_file);
1329
 
  safeFree(name);
 
923
  if (name)
 
924
  {
 
925
    free(name);
 
926
    name= NULL;
 
927
  }
1330
928
  log_state= LOG_CLOSED;
1331
 
  DBUG_RETURN(1);
 
929
  return(1);
1332
930
}
1333
931
 
1334
 
MYSQL_LOG::MYSQL_LOG()
1335
 
  : name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN),
 
932
DRIZZLE_LOG::DRIZZLE_LOG()
 
933
  : name(0), write_error(false), inited(false), log_type(LOG_UNKNOWN),
1336
934
    log_state(LOG_CLOSED)
1337
935
{
1338
936
  /*
1341
939
    called only in main(). Doing initialization here would make it happen
1342
940
    before main().
1343
941
  */
1344
 
  bzero((char*) &log_file, sizeof(log_file));
 
942
  memset(&log_file, 0, sizeof(log_file));
1345
943
}
1346
944
 
1347
 
void MYSQL_LOG::init_pthread_objects()
 
945
void DRIZZLE_LOG::init_pthread_objects()
1348
946
{
1349
 
  DBUG_ASSERT(inited == 0);
 
947
  assert(inited == 0);
1350
948
  inited= 1;
1351
949
  (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW);
1352
950
}
1365
963
    The internal structures are not freed until cleanup() is called
1366
964
*/
1367
965
 
1368
 
void MYSQL_LOG::close(uint exiting)
 
966
void DRIZZLE_LOG::close(uint32_t exiting)
1369
967
{                                       // One can't set log_type here!
1370
 
  DBUG_ENTER("MYSQL_LOG::close");
1371
 
  DBUG_PRINT("enter",("exiting: %d", (int) exiting));
1372
968
  if (log_state == LOG_OPENED)
1373
969
  {
1374
970
    end_io_cache(&log_file);
1387
983
  }
1388
984
 
1389
985
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
1390
 
  safeFree(name);
1391
 
  DBUG_VOID_RETURN;
 
986
  if (name)
 
987
  {
 
988
    free(name);
 
989
    name= NULL;
 
990
  }
 
991
  return;
1392
992
}
1393
993
 
1394
994
/** This is called only once. */
1395
995
 
1396
 
void MYSQL_LOG::cleanup()
 
996
void DRIZZLE_LOG::cleanup()
1397
997
{
1398
 
  DBUG_ENTER("cleanup");
1399
998
  if (inited)
1400
999
  {
1401
1000
    inited= 0;
1402
1001
    (void) pthread_mutex_destroy(&LOCK_log);
1403
1002
    close(0);
1404
1003
  }
1405
 
  DBUG_VOID_RETURN;
 
1004
  return;
1406
1005
}
1407
1006
 
1408
1007
 
1409
 
int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name)
 
1008
int DRIZZLE_LOG::generate_new_name(char *new_name, const char *log_name)
1410
1009
{
1411
1010
  fn_format(new_name, log_name, mysql_data_home, "", 4);
1412
1011
  if (log_type == LOG_BIN)
1424
1023
}
1425
1024
 
1426
1025
 
1427
 
/*
1428
 
  Reopen the log file
1429
 
 
1430
 
  SYNOPSIS
1431
 
    reopen_file()
1432
 
 
1433
 
  DESCRIPTION
1434
 
    Reopen the log file. The method is used during FLUSH LOGS
1435
 
    and locks LOCK_log mutex
1436
 
*/
1437
 
 
1438
 
 
1439
 
void MYSQL_QUERY_LOG::reopen_file()
1440
 
{
1441
 
  char *save_name;
1442
 
 
1443
 
  DBUG_ENTER("MYSQL_LOG::reopen_file");
1444
 
  if (!is_open())
1445
 
  {
1446
 
    DBUG_PRINT("info",("log is closed"));
1447
 
    DBUG_VOID_RETURN;
1448
 
  }
1449
 
 
1450
 
  pthread_mutex_lock(&LOCK_log);
1451
 
 
1452
 
  save_name= name;
1453
 
  name= 0;                              // Don't free name
1454
 
  close(LOG_CLOSE_TO_BE_OPENED);
1455
 
 
1456
 
  /*
1457
 
     Note that at this point, log_state != LOG_CLOSED (important for is_open()).
1458
 
  */
1459
 
 
1460
 
  open(save_name, log_type, 0, io_cache_type);
1461
 
  my_free(save_name, MYF(0));
1462
 
 
1463
 
  pthread_mutex_unlock(&LOCK_log);
1464
 
 
1465
 
  DBUG_VOID_RETURN;
1466
 
}
1467
 
 
1468
 
 
1469
 
/*
1470
 
  Write a command to traditional general log file
1471
 
 
1472
 
  SYNOPSIS
1473
 
    write()
1474
 
 
1475
 
    event_time        command start timestamp
1476
 
    user_host         the pointer to the string with user@host info
1477
 
    user_host_len     length of the user_host string. this is computed once
1478
 
                      and passed to all general log  event handlers
1479
 
    thread_id         Id of the thread, issued a query
1480
 
    command_type      the type of the command being logged
1481
 
    command_type_len  the length of the string above
1482
 
    sql_text          the very text of the query being executed
1483
 
    sql_text_len      the length of sql_text string
1484
 
 
1485
 
  DESCRIPTION
1486
 
 
1487
 
   Log given command to to normal (not rotable) log file
1488
 
 
1489
 
  RETURN
1490
 
    FASE - OK
1491
 
    TRUE - error occured
1492
 
*/
1493
 
 
1494
 
bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host,
1495
 
                            uint user_host_len, int thread_id,
1496
 
                            const char *command_type, uint command_type_len,
1497
 
                            const char *sql_text, uint sql_text_len)
1498
 
{
1499
 
  char buff[32];
1500
 
  uint length= 0;
1501
 
  char local_time_buff[MAX_TIME_SIZE];
1502
 
  struct tm start;
1503
 
  uint time_buff_len= 0;
1504
 
 
1505
 
  (void) pthread_mutex_lock(&LOCK_log);
1506
 
 
1507
 
  /* Test if someone closed between the is_open test and lock */
1508
 
  if (is_open())
1509
 
  {
1510
 
    /* Note that my_b_write() assumes it knows the length for this */
1511
 
      if (event_time != last_time)
1512
 
      {
1513
 
        last_time= event_time;
1514
 
 
1515
 
        localtime_r(&event_time, &start);
1516
 
 
1517
 
        time_buff_len= my_snprintf(local_time_buff, MAX_TIME_SIZE,
1518
 
                                   "%02d%02d%02d %2d:%02d:%02d",
1519
 
                                   start.tm_year % 100, start.tm_mon + 1,
1520
 
                                   start.tm_mday, start.tm_hour,
1521
 
                                   start.tm_min, start.tm_sec);
1522
 
 
1523
 
        if (my_b_write(&log_file, (uchar*) local_time_buff, time_buff_len))
1524
 
          goto err;
1525
 
      }
1526
 
      else
1527
 
        if (my_b_write(&log_file, (uchar*) "\t\t" ,2) < 0)
1528
 
          goto err;
1529
 
 
1530
 
      /* command_type, thread_id */
1531
 
      length= my_snprintf(buff, 32, "%5ld ", (long) thread_id);
1532
 
 
1533
 
    if (my_b_write(&log_file, (uchar*) buff, length))
1534
 
      goto err;
1535
 
 
1536
 
    if (my_b_write(&log_file, (uchar*) command_type, command_type_len))
1537
 
      goto err;
1538
 
 
1539
 
    if (my_b_write(&log_file, (uchar*) "\t", 1))
1540
 
      goto err;
1541
 
 
1542
 
    /* sql_text */
1543
 
    if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len))
1544
 
      goto err;
1545
 
 
1546
 
    if (my_b_write(&log_file, (uchar*) "\n", 1) ||
1547
 
        flush_io_cache(&log_file))
1548
 
      goto err;
1549
 
  }
1550
 
 
1551
 
  (void) pthread_mutex_unlock(&LOCK_log);
1552
 
  return FALSE;
1553
 
err:
1554
 
 
1555
 
  if (!write_error)
1556
 
  {
1557
 
    write_error= 1;
1558
 
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
1559
 
  }
1560
 
  (void) pthread_mutex_unlock(&LOCK_log);
1561
 
  return TRUE;
1562
 
}
1563
 
 
1564
 
 
1565
 
/*
1566
 
  Log a query to the traditional slow log file
1567
 
 
1568
 
  SYNOPSIS
1569
 
    write()
1570
 
 
1571
 
    thd               THD of the query
1572
 
    current_time      current timestamp
1573
 
    query_start_arg   command start timestamp
1574
 
    user_host         the pointer to the string with user@host info
1575
 
    user_host_len     length of the user_host string. this is computed once
1576
 
                      and passed to all general log event handlers
1577
 
    query_utime       Amount of time the query took to execute (in microseconds)
1578
 
    lock_utime        Amount of time the query was locked (in microseconds)
1579
 
    is_command        The flag, which determines, whether the sql_text is a
1580
 
                      query or an administrator command.
1581
 
    sql_text          the very text of the query or administrator command
1582
 
                      processed
1583
 
    sql_text_len      the length of sql_text string
1584
 
 
1585
 
  DESCRIPTION
1586
 
 
1587
 
   Log a query to the slow log file.
1588
 
 
1589
 
  RETURN
1590
 
    FALSE - OK
1591
 
    TRUE - error occured
1592
 
*/
1593
 
 
1594
 
bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
1595
 
                            time_t query_start_arg, const char *user_host,
1596
 
                            uint user_host_len, ulonglong query_utime,
1597
 
                            ulonglong lock_utime, bool is_command,
1598
 
                            const char *sql_text, uint sql_text_len)
1599
 
{
1600
 
  bool error= 0;
1601
 
  DBUG_ENTER("MYSQL_QUERY_LOG::write");
1602
 
 
1603
 
  (void) pthread_mutex_lock(&LOCK_log);
1604
 
 
1605
 
  if (!is_open())
1606
 
  {
1607
 
    (void) pthread_mutex_unlock(&LOCK_log);
1608
 
    DBUG_RETURN(0);
1609
 
  }
1610
 
 
1611
 
  if (is_open())
1612
 
  {                                             // Safety agains reopen
1613
 
    int tmp_errno= 0;
1614
 
    char buff[80], *end;
1615
 
    char query_time_buff[22+7], lock_time_buff[22+7];
1616
 
    uint buff_len;
1617
 
    end= buff;
1618
 
 
1619
 
    if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
1620
 
    {
1621
 
      if (current_time != last_time)
1622
 
      {
1623
 
        last_time= current_time;
1624
 
        struct tm start;
1625
 
        localtime_r(&current_time, &start);
1626
 
 
1627
 
        buff_len= my_snprintf(buff, sizeof buff,
1628
 
                              "# Time: %02d%02d%02d %2d:%02d:%02d\n",
1629
 
                              start.tm_year % 100, start.tm_mon + 1,
1630
 
                              start.tm_mday, start.tm_hour,
1631
 
                              start.tm_min, start.tm_sec);
1632
 
 
1633
 
        /* Note that my_b_write() assumes it knows the length for this */
1634
 
        if (my_b_write(&log_file, (uchar*) buff, buff_len))
1635
 
          tmp_errno= errno;
1636
 
      }
1637
 
      const uchar uh[]= "# User@Host: ";
1638
 
      if (my_b_write(&log_file, uh, sizeof(uh) - 1))
1639
 
        tmp_errno= errno;
1640
 
      if (my_b_write(&log_file, (uchar*) user_host, user_host_len))
1641
 
        tmp_errno= errno;
1642
 
      if (my_b_write(&log_file, (uchar*) "\n", 1))
1643
 
        tmp_errno= errno;
1644
 
    }
1645
 
    /* For slow query log */
1646
 
    sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
1647
 
    sprintf(lock_time_buff,  "%.6f", ulonglong2double(lock_utime)/1000000.0);
1648
 
    if (my_b_printf(&log_file,
1649
 
                    "# Query_time: %s  Lock_time: %s"
1650
 
                    " Rows_sent: %lu  Rows_examined: %lu\n",
1651
 
                    query_time_buff, lock_time_buff,
1652
 
                    (ulong) thd->sent_row_count,
1653
 
                    (ulong) thd->examined_row_count) == (uint) -1)
1654
 
      tmp_errno= errno;
1655
 
    if (thd->db && strcmp(thd->db, db))
1656
 
    {                                           // Database changed
1657
 
      if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
1658
 
        tmp_errno= errno;
1659
 
      strmov(db,thd->db);
1660
 
    }
1661
 
    if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
1662
 
    {
1663
 
      end=strmov(end, ",last_insert_id=");
1664
 
      end=longlong10_to_str((longlong)
1665
 
                            thd->first_successful_insert_id_in_prev_stmt_for_binlog,
1666
 
                            end, -10);
1667
 
    }
1668
 
    // Save value if we do an insert.
1669
 
    if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
1670
 
    {
1671
 
      if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
1672
 
      {
1673
 
        end=strmov(end,",insert_id=");
1674
 
        end=longlong10_to_str((longlong)
1675
 
                              thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(),
1676
 
                              end, -10);
1677
 
      }
1678
 
    }
1679
 
 
1680
 
    /*
1681
 
      This info used to show up randomly, depending on whether the query
1682
 
      checked the query start time or not. now we always write current
1683
 
      timestamp to the slow log
1684
 
    */
1685
 
    end= strmov(end, ",timestamp=");
1686
 
    end= int10_to_str((long) current_time, end, 10);
1687
 
 
1688
 
    if (end != buff)
1689
 
    {
1690
 
      *end++=';';
1691
 
      *end='\n';
1692
 
      if (my_b_write(&log_file, (uchar*) "SET ", 4) ||
1693
 
          my_b_write(&log_file, (uchar*) buff + 1, (uint) (end-buff)))
1694
 
        tmp_errno= errno;
1695
 
    }
1696
 
    if (is_command)
1697
 
    {
1698
 
      end= strxmov(buff, "# administrator command: ", NullS);
1699
 
      buff_len= (ulong) (end - buff);
1700
 
      my_b_write(&log_file, (uchar*) buff, buff_len);
1701
 
    }
1702
 
    if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len) ||
1703
 
        my_b_write(&log_file, (uchar*) ";\n",2) ||
1704
 
        flush_io_cache(&log_file))
1705
 
      tmp_errno= errno;
1706
 
    if (tmp_errno)
1707
 
    {
1708
 
      error= 1;
1709
 
      if (! write_error)
1710
 
      {
1711
 
        write_error= 1;
1712
 
        sql_print_error(ER(ER_ERROR_ON_WRITE), name, error);
1713
 
      }
1714
 
    }
1715
 
  }
1716
 
  (void) pthread_mutex_unlock(&LOCK_log);
1717
 
  DBUG_RETURN(error);
1718
 
}
1719
 
 
1720
 
 
1721
1026
/**
1722
1027
  @todo
1723
1028
  The following should be using fn_format();  We just need to
1724
1029
  first change fn_format() to cut the file name if it's too long.
1725
1030
*/
1726
 
const char *MYSQL_LOG::generate_name(const char *log_name,
 
1031
const char *DRIZZLE_LOG::generate_name(const char *log_name,
1727
1032
                                      const char *suffix,
1728
1033
                                      bool strip_ext, char *buff)
1729
1034
{
1737
1042
  if (strip_ext)
1738
1043
  {
1739
1044
    char *p= fn_ext(log_name);
1740
 
    uint length= (uint) (p - log_name);
1741
 
    strmake(buff, log_name, min(length, FN_REFLEN));
 
1045
    uint32_t length= (uint) (p - log_name);
 
1046
    strmake(buff, log_name, cmin(length, (uint)FN_REFLEN));
1742
1047
    return (const char*)buff;
1743
1048
  }
1744
1049
  return log_name;
1746
1051
 
1747
1052
 
1748
1053
 
1749
 
MYSQL_BIN_LOG::MYSQL_BIN_LOG()
 
1054
DRIZZLE_BIN_LOG::DRIZZLE_BIN_LOG()
1750
1055
  :bytes_written(0), prepared_xids(0), file_id(1), open_count(1),
1751
 
   need_start_event(TRUE), m_table_map_version(0),
 
1056
   need_start_event(true), m_table_map_version(0),
1752
1057
   description_event_for_exec(0), description_event_for_queue(0)
1753
1058
{
1754
1059
  /*
1758
1063
    before main().
1759
1064
  */
1760
1065
  index_file_name[0] = 0;
1761
 
  bzero((char*) &index_file, sizeof(index_file));
 
1066
  memset(&index_file, 0, sizeof(index_file));
1762
1067
}
1763
1068
 
1764
1069
/* this is called only once */
1765
1070
 
1766
 
void MYSQL_BIN_LOG::cleanup()
 
1071
void DRIZZLE_BIN_LOG::cleanup()
1767
1072
{
1768
 
  DBUG_ENTER("cleanup");
1769
1073
  if (inited)
1770
1074
  {
1771
1075
    inited= 0;
1776
1080
    (void) pthread_mutex_destroy(&LOCK_index);
1777
1081
    (void) pthread_cond_destroy(&update_cond);
1778
1082
  }
1779
 
  DBUG_VOID_RETURN;
 
1083
  return;
1780
1084
}
1781
1085
 
1782
1086
 
1783
1087
/* Init binlog-specific vars */
1784
 
void MYSQL_BIN_LOG::init(bool no_auto_events_arg, ulong max_size_arg)
 
1088
void DRIZZLE_BIN_LOG::init(bool no_auto_events_arg, ulong max_size_arg)
1785
1089
{
1786
 
  DBUG_ENTER("MYSQL_BIN_LOG::init");
1787
1090
  no_auto_events= no_auto_events_arg;
1788
1091
  max_size= max_size_arg;
1789
 
  DBUG_PRINT("info",("max_size: %lu", max_size));
1790
 
  DBUG_VOID_RETURN;
 
1092
  return;
1791
1093
}
1792
1094
 
1793
1095
 
1794
 
void MYSQL_BIN_LOG::init_pthread_objects()
 
1096
void DRIZZLE_BIN_LOG::init_pthread_objects()
1795
1097
{
1796
 
  DBUG_ASSERT(inited == 0);
 
1098
  assert(inited == 0);
1797
1099
  inited= 1;
1798
1100
  (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW);
1799
1101
  (void) pthread_mutex_init(&LOCK_index, MY_MUTEX_INIT_SLOW);
1801
1103
}
1802
1104
 
1803
1105
 
1804
 
bool MYSQL_BIN_LOG::open_index_file(const char *index_file_name_arg,
 
1106
bool DRIZZLE_BIN_LOG::open_index_file(const char *index_file_name_arg,
1805
1107
                                const char *log_name)
1806
1108
{
1807
1109
  File index_file_nr= -1;
1808
 
  DBUG_ASSERT(!my_b_inited(&index_file));
 
1110
  assert(!my_b_inited(&index_file));
1809
1111
 
1810
1112
  /*
1811
1113
    First open of this class instance
1821
1123
  fn_format(index_file_name, index_file_name_arg, mysql_data_home,
1822
1124
            ".index", opt);
1823
1125
  if ((index_file_nr= my_open(index_file_name,
1824
 
                              O_RDWR | O_CREAT | O_BINARY ,
 
1126
                              O_RDWR | O_CREAT,
1825
1127
                              MYF(MY_WME))) < 0 ||
1826
1128
       my_sync(index_file_nr, MYF(MY_WME)) ||
1827
1129
       init_io_cache(&index_file, index_file_nr,
1836
1138
    */
1837
1139
    if (index_file_nr >= 0)
1838
1140
      my_close(index_file_nr,MYF(0));
1839
 
    return TRUE;
 
1141
    return true;
1840
1142
  }
1841
 
  return FALSE;
 
1143
  return false;
1842
1144
}
1843
1145
 
1844
1146
 
1856
1158
    1   error
1857
1159
*/
1858
1160
 
1859
 
bool MYSQL_BIN_LOG::open(const char *log_name,
 
1161
bool DRIZZLE_BIN_LOG::open(const char *log_name,
1860
1162
                         enum_log_type log_type_arg,
1861
1163
                         const char *new_name,
1862
1164
                         enum cache_type io_cache_type_arg,
1865
1167
                         bool null_created_arg)
1866
1168
{
1867
1169
  File file= -1;
1868
 
  DBUG_ENTER("MYSQL_BIN_LOG::open");
1869
 
  DBUG_PRINT("enter",("log_type: %d",(int) log_type_arg));
1870
1170
 
1871
1171
  write_error=0;
1872
1172
 
1873
1173
  /* open the main log file */
1874
 
  if (MYSQL_LOG::open(log_name, log_type_arg, new_name, io_cache_type_arg))
1875
 
    DBUG_RETURN(1);                            /* all warnings issued */
 
1174
  if (DRIZZLE_LOG::open(log_name, log_type_arg, new_name, io_cache_type_arg))
 
1175
    return(1);                            /* all warnings issued */
1876
1176
 
1877
1177
  init(no_auto_events_arg, max_size_arg);
1878
1178
 
1879
1179
  open_count++;
1880
1180
 
1881
 
  DBUG_ASSERT(log_type == LOG_BIN);
 
1181
  assert(log_type == LOG_BIN);
1882
1182
 
1883
1183
  {
1884
1184
    bool write_file_name_to_index_file=0;
1891
1191
        an extension for the binary log files.
1892
1192
        In this case we write a standard header to it.
1893
1193
      */
1894
 
      if (my_b_safe_write(&log_file, (uchar*) BINLOG_MAGIC,
 
1194
      if (my_b_safe_write(&log_file, (unsigned char*) BINLOG_MAGIC,
1895
1195
                          BIN_LOG_HEADER_SIZE))
1896
1196
        goto err;
1897
1197
      bytes_written+= BIN_LOG_HEADER_SIZE;
1898
1198
      write_file_name_to_index_file= 1;
1899
1199
    }
1900
1200
 
1901
 
    DBUG_ASSERT(my_b_inited(&index_file) != 0);
 
1201
    assert(my_b_inited(&index_file) != 0);
1902
1202
    reinit_io_cache(&index_file, WRITE_CACHE,
1903
1203
                    my_b_filelength(&index_file), 0, 0);
1904
1204
    if (need_start_event && !no_auto_events)
1962
1262
        As this is a new log file, we write the file name to the index
1963
1263
        file. As every time we write to the index file, we sync it.
1964
1264
      */
1965
 
      if (my_b_write(&index_file, (uchar*) log_file_name,
 
1265
      if (my_b_write(&index_file, (unsigned char*) log_file_name,
1966
1266
                     strlen(log_file_name)) ||
1967
 
          my_b_write(&index_file, (uchar*) "\n", 1) ||
 
1267
          my_b_write(&index_file, (unsigned char*) "\n", 1) ||
1968
1268
          flush_io_cache(&index_file) ||
1969
1269
          my_sync(index_file.file, MYF(MY_WME)))
1970
1270
        goto err;
1972
1272
  }
1973
1273
  log_state= LOG_OPENED;
1974
1274
 
1975
 
  DBUG_RETURN(0);
 
1275
  return(0);
1976
1276
 
1977
1277
err:
1978
 
  sql_print_error("Could not use %s for logging (error %d). \
1979
 
Turning logging off for the whole duration of the MySQL server process. \
1980
 
To turn it on again: fix the cause, \
1981
 
shutdown the MySQL server and restart it.", name, errno);
 
1278
  sql_print_error(_("Could not use %s for logging (error %d). "
 
1279
                    "Turning logging off for the whole duration of the "
 
1280
                    "Drizzle server process. "
 
1281
                    "To turn it on again: fix the cause, "
 
1282
                    "shutdown the Drizzle server and restart it."),
 
1283
                    name, errno);
1982
1284
  if (file >= 0)
1983
1285
    my_close(file,MYF(0));
1984
1286
  end_io_cache(&log_file);
1985
1287
  end_io_cache(&index_file);
1986
 
  safeFree(name);
 
1288
  if (name)
 
1289
  {
 
1290
    free(name);
 
1291
    name= NULL;
 
1292
  }
1987
1293
  log_state= LOG_CLOSED;
1988
 
  DBUG_RETURN(1);
 
1294
  return(1);
1989
1295
}
1990
1296
 
1991
1297
 
1992
 
int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo)
 
1298
int DRIZZLE_BIN_LOG::get_current_log(LOG_INFO* linfo)
1993
1299
{
1994
1300
  pthread_mutex_lock(&LOCK_log);
1995
1301
  int ret = raw_get_current_log(linfo);
1997
1303
  return ret;
1998
1304
}
1999
1305
 
2000
 
int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO* linfo)
 
1306
int DRIZZLE_BIN_LOG::raw_get_current_log(LOG_INFO* linfo)
2001
1307
{
2002
1308
  strmake(linfo->log_file_name, log_file_name, sizeof(linfo->log_file_name)-1);
2003
1309
  linfo->pos = my_b_tell(&log_file);
2021
1327
    0   ok
2022
1328
*/
2023
1329
 
2024
 
#ifdef HAVE_REPLICATION
2025
 
 
2026
1330
static bool copy_up_file_and_fill(IO_CACHE *index_file, my_off_t offset)
2027
1331
{
2028
1332
  int bytes_read;
2029
1333
  my_off_t init_offset= offset;
2030
1334
  File file= index_file->file;
2031
 
  uchar io_buf[IO_SIZE*2];
2032
 
  DBUG_ENTER("copy_up_file_and_fill");
 
1335
  unsigned char io_buf[IO_SIZE*2];
2033
1336
 
2034
1337
  for (;; offset+= bytes_read)
2035
1338
  {
2049
1352
 
2050
1353
  /* Reset data in old index cache */
2051
1354
  reinit_io_cache(index_file, READ_CACHE, (my_off_t) 0, 0, 1);
2052
 
  DBUG_RETURN(0);
 
1355
  return(0);
2053
1356
 
2054
1357
err:
2055
 
  DBUG_RETURN(1);
 
1358
  return(1);
2056
1359
}
2057
1360
 
2058
 
#endif /* HAVE_REPLICATION */
2059
 
 
2060
1361
/**
2061
1362
  Find the position in the log-index-file for the given log name.
2062
1363
 
2079
1380
    LOG_INFO_IO         Got IO error while reading file
2080
1381
*/
2081
1382
 
2082
 
int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
 
1383
int DRIZZLE_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
2083
1384
                            bool need_lock)
2084
1385
{
2085
1386
  int error= 0;
2086
1387
  char *fname= linfo->log_file_name;
2087
 
  uint log_name_len= log_name ? (uint) strlen(log_name) : 0;
2088
 
  DBUG_ENTER("find_log_pos");
2089
 
  DBUG_PRINT("enter",("log_name: %s", log_name ? log_name : "NULL"));
 
1388
  uint32_t log_name_len= log_name ? (uint) strlen(log_name) : 0;
2090
1389
 
2091
1390
  /*
2092
1391
    Mutex needed because we need to make sure the file pointer does not
2101
1400
 
2102
1401
  for (;;)
2103
1402
  {
2104
 
    uint length;
 
1403
    uint32_t length;
2105
1404
    my_off_t offset= my_b_tell(&index_file);
2106
1405
    /* If we get 0 or 1 characters, this is the end of the file */
2107
1406
 
2117
1416
        (log_name_len == length-1 && fname[log_name_len] == '\n' &&
2118
1417
         !memcmp(fname, log_name, log_name_len)))
2119
1418
    {
2120
 
      DBUG_PRINT("info",("Found log file entry"));
2121
1419
      fname[length-1]=0;                        // remove last \n
2122
1420
      linfo->index_file_start_offset= offset;
2123
1421
      linfo->index_file_offset = my_b_tell(&index_file);
2127
1425
 
2128
1426
  if (need_lock)
2129
1427
    pthread_mutex_unlock(&LOCK_index);
2130
 
  DBUG_RETURN(error);
 
1428
  return(error);
2131
1429
}
2132
1430
 
2133
1431
 
2155
1453
    LOG_INFO_IO         Got IO error while reading file
2156
1454
*/
2157
1455
 
2158
 
int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
 
1456
int DRIZZLE_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
2159
1457
{
2160
1458
  int error= 0;
2161
 
  uint length;
 
1459
  uint32_t length;
2162
1460
  char *fname= linfo->log_file_name;
2163
1461
 
2164
1462
  if (need_lock)
2202
1500
    1   error
2203
1501
*/
2204
1502
 
2205
 
bool MYSQL_BIN_LOG::reset_logs(THD* thd)
 
1503
bool DRIZZLE_BIN_LOG::reset_logs(THD* thd)
2206
1504
{
2207
1505
  LOG_INFO linfo;
2208
1506
  bool error=0;
2209
1507
  const char* save_name;
2210
 
  DBUG_ENTER("reset_logs");
2211
1508
 
2212
 
  ha_reset_logs(thd);
2213
1509
  /*
2214
1510
    We need to get both locks to be sure that no one is trying to
2215
1511
    write to the index log file.
2223
1519
    thread. If the transaction involved MyISAM tables, it should go
2224
1520
    into binlog even on rollback.
2225
1521
  */
2226
 
  VOID(pthread_mutex_lock(&LOCK_thread_count));
 
1522
  pthread_mutex_lock(&LOCK_thread_count);
2227
1523
 
2228
1524
  /* Save variables so that we can reopen the log */
2229
1525
  save_name=name;
2232
1528
 
2233
1529
  /* First delete all old log files */
2234
1530
 
2235
 
  if (find_log_pos(&linfo, NullS, 0))
 
1531
  if (find_log_pos(&linfo, NULL, 0))
2236
1532
  {
2237
1533
    error=1;
2238
1534
    goto err;
2244
1540
    {
2245
1541
      if (my_errno == ENOENT) 
2246
1542
      {
2247
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1543
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2248
1544
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2249
1545
                            linfo.log_file_name);
2250
 
        sql_print_information("Failed to delete file '%s'",
 
1546
        sql_print_information(_("Failed to delete file '%s'"),
2251
1547
                              linfo.log_file_name);
2252
1548
        my_errno= 0;
2253
1549
        error= 0;
2254
1550
      }
2255
1551
      else
2256
1552
      {
2257
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1553
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2258
1554
                            ER_BINLOG_PURGE_FATAL_ERR,
2259
 
                            "a problem with deleting %s; "
 
1555
                            _("a problem with deleting %s; "
2260
1556
                            "consider examining correspondence "
2261
1557
                            "of your binlog index file "
2262
 
                            "to the actual binlog files",
 
1558
                            "to the actual binlog files"),
2263
1559
                            linfo.log_file_name);
2264
1560
        error= 1;
2265
1561
        goto err;
2275
1571
  {
2276
1572
    if (my_errno == ENOENT) 
2277
1573
    {
2278
 
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1574
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2279
1575
                          ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2280
1576
                          index_file_name);
2281
 
      sql_print_information("Failed to delete file '%s'",
 
1577
      sql_print_information(_("Failed to delete file '%s'"),
2282
1578
                            index_file_name);
2283
1579
      my_errno= 0;
2284
1580
      error= 0;
2285
1581
    }
2286
1582
    else
2287
1583
    {
2288
 
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1584
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2289
1585
                          ER_BINLOG_PURGE_FATAL_ERR,
2290
1586
                          "a problem with deleting %s; "
2291
1587
                          "consider examining correspondence "
2300
1596
    need_start_event=1;
2301
1597
  if (!open_index_file(index_file_name, 0))
2302
1598
    open(save_name, log_type, 0, io_cache_type, no_auto_events, max_size, 0);
2303
 
  my_free((uchar*) save_name, MYF(0));
 
1599
  free((unsigned char*) save_name);
2304
1600
 
2305
1601
err:
2306
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1602
  pthread_mutex_unlock(&LOCK_thread_count);
2307
1603
  pthread_mutex_unlock(&LOCK_index);
2308
1604
  pthread_mutex_unlock(&LOCK_log);
2309
 
  DBUG_RETURN(error);
 
1605
  return(error);
2310
1606
}
2311
1607
 
2312
1608
 
2347
1643
    LOG_INFO_IO         Got IO error while reading file
2348
1644
*/
2349
1645
 
2350
 
#ifdef HAVE_REPLICATION
2351
1646
 
2352
 
int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
 
1647
int DRIZZLE_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
2353
1648
{
2354
1649
  int error;
2355
 
  DBUG_ENTER("purge_first_log");
2356
1650
 
2357
 
  DBUG_ASSERT(is_open());
2358
 
  DBUG_ASSERT(rli->slave_running == 1);
2359
 
  DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name));
 
1651
  assert(is_open());
 
1652
  assert(rli->slave_running == 1);
 
1653
  assert(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name.c_str()));
2360
1654
 
2361
1655
  pthread_mutex_lock(&LOCK_index);
2362
1656
  pthread_mutex_lock(&rli->log_space_lock);
2363
 
  rli->relay_log.purge_logs(rli->group_relay_log_name, included,
 
1657
  rli->relay_log.purge_logs(rli->group_relay_log_name.c_str(), included,
2364
1658
                            0, 0, &rli->log_space_total);
2365
1659
  // Tell the I/O thread to take the relay_log_space_limit into account
2366
1660
  rli->ignore_log_space_limit= 0;
2379
1673
    If included is true, we want the first relay log;
2380
1674
    otherwise we want the one after event_relay_log_name.
2381
1675
  */
2382
 
  if ((included && (error=find_log_pos(&rli->linfo, NullS, 0))) ||
 
1676
  if ((included && (error=find_log_pos(&rli->linfo, NULL, 0))) ||
2383
1677
      (!included &&
2384
 
       ((error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0)) ||
 
1678
       ((error=find_log_pos(&rli->linfo, rli->event_relay_log_name.c_str(), 0)) ||
2385
1679
        (error=find_next_log(&rli->linfo, 0)))))
2386
1680
  {
2387
1681
    char buff[22];
2388
 
    sql_print_error("next log error: %d  offset: %s  log: %s included: %d",
 
1682
    sql_print_error(_("next log error: %d  offset: %s  log: %s included: %d"),
2389
1683
                    error,
2390
1684
                    llstr(rli->linfo.index_file_offset,buff),
2391
 
                    rli->group_relay_log_name,
 
1685
                    rli->group_relay_log_name.c_str(),
2392
1686
                    included);
2393
1687
    goto err;
2394
1688
  }
2397
1691
    Reset rli's coordinates to the current log.
2398
1692
  */
2399
1693
  rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
2400
 
  strmake(rli->event_relay_log_name,rli->linfo.log_file_name,
2401
 
          sizeof(rli->event_relay_log_name)-1);
 
1694
  rli->event_relay_log_name.assign(rli->linfo.log_file_name);
2402
1695
 
2403
1696
  /*
2404
1697
    If we removed the rli->group_relay_log_name file,
2408
1701
  if (included)
2409
1702
  {
2410
1703
    rli->group_relay_log_pos = BIN_LOG_HEADER_SIZE;
2411
 
    strmake(rli->group_relay_log_name,rli->linfo.log_file_name,
2412
 
            sizeof(rli->group_relay_log_name)-1);
 
1704
    rli->group_relay_log_name.assign(rli->linfo.log_file_name);
2413
1705
    rli->notify_group_relay_log_name_update();
2414
1706
  }
2415
1707
 
2418
1710
 
2419
1711
err:
2420
1712
  pthread_mutex_unlock(&LOCK_index);
2421
 
  DBUG_RETURN(error);
 
1713
  return(error);
2422
1714
}
2423
1715
 
2424
1716
/**
2425
1717
  Update log index_file.
2426
1718
*/
2427
1719
 
2428
 
int MYSQL_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads)
 
1720
int DRIZZLE_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads)
2429
1721
{
2430
1722
  if (copy_up_file_and_fill(&index_file, log_info->index_file_start_offset))
2431
1723
    return LOG_INFO_IO;
2460
1752
                                stat() or my_delete()
2461
1753
*/
2462
1754
 
2463
 
int MYSQL_BIN_LOG::purge_logs(const char *to_log, 
 
1755
int DRIZZLE_BIN_LOG::purge_logs(const char *to_log, 
2464
1756
                          bool included,
2465
1757
                          bool need_mutex, 
2466
1758
                          bool need_update_threads, 
2467
 
                          ulonglong *decrease_log_space)
 
1759
                          uint64_t *decrease_log_space)
2468
1760
{
2469
1761
  int error;
2470
1762
  int ret = 0;
2471
1763
  bool exit_loop= 0;
2472
1764
  LOG_INFO log_info;
2473
 
  DBUG_ENTER("purge_logs");
2474
 
  DBUG_PRINT("info",("to_log= %s",to_log));
2475
1765
 
2476
1766
  if (need_mutex)
2477
1767
    pthread_mutex_lock(&LOCK_index);
2482
1772
    File name exists in index file; delete until we find this file
2483
1773
    or a file that is used.
2484
1774
  */
2485
 
  if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
 
1775
  if ((error=find_log_pos(&log_info, NULL, 0 /*no mutex*/)))
2486
1776
    goto err;
2487
1777
  while ((strcmp(to_log,log_info.log_file_name) || (exit_loop=included)) &&
2488
1778
         !log_in_use(log_info.log_file_name))
2496
1786
          It's not fatal if we can't stat a log file that does not exist;
2497
1787
          If we could not stat, we won't delete.
2498
1788
        */     
2499
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1789
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2500
1790
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2501
1791
                            log_info.log_file_name);
2502
 
        sql_print_information("Failed to execute stat on file '%s'",
 
1792
        sql_print_information(_("Failed to execute stat() on file '%s'"),
2503
1793
                              log_info.log_file_name);
2504
1794
        my_errno= 0;
2505
1795
      }
2508
1798
        /*
2509
1799
          Other than ENOENT are fatal
2510
1800
        */
2511
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1801
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2512
1802
                            ER_BINLOG_PURGE_FATAL_ERR,
2513
 
                            "a problem with getting info on being purged %s; "
 
1803
                            _("a problem with getting info on being purged %s; "
2514
1804
                            "consider examining correspondence "
2515
1805
                            "of your binlog index file "
2516
 
                            "to the actual binlog files",
 
1806
                            "to the actual binlog files"),
2517
1807
                            log_info.log_file_name);
2518
1808
        error= LOG_INFO_FATAL;
2519
1809
        goto err;
2521
1811
    }
2522
1812
    else
2523
1813
    {
2524
 
      DBUG_PRINT("info",("purging %s",log_info.log_file_name));
2525
1814
      if (!my_delete(log_info.log_file_name, MYF(0)))
2526
1815
      {
2527
1816
        if (decrease_log_space)
2531
1820
      {
2532
1821
        if (my_errno == ENOENT) 
2533
1822
        {
2534
 
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1823
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2535
1824
                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2536
1825
                              log_info.log_file_name);
2537
 
          sql_print_information("Failed to delete file '%s'",
 
1826
          sql_print_information(_("Failed to delete file '%s'"),
2538
1827
                                log_info.log_file_name);
2539
1828
          my_errno= 0;
2540
1829
        }
2541
1830
        else
2542
1831
        {
2543
 
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1832
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2544
1833
                              ER_BINLOG_PURGE_FATAL_ERR,
2545
 
                              "a problem with deleting %s; "
 
1834
                              _("a problem with deleting %s; "
2546
1835
                              "consider examining correspondence "
2547
1836
                              "of your binlog index file "
2548
 
                              "to the actual binlog files",
 
1837
                              "to the actual binlog files"),
2549
1838
                              log_info.log_file_name);
2550
1839
          if (my_errno == EMFILE)
2551
1840
          {
2552
 
            DBUG_PRINT("info",
2553
 
                       ("my_errno: %d, set ret = LOG_INFO_EMFILE", my_errno));
2554
1841
            error= LOG_INFO_EMFILE;
2555
1842
          }
2556
1843
          error= LOG_INFO_FATAL;
2559
1846
      }
2560
1847
    }
2561
1848
 
2562
 
    ha_binlog_index_purge_file(current_thd, log_info.log_file_name);
2563
 
 
2564
1849
    if (find_next_log(&log_info, 0) || exit_loop)
2565
1850
      break;
2566
1851
  }
2577
1862
err:
2578
1863
  if (need_mutex)
2579
1864
    pthread_mutex_unlock(&LOCK_index);
2580
 
  DBUG_RETURN(error);
 
1865
  return(error);
2581
1866
}
2582
1867
 
2583
1868
/**
2599
1884
                                stat() or my_delete()
2600
1885
*/
2601
1886
 
2602
 
int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time)
 
1887
int DRIZZLE_BIN_LOG::purge_logs_before_date(time_t purge_time)
2603
1888
{
2604
1889
  int error;
2605
1890
  LOG_INFO log_info;
2606
1891
  struct stat stat_area;
2607
1892
 
2608
 
  DBUG_ENTER("purge_logs_before_date");
2609
 
 
2610
1893
  pthread_mutex_lock(&LOCK_index);
2611
1894
 
2612
1895
  /*
2614
1897
    or a file that is used or a file
2615
1898
    that is older than purge_time.
2616
1899
  */
2617
 
  if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
 
1900
  if ((error=find_log_pos(&log_info, NULL, 0 /*no mutex*/)))
2618
1901
    goto err;
2619
1902
 
2620
1903
  while (strcmp(log_file_name, log_info.log_file_name) &&
2627
1910
        /*
2628
1911
          It's not fatal if we can't stat a log file that does not exist.
2629
1912
        */     
2630
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1913
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2631
1914
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2632
1915
                            log_info.log_file_name);
2633
 
        sql_print_information("Failed to execute stat on file '%s'",
 
1916
        sql_print_information(_("Failed to execute stat() on file '%s'"),
2634
1917
                              log_info.log_file_name);
2635
1918
        my_errno= 0;
2636
1919
      }
2639
1922
        /*
2640
1923
          Other than ENOENT are fatal
2641
1924
        */
2642
 
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1925
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2643
1926
                            ER_BINLOG_PURGE_FATAL_ERR,
2644
 
                            "a problem with getting info on being purged %s; "
 
1927
                            _("a problem with getting info on being purged %s; "
2645
1928
                            "consider examining correspondence "
2646
1929
                            "of your binlog index file "
2647
 
                            "to the actual binlog files",
 
1930
                            "to the actual binlog files"),
2648
1931
                            log_info.log_file_name);
2649
1932
        error= LOG_INFO_FATAL;
2650
1933
        goto err;
2659
1942
        if (my_errno == ENOENT) 
2660
1943
        {
2661
1944
          /* It's not fatal even if we can't delete a log file */
2662
 
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1945
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2663
1946
                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
2664
1947
                              log_info.log_file_name);
2665
 
          sql_print_information("Failed to delete file '%s'",
 
1948
          sql_print_information(_("Failed to delete file '%s'"),
2666
1949
                                log_info.log_file_name);
2667
1950
          my_errno= 0;
2668
1951
        }
2669
1952
        else
2670
1953
        {
2671
 
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
 
1954
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2672
1955
                              ER_BINLOG_PURGE_FATAL_ERR,
2673
 
                              "a problem with deleting %s; "
 
1956
                              _("a problem with deleting %s; "
2674
1957
                              "consider examining correspondence "
2675
1958
                              "of your binlog index file "
2676
 
                              "to the actual binlog files",
 
1959
                              "to the actual binlog files"),
2677
1960
                              log_info.log_file_name);
2678
1961
          error= LOG_INFO_FATAL;
2679
1962
          goto err;
2680
1963
        }
2681
1964
      }
2682
 
      ha_binlog_index_purge_file(current_thd, log_info.log_file_name);
2683
1965
    }
2684
1966
    if (find_next_log(&log_info, 0))
2685
1967
      break;
2693
1975
 
2694
1976
err:
2695
1977
  pthread_mutex_unlock(&LOCK_index);
2696
 
  DBUG_RETURN(error);
 
1978
  return(error);
2697
1979
}
2698
 
#endif /* HAVE_REPLICATION */
2699
1980
 
2700
1981
 
2701
1982
/**
2707
1988
    If file name will be longer then FN_REFLEN it will be truncated
2708
1989
*/
2709
1990
 
2710
 
void MYSQL_BIN_LOG::make_log_name(char* buf, const char* log_ident)
 
1991
void DRIZZLE_BIN_LOG::make_log_name(char* buf, const char* log_ident)
2711
1992
{
2712
 
  uint dir_len = dirname_length(log_file_name); 
 
1993
  uint32_t dir_len = dirname_length(log_file_name); 
2713
1994
  if (dir_len >= FN_REFLEN)
2714
1995
    dir_len=FN_REFLEN-1;
2715
 
  strnmov(buf, log_file_name, dir_len);
 
1996
  my_stpncpy(buf, log_file_name, dir_len);
2716
1997
  strmake(buf+dir_len, log_ident, FN_REFLEN - dir_len -1);
2717
1998
}
2718
1999
 
2721
2002
  Check if we are writing/reading to the given log file.
2722
2003
*/
2723
2004
 
2724
 
bool MYSQL_BIN_LOG::is_active(const char *log_file_name_arg)
 
2005
bool DRIZZLE_BIN_LOG::is_active(const char *log_file_name_arg)
2725
2006
{
2726
2007
  return !strcmp(log_file_name, log_file_name_arg);
2727
2008
}
2735
2016
  method).
2736
2017
*/
2737
2018
 
2738
 
void MYSQL_BIN_LOG::new_file()
 
2019
void DRIZZLE_BIN_LOG::new_file()
2739
2020
{
2740
2021
  new_file_impl(1);
2741
2022
}
2742
2023
 
2743
2024
 
2744
 
void MYSQL_BIN_LOG::new_file_without_locking()
 
2025
void DRIZZLE_BIN_LOG::new_file_without_locking()
2745
2026
{
2746
2027
  new_file_impl(0);
2747
2028
}
2756
2037
    The new file name is stored last in the index file
2757
2038
*/
2758
2039
 
2759
 
void MYSQL_BIN_LOG::new_file_impl(bool need_lock)
 
2040
void DRIZZLE_BIN_LOG::new_file_impl(bool need_lock)
2760
2041
{
2761
2042
  char new_name[FN_REFLEN], *new_name_ptr, *old_name;
2762
2043
 
2763
 
  DBUG_ENTER("MYSQL_BIN_LOG::new_file_impl");
2764
2044
  if (!is_open())
2765
2045
  {
2766
 
    DBUG_PRINT("info",("log is closed"));
2767
 
    DBUG_VOID_RETURN;
 
2046
    return;
2768
2047
  }
2769
2048
 
2770
2049
  if (need_lock)
2788
2067
    tc_log_page_waits++;
2789
2068
    pthread_mutex_lock(&LOCK_prep_xids);
2790
2069
    while (prepared_xids) {
2791
 
      DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
2792
2070
      pthread_cond_wait(&COND_prep_xids, &LOCK_prep_xids);
2793
2071
    }
2794
2072
    pthread_mutex_unlock(&LOCK_prep_xids);
2845
2123
 
2846
2124
  open(old_name, log_type, new_name_ptr,
2847
2125
       io_cache_type, no_auto_events, max_size, 1);
2848
 
  my_free(old_name,MYF(0));
 
2126
  free(old_name);
2849
2127
 
2850
2128
end:
2851
2129
  if (need_lock)
2852
2130
    pthread_mutex_unlock(&LOCK_log);
2853
2131
  pthread_mutex_unlock(&LOCK_index);
2854
2132
 
2855
 
  DBUG_VOID_RETURN;
 
2133
  return;
2856
2134
}
2857
2135
 
2858
2136
 
2859
 
bool MYSQL_BIN_LOG::append(Log_event* ev)
 
2137
bool DRIZZLE_BIN_LOG::append(Log_event* ev)
2860
2138
{
2861
2139
  bool error = 0;
2862
2140
  pthread_mutex_lock(&LOCK_log);
2863
 
  DBUG_ENTER("MYSQL_BIN_LOG::append");
2864
2141
 
2865
 
  DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
 
2142
  assert(log_file.type == SEQ_READ_APPEND);
2866
2143
  /*
2867
2144
    Log_event::write() is smart enough to use my_b_write() or
2868
2145
    my_b_append() depending on the kind of cache we have.
2873
2150
    goto err;
2874
2151
  }
2875
2152
  bytes_written+= ev->data_written;
2876
 
  DBUG_PRINT("info",("max_size: %lu",max_size));
2877
2153
  if ((uint) my_b_append_tell(&log_file) > max_size)
2878
2154
    new_file_without_locking();
2879
2155
 
2880
2156
err:
2881
2157
  pthread_mutex_unlock(&LOCK_log);
2882
2158
  signal_update();                              // Safe as we don't call close
2883
 
  DBUG_RETURN(error);
 
2159
  return(error);
2884
2160
}
2885
2161
 
2886
2162
 
2887
 
bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
 
2163
bool DRIZZLE_BIN_LOG::appendv(const char* buf, uint32_t len,...)
2888
2164
{
2889
2165
  bool error= 0;
2890
 
  DBUG_ENTER("MYSQL_BIN_LOG::appendv");
2891
2166
  va_list(args);
2892
2167
  va_start(args,len);
2893
2168
 
2894
 
  DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
 
2169
  assert(log_file.type == SEQ_READ_APPEND);
2895
2170
 
2896
2171
  safe_mutex_assert_owner(&LOCK_log);
2897
2172
  do
2898
2173
  {
2899
 
    if (my_b_append(&log_file,(uchar*) buf,len))
 
2174
    if (my_b_append(&log_file,(unsigned char*) buf,len))
2900
2175
    {
2901
2176
      error= 1;
2902
2177
      goto err;
2903
2178
    }
2904
2179
    bytes_written += len;
2905
2180
  } while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
2906
 
  DBUG_PRINT("info",("max_size: %lu",max_size));
2907
2181
  if ((uint) my_b_append_tell(&log_file) > max_size)
2908
2182
    new_file_without_locking();
2909
2183
 
2910
2184
err:
2911
2185
  if (!error)
2912
2186
    signal_update();
2913
 
  DBUG_RETURN(error);
 
2187
  return(error);
2914
2188
}
2915
2189
 
2916
2190
 
2917
 
bool MYSQL_BIN_LOG::flush_and_sync()
 
2191
bool DRIZZLE_BIN_LOG::flush_and_sync()
2918
2192
{
2919
2193
  int err=0, fd=log_file.file;
2920
2194
  safe_mutex_assert_owner(&LOCK_log);
2928
2202
  return err;
2929
2203
}
2930
2204
 
2931
 
void MYSQL_BIN_LOG::start_union_events(THD *thd, query_id_t query_id_param)
 
2205
void DRIZZLE_BIN_LOG::start_union_events(THD *thd, query_id_t query_id_param)
2932
2206
{
2933
 
  DBUG_ASSERT(!thd->binlog_evt_union.do_union);
2934
 
  thd->binlog_evt_union.do_union= TRUE;
2935
 
  thd->binlog_evt_union.unioned_events= FALSE;
2936
 
  thd->binlog_evt_union.unioned_events_trans= FALSE;
 
2207
  assert(!thd->binlog_evt_union.do_union);
 
2208
  thd->binlog_evt_union.do_union= true;
 
2209
  thd->binlog_evt_union.unioned_events= false;
 
2210
  thd->binlog_evt_union.unioned_events_trans= false;
2937
2211
  thd->binlog_evt_union.first_query_id= query_id_param;
2938
2212
}
2939
2213
 
2940
 
void MYSQL_BIN_LOG::stop_union_events(THD *thd)
 
2214
void DRIZZLE_BIN_LOG::stop_union_events(THD *thd)
2941
2215
{
2942
 
  DBUG_ASSERT(thd->binlog_evt_union.do_union);
2943
 
  thd->binlog_evt_union.do_union= FALSE;
 
2216
  assert(thd->binlog_evt_union.do_union);
 
2217
  thd->binlog_evt_union.do_union= false;
2944
2218
}
2945
2219
 
2946
 
bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
 
2220
bool DRIZZLE_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
2947
2221
{
2948
2222
  return (thd->binlog_evt_union.do_union && 
2949
2223
          query_id_param >= thd->binlog_evt_union.first_query_id);
2957
2231
 
2958
2232
int THD::binlog_setup_trx_data()
2959
2233
{
2960
 
  DBUG_ENTER("THD::binlog_setup_trx_data");
2961
2234
  binlog_trx_data *trx_data=
2962
2235
    (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
2963
2236
 
2964
2237
  if (trx_data)
2965
 
    DBUG_RETURN(0);                             // Already set up
 
2238
    return(0);                             // Already set up
2966
2239
 
2967
2240
  trx_data= (binlog_trx_data*) my_malloc(sizeof(binlog_trx_data), MYF(MY_ZEROFILL));
2968
2241
  if (!trx_data ||
2969
2242
      open_cached_file(&trx_data->trans_log, mysql_tmpdir,
2970
2243
                       LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
2971
2244
  {
2972
 
    my_free((uchar*)trx_data, MYF(MY_ALLOW_ZERO_PTR));
2973
 
    DBUG_RETURN(1);                      // Didn't manage to set it up
 
2245
    free((unsigned char*)trx_data);
 
2246
    return(1);                      // Didn't manage to set it up
2974
2247
  }
2975
2248
  thd_set_ha_data(this, binlog_hton, trx_data);
2976
2249
 
2977
2250
  trx_data= new (thd_get_ha_data(this, binlog_hton)) binlog_trx_data;
2978
2251
 
2979
 
  DBUG_RETURN(0);
 
2252
  return(0);
2980
2253
}
2981
2254
 
2982
2255
/*
3011
2284
THD::binlog_start_trans_and_stmt()
3012
2285
{
3013
2286
  binlog_trx_data *trx_data= (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
3014
 
  DBUG_ENTER("binlog_start_trans_and_stmt");
3015
 
  DBUG_PRINT("enter", ("trx_data: 0x%lx  trx_data->before_stmt_pos: %lu",
3016
 
                       (long) trx_data,
3017
 
                       (trx_data ? (ulong) trx_data->before_stmt_pos :
3018
 
                        (ulong) 0)));
3019
2287
 
3020
2288
  if (trx_data == NULL ||
3021
2289
      trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
3022
2290
  {
3023
2291
    this->binlog_set_stmt_begin();
3024
2292
    if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
3025
 
      trans_register_ha(this, TRUE, binlog_hton);
3026
 
    trans_register_ha(this, FALSE, binlog_hton);
 
2293
      trans_register_ha(this, true, binlog_hton);
 
2294
    trans_register_ha(this, false, binlog_hton);
3027
2295
    /*
3028
2296
      Mark statement transaction as read/write. We never start
3029
2297
      a binary log transaction and keep it read-only,
3035
2303
    */
3036
2304
    ha_data[binlog_hton->slot].ha_info[0].set_trx_read_write();
3037
2305
  }
3038
 
  DBUG_VOID_RETURN;
 
2306
  return;
3039
2307
}
3040
2308
 
3041
2309
void THD::binlog_set_stmt_begin() {
3059
2327
  Write a table map to the binary log.
3060
2328
 */
3061
2329
 
3062
 
int THD::binlog_write_table_map(TABLE *table, bool is_trans)
 
2330
int THD::binlog_write_table_map(Table *table, bool is_trans)
3063
2331
{
3064
2332
  int error;
3065
 
  DBUG_ENTER("THD::binlog_write_table_map");
3066
 
  DBUG_PRINT("enter", ("table: 0x%lx  (%s: #%lu)",
3067
 
                       (long) table, table->s->table_name.str,
3068
 
                       table->s->table_map_id));
3069
2333
 
3070
2334
  /* Pre-conditions */
3071
 
  DBUG_ASSERT(current_stmt_binlog_row_based && mysql_bin_log.is_open());
3072
 
  DBUG_ASSERT(table->s->table_map_id != ULONG_MAX);
 
2335
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
 
2336
  assert(table->s->table_map_id != UINT32_MAX);
3073
2337
 
3074
2338
  Table_map_log_event::flag_set const
3075
2339
    flags= Table_map_log_event::TM_NO_FLAGS;
3081
2345
    binlog_start_trans_and_stmt();
3082
2346
 
3083
2347
  if ((error= mysql_bin_log.write(&the_event)))
3084
 
    DBUG_RETURN(error);
 
2348
    return(error);
3085
2349
 
3086
2350
  binlog_table_maps++;
3087
2351
  table->s->table_map_version= mysql_bin_log.table_map_version();
3088
 
  DBUG_RETURN(0);
 
2352
  return(0);
3089
2353
}
3090
2354
 
3091
2355
Rows_log_event*
3111
2375
  binlog_trx_data *const trx_data=
3112
2376
    (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
3113
2377
 
3114
 
  DBUG_ASSERT(trx_data);
 
2378
  assert(trx_data);
3115
2379
  trx_data->set_pending(ev);
3116
2380
}
3117
2381
 
3122
2386
  event.
3123
2387
*/
3124
2388
int
3125
 
MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
 
2389
DRIZZLE_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
3126
2390
                                                Rows_log_event* event)
3127
2391
{
3128
 
  DBUG_ENTER("MYSQL_BIN_LOG::flush_and_set_pending_rows_event(event)");
3129
 
  DBUG_ASSERT(mysql_bin_log.is_open());
3130
 
  DBUG_PRINT("enter", ("event: 0x%lx", (long) event));
 
2392
  assert(mysql_bin_log.is_open());
3131
2393
 
3132
2394
  int error= 0;
3133
2395
 
3134
2396
  binlog_trx_data *const trx_data=
3135
2397
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
3136
2398
 
3137
 
  DBUG_ASSERT(trx_data);
3138
 
 
3139
 
  DBUG_PRINT("info", ("trx_data->pending(): 0x%lx", (long) trx_data->pending()));
 
2399
  assert(trx_data);
3140
2400
 
3141
2401
  if (Rows_log_event* pending= trx_data->pending())
3142
2402
  {
3163
2423
    if (pending->write(file))
3164
2424
    {
3165
2425
      pthread_mutex_unlock(&LOCK_log);
3166
 
      DBUG_RETURN(1);
 
2426
      return(1);
3167
2427
    }
3168
2428
 
3169
2429
    /*
3201
2461
 
3202
2462
  thd->binlog_set_pending_rows_event(event);
3203
2463
 
3204
 
  DBUG_RETURN(error);
 
2464
  return(error);
3205
2465
}
3206
2466
 
3207
2467
/**
3208
2468
  Write an event to the binary log.
3209
2469
*/
3210
2470
 
3211
 
bool MYSQL_BIN_LOG::write(Log_event *event_info)
 
2471
bool DRIZZLE_BIN_LOG::write(Log_event *event_info)
3212
2472
{
3213
2473
  THD *thd= event_info->thd;
3214
2474
  bool error= 1;
3215
 
  DBUG_ENTER("MYSQL_BIN_LOG::write(Log_event *)");
3216
2475
 
3217
2476
  if (thd->binlog_evt_union.do_union)
3218
2477
  {
3220
2479
      In Stored function; Remember that function call caused an update.
3221
2480
      We will log the function call to the binary log on function exit
3222
2481
    */
3223
 
    thd->binlog_evt_union.unioned_events= TRUE;
 
2482
    thd->binlog_evt_union.unioned_events= true;
3224
2483
    thd->binlog_evt_union.unioned_events_trans |= event_info->cache_stmt;
3225
 
    DBUG_RETURN(0);
 
2484
    return(0);
3226
2485
  }
3227
2486
 
3228
2487
  /*
3257
2516
    if ((thd && !(thd->options & OPTION_BIN_LOG)) ||
3258
2517
        (!binlog_filter->db_ok(local_db)))
3259
2518
    {
3260
 
      VOID(pthread_mutex_unlock(&LOCK_log));
3261
 
      DBUG_RETURN(0);
 
2519
      pthread_mutex_unlock(&LOCK_log);
 
2520
      return(0);
3262
2521
    }
3263
2522
 
3264
2523
    /*
3281
2540
      my_off_t trans_log_pos= my_b_tell(trans_log);
3282
2541
      if (event_info->get_cache_stmt() || trans_log_pos != 0)
3283
2542
      {
3284
 
        DBUG_PRINT("info", ("Using trans_log: cache: %d, trans_log_pos: %lu",
3285
 
                            event_info->get_cache_stmt(),
3286
 
                            (ulong) trans_log_pos));
3287
2543
        if (trans_log_pos == 0)
3288
2544
          thd->binlog_start_trans_and_stmt();
3289
2545
        file= trans_log;
3295
2551
        LOCK_log.
3296
2552
      */
3297
2553
    }
3298
 
    DBUG_PRINT("info",("event type: %d",event_info->get_type_code()));
3299
2554
 
3300
2555
    /*
3301
2556
      No check for auto events flag here - this write method should
3317
2572
      {
3318
2573
        if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
3319
2574
        {
3320
 
          Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
 
2575
          Intvar_log_event e(thd,(unsigned char) LAST_INSERT_ID_EVENT,
3321
2576
                             thd->first_successful_insert_id_in_prev_stmt_for_binlog);
3322
2577
          if (e.write(file))
3323
2578
            goto err;
3324
2579
        }
3325
2580
        if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
3326
2581
        {
3327
 
          DBUG_PRINT("info",("number of auto_inc intervals: %u",
3328
 
                             thd->auto_inc_intervals_in_cur_stmt_for_binlog.
3329
 
                             nb_elements()));
3330
2582
          /*
3331
2583
            If the auto_increment was second in a table's index (possible with
3332
2584
            MyISAM or BDB) (table->next_number_keypart != 0), such event is
3333
2585
            in fact not necessary. We could avoid logging it.
3334
2586
          */
3335
 
          Intvar_log_event e(thd, (uchar) INSERT_ID_EVENT,
 
2587
          Intvar_log_event e(thd, (unsigned char) INSERT_ID_EVENT,
3336
2588
                             thd->auto_inc_intervals_in_cur_stmt_for_binlog.
3337
2589
                             minimum());
3338
2590
          if (e.write(file))
3346
2598
        }
3347
2599
        if (thd->user_var_events.elements)
3348
2600
        {
3349
 
          for (uint i= 0; i < thd->user_var_events.elements; i++)
 
2601
          for (uint32_t i= 0; i < thd->user_var_events.elements; i++)
3350
2602
          {
3351
2603
            BINLOG_USER_VAR_EVENT *user_var_event;
3352
 
            get_dynamic(&thd->user_var_events,(uchar*) &user_var_event, i);
 
2604
            get_dynamic(&thd->user_var_events,(unsigned char*) &user_var_event, i);
3353
2605
            User_var_log_event e(thd, user_var_event->user_var_event->name.str,
3354
2606
                                 user_var_event->user_var_event->name.length,
3355
2607
                                 user_var_event->value,
3394
2646
    ++m_table_map_version;
3395
2647
 
3396
2648
  pthread_mutex_unlock(&LOCK_log);
3397
 
  DBUG_RETURN(error);
 
2649
  return(error);
3398
2650
}
3399
2651
 
3400
2652
 
3404
2656
  return logger.error_log_print(level, format, args);
3405
2657
}
3406
2658
 
3407
 
 
3408
 
bool slow_log_print(THD *thd, const char *query, uint query_length,
3409
 
                    ulonglong current_utime)
3410
 
{
3411
 
  return logger.slow_log_print(thd, query, query_length, current_utime);
3412
 
}
3413
 
 
3414
 
 
3415
 
bool LOGGER::log_command(THD *thd, enum enum_server_command command)
3416
 
{
3417
 
  /*
3418
 
    Log command if we have at least one log event handler enabled and want
3419
 
    to log this king of commands
3420
 
  */
3421
 
  if (*general_log_handler_list && (what_to_log & (1L << (uint) command)))
3422
 
  {
3423
 
    if (thd->options & OPTION_LOG_OFF)
3424
 
    {
3425
 
      /* No logging */
3426
 
      return FALSE;
3427
 
    }
3428
 
 
3429
 
    return TRUE;
3430
 
  }
3431
 
 
3432
 
  return FALSE;
3433
 
}
3434
 
 
3435
 
 
3436
 
bool general_log_print(THD *thd, enum enum_server_command command,
3437
 
                       const char *format, ...)
3438
 
{
3439
 
  va_list args;
3440
 
  uint error= 0;
3441
 
 
3442
 
  /* Print the message to the buffer if we want to log this king of commands */
3443
 
  if (! logger.log_command(thd, command))
3444
 
    return FALSE;
3445
 
 
3446
 
  va_start(args, format);
3447
 
  error= logger.general_log_print(thd, command, format, args);
3448
 
  va_end(args);
3449
 
 
3450
 
  return error;
3451
 
}
3452
 
 
3453
 
bool general_log_write(THD *thd, enum enum_server_command command,
3454
 
                       const char *query, uint query_length)
3455
 
{
3456
 
  /* Write the message to the log if we want to log this king of commands */
3457
 
  if (logger.log_command(thd, command))
3458
 
    return logger.general_log_write(thd, command, query, query_length);
3459
 
 
3460
 
  return FALSE;
3461
 
}
3462
 
 
3463
 
void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
 
2659
void DRIZZLE_BIN_LOG::rotate_and_purge(uint32_t flags)
3464
2660
{
3465
2661
  if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
3466
2662
    pthread_mutex_lock(&LOCK_log);
3468
2664
      (my_b_tell(&log_file) >= (my_off_t) max_size))
3469
2665
  {
3470
2666
    new_file_without_locking();
3471
 
#ifdef HAVE_REPLICATION
3472
2667
    if (expire_logs_days)
3473
2668
    {
3474
2669
      time_t purge_time= my_time(0) - expire_logs_days*24*60*60;
3475
2670
      if (purge_time >= 0)
3476
2671
        purge_logs_before_date(purge_time);
3477
2672
    }
3478
 
#endif
3479
2673
  }
3480
2674
  if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
3481
2675
    pthread_mutex_unlock(&LOCK_log);
3482
2676
}
3483
2677
 
3484
 
uint MYSQL_BIN_LOG::next_file_id()
 
2678
uint32_t DRIZZLE_BIN_LOG::next_file_id()
3485
2679
{
3486
 
  uint res;
 
2680
  uint32_t res;
3487
2681
  pthread_mutex_lock(&LOCK_log);
3488
2682
  res = file_id++;
3489
2683
  pthread_mutex_unlock(&LOCK_log);
3505
2699
    be reset as a READ_CACHE to be able to read the contents from it.
3506
2700
 */
3507
2701
 
3508
 
int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
 
2702
int DRIZZLE_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
3509
2703
{
3510
2704
  Mutex_sentry sentry(lock_log ? &LOCK_log : NULL);
3511
2705
 
3512
2706
  if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0))
3513
2707
    return ER_ERROR_ON_WRITE;
3514
 
  uint length= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
 
2708
  uint32_t length= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
3515
2709
  long val;
3516
 
  uchar header[LOG_EVENT_HEADER_LEN];
 
2710
  unsigned char header[LOG_EVENT_HEADER_LEN];
3517
2711
 
3518
2712
  /*
3519
2713
    The events in the buffer have incorrect end_log_pos data
3541
2735
    */
3542
2736
    if (unlikely(carry > 0))
3543
2737
    {
3544
 
      DBUG_ASSERT(carry < LOG_EVENT_HEADER_LEN);
 
2738
      assert(carry < LOG_EVENT_HEADER_LEN);
3545
2739
 
3546
2740
      /* assemble both halves */
3547
 
      memcpy(&header[carry], (char *)cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
 
2741
      memcpy(&header[carry], cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
3548
2742
 
3549
2743
      /* fix end_log_pos */
3550
2744
      val= uint4korr(&header[LOG_POS_OFFSET]) + group;
3558
2752
        copy fixed second half of header to cache so the correct
3559
2753
        version will be written later.
3560
2754
      */
3561
 
      memcpy((char *)cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
 
2755
      memcpy(cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
3562
2756
 
3563
2757
      /* next event header at ... */
3564
2758
      hdr_offs = uint4korr(&header[EVENT_LEN_OFFSET]) - carry;
3587
2781
        if (hdr_offs + LOG_EVENT_HEADER_LEN > length)
3588
2782
        {
3589
2783
          carry= length - hdr_offs;
3590
 
          memcpy(header, (char *)cache->read_pos + hdr_offs, carry);
 
2784
          memcpy(header, cache->read_pos + hdr_offs, carry);
3591
2785
          length= hdr_offs;
3592
2786
        }
3593
2787
        else
3594
2788
        {
3595
2789
          /* we've got a full event-header, and it came in one piece */
3596
2790
 
3597
 
          uchar *log_pos= (uchar *)cache->read_pos + hdr_offs + LOG_POS_OFFSET;
 
2791
          unsigned char *log_pos= (unsigned char *)cache->read_pos + hdr_offs + LOG_POS_OFFSET;
3598
2792
 
3599
2793
          /* fix end_log_pos */
3600
2794
          val= uint4korr(log_pos) + group;
3601
2795
          int4store(log_pos, val);
3602
2796
 
3603
2797
          /* next event header at ... */
3604
 
          log_pos= (uchar *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET;
 
2798
          log_pos= (unsigned char *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET;
3605
2799
          hdr_offs += uint4korr(log_pos);
3606
2800
 
3607
2801
        }
3624
2818
    cache->read_pos=cache->read_end;            // Mark buffer used up
3625
2819
  } while ((length= my_b_fill(cache)));
3626
2820
 
3627
 
  DBUG_ASSERT(carry == 0);
 
2821
  assert(carry == 0);
3628
2822
 
3629
2823
  if (sync_log)
3630
2824
    flush_and_sync();
3653
2847
    'cache' needs to be reinitialized after this functions returns.
3654
2848
*/
3655
2849
 
3656
 
bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
 
2850
bool DRIZZLE_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
3657
2851
{
3658
 
  DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)");
3659
 
  VOID(pthread_mutex_lock(&LOCK_log));
 
2852
  pthread_mutex_lock(&LOCK_log);
3660
2853
 
3661
2854
  /* NULL would represent nothing to replicate after ROLLBACK */
3662
 
  DBUG_ASSERT(commit_event != NULL);
 
2855
  assert(commit_event != NULL);
3663
2856
 
3664
 
  DBUG_ASSERT(is_open());
 
2857
  assert(is_open());
3665
2858
  if (likely(is_open()))                       // Should always be true
3666
2859
  {
3667
2860
    /*
3675
2868
        transaction is either a BEGIN..COMMIT block or a single
3676
2869
        statement in autocommit mode.
3677
2870
      */
3678
 
      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE);
 
2871
      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), true, false);
3679
2872
      /*
3680
2873
        Imagine this is rollback due to net timeout, after all
3681
2874
        statements of the transaction succeeded. Then we want a
3699
2892
      if (qinfo.write(&log_file))
3700
2893
        goto err;
3701
2894
 
3702
 
      DBUG_EXECUTE_IF("crash_before_writing_xid",
3703
 
                      {
3704
 
                        if ((write_error= write_cache(cache, false, true)))
3705
 
                          DBUG_PRINT("info", ("error writing binlog cache: %d",
3706
 
                                               write_error));
3707
 
                        DBUG_PRINT("info", ("crashing before writing xid"));
3708
 
                        abort();
3709
 
                      });
3710
 
 
3711
2895
      if ((write_error= write_cache(cache, false, false)))
3712
2896
        goto err;
3713
2897
 
3715
2899
        goto err;
3716
2900
      if (flush_and_sync())
3717
2901
        goto err;
3718
 
      DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
3719
2902
      if (cache->error)                         // Error on read
3720
2903
      {
3721
2904
        sql_print_error(ER(ER_ERROR_ON_READ), cache->file_name, errno);
3742
2925
    else
3743
2926
      rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
3744
2927
  }
3745
 
  VOID(pthread_mutex_unlock(&LOCK_log));
 
2928
  pthread_mutex_unlock(&LOCK_log);
3746
2929
 
3747
 
  DBUG_RETURN(0);
 
2930
  return(0);
3748
2931
 
3749
2932
err:
3750
2933
  if (!write_error)
3752
2935
    write_error= 1;
3753
2936
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
3754
2937
  }
3755
 
  VOID(pthread_mutex_unlock(&LOCK_log));
3756
 
  DBUG_RETURN(1);
 
2938
  pthread_mutex_unlock(&LOCK_log);
 
2939
  return(1);
3757
2940
}
3758
2941
 
3759
2942
 
3766
2949
    It will be released at the end of the function.
3767
2950
*/
3768
2951
 
3769
 
void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
 
2952
void DRIZZLE_BIN_LOG::wait_for_update_relay_log(THD* thd)
3770
2953
{
3771
2954
  const char *old_msg;
3772
 
  DBUG_ENTER("wait_for_update_relay_log");
3773
2955
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
3774
2956
                           "Slave has read all relay log; " 
3775
2957
                           "waiting for the slave I/O "
3776
2958
                           "thread to update it" );
3777
2959
  pthread_cond_wait(&update_cond, &LOCK_log);
3778
2960
  thd->exit_cond(old_msg);
3779
 
  DBUG_VOID_RETURN;
 
2961
  return;
3780
2962
}
3781
2963
 
3782
2964
 
3796
2978
    LOCK_log is released by the caller.
3797
2979
*/
3798
2980
 
3799
 
int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd,
 
2981
int DRIZZLE_BIN_LOG::wait_for_update_bin_log(THD* thd,
3800
2982
                                           const struct timespec *timeout)
3801
2983
{
3802
2984
  int ret= 0;
3803
 
  const char* old_msg = thd->proc_info;
3804
 
  DBUG_ENTER("wait_for_update_bin_log");
 
2985
  const char* old_msg = thd->get_proc_info();
3805
2986
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
3806
2987
                           "Master has sent all binlog to slave; "
3807
2988
                           "waiting for binlog to be updated");
3810
2991
  else
3811
2992
    ret= pthread_cond_timedwait(&update_cond, &LOCK_log,
3812
2993
                                const_cast<struct timespec *>(timeout));
3813
 
  DBUG_RETURN(ret);
 
2994
  return(ret);
3814
2995
}
3815
2996
 
3816
2997
 
3828
3009
    The internal structures are not freed until cleanup() is called
3829
3010
*/
3830
3011
 
3831
 
void MYSQL_BIN_LOG::close(uint exiting)
 
3012
void DRIZZLE_BIN_LOG::close(uint32_t exiting)
3832
3013
{                                       // One can't set log_type here!
3833
 
  DBUG_ENTER("MYSQL_BIN_LOG::close");
3834
 
  DBUG_PRINT("enter",("exiting: %d", (int) exiting));
3835
3014
  if (log_state == LOG_OPENED)
3836
3015
  {
3837
 
#ifdef HAVE_REPLICATION
3838
3016
    if (log_type == LOG_BIN && !no_auto_events &&
3839
3017
        (exiting & LOG_CLOSE_STOP_EVENT))
3840
3018
    {
3843
3021
      bytes_written+= s.data_written;
3844
3022
      signal_update();
3845
3023
    }
3846
 
#endif /* HAVE_REPLICATION */
3847
3024
 
3848
3025
    /* don't pwrite in a file opened with O_APPEND - it doesn't work */
3849
3026
    if (log_file.type == WRITE_CACHE && log_type == LOG_BIN)
3850
3027
    {
3851
3028
      my_off_t offset= BIN_LOG_HEADER_SIZE + FLAGS_OFFSET;
3852
 
      my_off_t org_position= my_tell(log_file.file, MYF(0));
3853
 
      uchar flags= 0;            // clearing LOG_EVENT_BINLOG_IN_USE_F
 
3029
      unsigned char flags= 0;            // clearing LOG_EVENT_BINLOG_IN_USE_F
3854
3030
      pwrite(log_file.file, &flags, 1, offset);
3855
3031
    }
3856
3032
 
3857
3033
    /* this will cleanup IO_CACHE, sync and close the file */
3858
 
    MYSQL_LOG::close(exiting);
 
3034
    DRIZZLE_LOG::close(exiting);
3859
3035
  }
3860
3036
 
3861
3037
  /*
3873
3049
    }
3874
3050
  }
3875
3051
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
3876
 
  safeFree(name);
3877
 
  DBUG_VOID_RETURN;
 
3052
  if (name)
 
3053
  {
 
3054
    free(name);
 
3055
    name= NULL;
 
3056
  }
 
3057
  return;
3878
3058
}
3879
3059
 
3880
3060
 
3881
 
void MYSQL_BIN_LOG::set_max_size(ulong max_size_arg)
 
3061
void DRIZZLE_BIN_LOG::set_max_size(ulong max_size_arg)
3882
3062
{
3883
3063
  /*
3884
3064
    We need to take locks, otherwise this may happen:
3887
3067
    uses the old_max_size argument, so max_size_arg has been overwritten and
3888
3068
    it's like if the SET command was never run.
3889
3069
  */
3890
 
  DBUG_ENTER("MYSQL_BIN_LOG::set_max_size");
3891
3070
  pthread_mutex_lock(&LOCK_log);
3892
3071
  if (is_open())
3893
3072
    max_size= max_size_arg;
3894
3073
  pthread_mutex_unlock(&LOCK_log);
3895
 
  DBUG_VOID_RETURN;
 
3074
  return;
3896
3075
}
3897
3076
 
3898
3077
 
3918
3097
{
3919
3098
  register int flag;
3920
3099
  const char *start;
3921
 
  DBUG_ENTER("test_if_number");
3922
3100
 
3923
3101
  flag= 0; 
3924
3102
  start= str;
3939
3117
         str++, flag=1) ;
3940
3118
  }
3941
3119
  if (*str != 0 || flag == 0)
3942
 
    DBUG_RETURN(0);
 
3120
    return(0);
3943
3121
  if (res)
3944
3122
    *res=atol(start);
3945
 
  DBUG_RETURN(1);                       /* Number ok */
 
3123
  return(1);                    /* Number ok */
3946
3124
} /* test_if_number */
3947
3125
 
3948
3126
 
3949
3127
void sql_perror(const char *message)
3950
3128
{
3951
 
#ifdef HAVE_STRERROR
3952
3129
  sql_print_error("%s: %s",message, strerror(errno));
3953
 
#else
3954
 
  perror(message);
3955
 
#endif
3956
3130
}
3957
3131
 
3958
3132
 
3963
3137
  {
3964
3138
    char err_renamed[FN_REFLEN], *end;
3965
3139
    end= strmake(err_renamed,log_error_file,FN_REFLEN-4);
3966
 
    strmov(end, "-old");
3967
 
    VOID(pthread_mutex_lock(&LOCK_error_log));
 
3140
    my_stpcpy(end, "-old");
 
3141
    pthread_mutex_lock(&LOCK_error_log);
3968
3142
    char err_temp[FN_REFLEN+4];
3969
3143
    /*
3970
3144
     On Windows is necessary a temporary file for to rename
3971
3145
     the current error file.
3972
3146
    */
3973
 
    strxmov(err_temp, err_renamed,"-tmp",NullS);
 
3147
    strxmov(err_temp, err_renamed,"-tmp",NULL);
3974
3148
    (void) my_delete(err_temp, MYF(0)); 
3975
3149
    if (freopen(err_temp,"a+",stdout))
3976
3150
    {
3977
3151
      int fd;
3978
3152
      size_t bytes;
3979
 
      uchar buf[IO_SIZE];
 
3153
      unsigned char buf[IO_SIZE];
3980
3154
 
3981
3155
      freopen(err_temp,"a+",stderr);
3982
3156
      (void) my_delete(err_renamed, MYF(0));
3995
3169
    }
3996
3170
    else
3997
3171
     result= 1;
3998
 
    VOID(pthread_mutex_unlock(&LOCK_error_log));
 
3172
    pthread_mutex_unlock(&LOCK_error_log);
3999
3173
  }
4000
3174
   return result;
4001
3175
}
4002
3176
 
4003
 
void MYSQL_BIN_LOG::signal_update()
 
3177
void DRIZZLE_BIN_LOG::signal_update()
4004
3178
{
4005
 
  DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
4006
3179
  pthread_cond_broadcast(&update_cond);
4007
 
  DBUG_VOID_RETURN;
 
3180
  return;
4008
3181
}
4009
3182
 
4010
3183
/**
4023
3196
    signature to be compatible with other logging routines, which could
4024
3197
    return an error (e.g. logging to the log tables)
4025
3198
*/
4026
 
static void print_buffer_to_file(enum loglevel level, int error_code,
4027
 
                                 const char *buffer, size_t buffer_length)
 
3199
static void print_buffer_to_file(enum loglevel level,
 
3200
                                 int error_code __attribute__((unused)),
 
3201
                                 const char *buffer,
 
3202
                                 size_t buffer_length __attribute__((unused)))
4028
3203
{
4029
3204
  time_t skr;
4030
3205
  struct tm tm_tmp;
4031
3206
  struct tm *start;
4032
 
  DBUG_ENTER("print_buffer_to_file");
4033
 
  DBUG_PRINT("enter",("buffer: %s", buffer));
4034
3207
 
4035
 
  VOID(pthread_mutex_lock(&LOCK_error_log));
 
3208
  pthread_mutex_lock(&LOCK_error_log);
4036
3209
 
4037
3210
  skr= my_time(0);
4038
3211
  localtime_r(&skr, &tm_tmp);
4051
3224
 
4052
3225
  fflush(stderr);
4053
3226
 
4054
 
  VOID(pthread_mutex_unlock(&LOCK_error_log));
4055
 
  DBUG_VOID_RETURN;
 
3227
  pthread_mutex_unlock(&LOCK_error_log);
 
3228
  return;
4056
3229
}
4057
3230
 
4058
3231
 
4061
3234
  char   buff[1024];
4062
3235
  size_t length;
4063
3236
  int error_code= errno;
4064
 
  DBUG_ENTER("vprint_msg_to_log");
4065
3237
 
4066
 
  length= my_vsnprintf(buff, sizeof(buff), format, args);
 
3238
  length= vsnprintf(buff, sizeof(buff), format, args);
4067
3239
 
4068
3240
  print_buffer_to_file(level, error_code, buff, length);
4069
3241
 
4070
 
  DBUG_RETURN(0);
 
3242
  return(0);
4071
3243
}
4072
3244
 
4073
3245
 
4074
3246
void sql_print_error(const char *format, ...) 
4075
3247
{
4076
3248
  va_list args;
4077
 
  DBUG_ENTER("sql_print_error");
4078
3249
 
4079
3250
  va_start(args, format);
4080
3251
  error_log_print(ERROR_LEVEL, format, args);
4081
3252
  va_end(args);
4082
3253
 
4083
 
  DBUG_VOID_RETURN;
 
3254
  return;
4084
3255
}
4085
3256
 
4086
3257
 
4087
3258
void sql_print_warning(const char *format, ...) 
4088
3259
{
4089
3260
  va_list args;
4090
 
  DBUG_ENTER("sql_print_warning");
4091
3261
 
4092
3262
  va_start(args, format);
4093
3263
  error_log_print(WARNING_LEVEL, format, args);
4094
3264
  va_end(args);
4095
3265
 
4096
 
  DBUG_VOID_RETURN;
 
3266
  return;
4097
3267
}
4098
3268
 
4099
3269
 
4100
3270
void sql_print_information(const char *format, ...) 
4101
3271
{
4102
3272
  va_list args;
4103
 
  DBUG_ENTER("sql_print_information");
4104
3273
 
4105
3274
  va_start(args, format);
4106
3275
  error_log_print(INFORMATION_LEVEL, format, args);
4107
3276
  va_end(args);
4108
3277
 
4109
 
  DBUG_VOID_RETURN;
 
3278
  return;
4110
3279
}
4111
3280
 
4112
3281
 
4161
3330
 
4162
3331
int TC_LOG_MMAP::open(const char *opt_name)
4163
3332
{
4164
 
  uint i;
4165
 
  bool crashed=FALSE;
 
3333
  uint32_t i;
 
3334
  bool crashed= false;
4166
3335
  PAGE *pg;
4167
3336
 
4168
 
  DBUG_ASSERT(total_ha_2pc > 1);
4169
 
  DBUG_ASSERT(opt_name && opt_name[0]);
 
3337
  assert(total_ha_2pc > 1);
 
3338
  assert(opt_name && opt_name[0]);
4170
3339
 
4171
 
  tc_log_page_size= my_getpagesize();
4172
 
  DBUG_ASSERT(TC_LOG_PAGE_SIZE % tc_log_page_size == 0);
 
3340
  tc_log_page_size= getpagesize();
 
3341
  assert(TC_LOG_PAGE_SIZE % tc_log_page_size == 0);
4173
3342
 
4174
3343
  fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME);
4175
3344
  if ((fd= my_open(logname, O_RDWR, MYF(0))) < 0)
4188
3357
  else
4189
3358
  {
4190
3359
    inited= 1;
4191
 
    crashed= TRUE;
4192
 
    sql_print_information("Recovering after a crash using %s", opt_name);
 
3360
    crashed= true;
 
3361
    sql_print_information(_("Recovering after a crash using %s"), opt_name);
4193
3362
    if (tc_heuristic_recover)
4194
3363
    {
4195
 
      sql_print_error("Cannot perform automatic crash recovery when "
4196
 
                      "--tc-heuristic-recover is used");
 
3364
      sql_print_error(_("Cannot perform automatic crash recovery when "
 
3365
                      "--tc-heuristic-recover is used"));
4197
3366
      goto err;
4198
3367
    }
4199
3368
    file_length= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE));
4201
3370
      goto err;
4202
3371
  }
4203
3372
 
4204
 
  data= (uchar *)my_mmap(0, (size_t)file_length, PROT_READ|PROT_WRITE,
 
3373
  data= (unsigned char *)my_mmap(0, (size_t)file_length, PROT_READ|PROT_WRITE,
4205
3374
                        MAP_NOSYNC|MAP_SHARED, fd, 0);
4206
3375
  if (data == MAP_FAILED)
4207
3376
  {
4211
3380
  inited=2;
4212
3381
 
4213
3382
  npages=(uint)file_length/tc_log_page_size;
4214
 
  DBUG_ASSERT(npages >= 3);             // to guarantee non-empty pool
 
3383
  assert(npages >= 3);             // to guarantee non-empty pool
4215
3384
  if (!(pages=(PAGE *)my_malloc(npages*sizeof(PAGE), MYF(MY_WME|MY_ZEROFILL))))
4216
3385
    goto err;
4217
3386
  inited=3;
4237
3406
      goto err;
4238
3407
 
4239
3408
  memcpy(data, tc_log_magic, sizeof(tc_log_magic));
4240
 
  data[sizeof(tc_log_magic)]= (uchar)total_ha_2pc;
 
3409
  data[sizeof(tc_log_magic)]= (unsigned char)total_ha_2pc;
4241
3410
  msync(data, tc_log_page_size, MS_SYNC);
4242
3411
  my_sync(fd, MYF(0));
4243
3412
  inited=5;
4345
3514
    threads waiting for a page, but then all these threads will be waiting
4346
3515
    for a fsync() anyway
4347
3516
 
4348
 
   If tc_log == MYSQL_LOG then tc_log writes transaction to binlog and
 
3517
   If tc_log == DRIZZLE_LOG then tc_log writes transaction to binlog and
4349
3518
   records XID in a special Xid_log_event.
4350
3519
   If tc_log = TC_LOG_MMAP then xid is written in a special memory-mapped
4351
3520
   log.
4359
3528
    to the position in memory where xid was logged to.
4360
3529
*/
4361
3530
 
4362
 
int TC_LOG_MMAP::log_xid(THD *thd, my_xid xid)
 
3531
int TC_LOG_MMAP::log_xid(THD *thd __attribute__((unused)), my_xid xid)
4363
3532
{
4364
3533
  int err;
4365
3534
  PAGE *p;
4388
3557
  while (*p->ptr)
4389
3558
  {
4390
3559
    p->ptr++;
4391
 
    DBUG_ASSERT(p->ptr < p->end);               // because p->free > 0
 
3560
    assert(p->ptr < p->end);               // because p->free > 0
4392
3561
  }
4393
3562
 
4394
3563
  /* found! store xid there and mark the page dirty */
4395
 
  cookie= (ulong)((uchar *)p->ptr - data);      // can never be zero
 
3564
  cookie= (ulong)((unsigned char *)p->ptr - data);      // can never be zero
4396
3565
  *p->ptr++= xid;
4397
3566
  p->free--;
4398
3567
  p->state= DIRTY;
4421
3590
      goto done;                             // we're done
4422
3591
    }
4423
3592
  }                                          // page was not synced! do it now
4424
 
  DBUG_ASSERT(active == p && syncing == 0);
 
3593
  assert(active == p && syncing == 0);
4425
3594
  pthread_mutex_lock(&LOCK_active);
4426
3595
  syncing=p;                                 // place is vacant - take it
4427
3596
  active=0;                                  // page is not active anymore
4438
3607
{
4439
3608
  int err;
4440
3609
 
4441
 
  DBUG_ASSERT(syncing != active);
 
3610
  assert(syncing != active);
4442
3611
 
4443
3612
  /*
4444
3613
    sit down and relax - this can take a while...
4471
3640
  cookie points directly to the memory where xid was logged.
4472
3641
*/
4473
3642
 
4474
 
void TC_LOG_MMAP::unlog(ulong cookie, my_xid xid)
 
3643
void TC_LOG_MMAP::unlog(ulong cookie, my_xid xid __attribute__((unused)))
4475
3644
{
4476
3645
  PAGE *p=pages+(cookie/tc_log_page_size);
4477
3646
  my_xid *x=(my_xid *)(data+cookie);
4478
3647
 
4479
 
  DBUG_ASSERT(*x == xid);
4480
 
  DBUG_ASSERT(x >= p->start && x < p->end);
 
3648
  assert(*x == xid);
 
3649
  assert(x >= p->start && x < p->end);
4481
3650
  *x=0;
4482
3651
 
4483
3652
  pthread_mutex_lock(&p->lock);
4484
3653
  p->free++;
4485
 
  DBUG_ASSERT(p->free <= p->size);
 
3654
  assert(p->free <= p->size);
4486
3655
  set_if_smaller(p->ptr, x);
4487
3656
  if (p->free == p->size)               // the page is completely empty
4488
3657
    statistic_decrement(tc_log_cur_pages_used, &LOCK_status);
4493
3662
 
4494
3663
void TC_LOG_MMAP::close()
4495
3664
{
4496
 
  uint i;
 
3665
  uint32_t i;
4497
3666
  switch (inited) {
4498
3667
  case 6:
4499
3668
    pthread_mutex_destroy(&LOCK_sync);
4511
3680
      pthread_cond_destroy(&pages[i].cond);
4512
3681
    }
4513
3682
  case 3:
4514
 
    my_free((uchar*)pages, MYF(0));
 
3683
    free((unsigned char*)pages);
4515
3684
  case 2:
4516
3685
    my_munmap((char*)data, (size_t)file_length);
4517
3686
  case 1:
4529
3698
 
4530
3699
  if (memcmp(data, tc_log_magic, sizeof(tc_log_magic)))
4531
3700
  {
4532
 
    sql_print_error("Bad magic header in tc log");
 
3701
    sql_print_error(_("Bad magic header in tc log"));
4533
3702
    goto err1;
4534
3703
  }
4535
3704
 
4539
3708
  */
4540
3709
  if (data[sizeof(tc_log_magic)] != total_ha_2pc)
4541
3710
  {
4542
 
    sql_print_error("Recovery failed! You must enable "
 
3711
    sql_print_error(_("Recovery failed! You must enable "
4543
3712
                    "exactly %d storage engines that support "
4544
 
                    "two-phase commit protocol",
 
3713
                    "two-phase commit protocol"),
4545
3714
                    data[sizeof(tc_log_magic)]);
4546
3715
    goto err1;
4547
3716
  }
4553
3722
  for ( ; p < end_p ; p++)
4554
3723
  {
4555
3724
    for (my_xid *x=p->start; x < p->end; x++)
4556
 
      if (*x && my_hash_insert(&xids, (uchar *)x))
 
3725
      if (*x && my_hash_insert(&xids, (unsigned char *)x))
4557
3726
        goto err2; // OOM
4558
3727
  }
4559
3728
 
4561
3730
    goto err2;
4562
3731
 
4563
3732
  hash_free(&xids);
4564
 
  bzero(data, (size_t)file_length);
 
3733
  memset(data, 0, (size_t)file_length);
4565
3734
  return 0;
4566
3735
 
4567
3736
err2:
4568
3737
  hash_free(&xids);
4569
3738
err1:
4570
 
  sql_print_error("Crash recovery failed. Either correct the problem "
 
3739
  sql_print_error(_("Crash recovery failed. Either correct the problem "
4571
3740
                  "(if it's, for example, out of memory error) and restart, "
4572
 
                  "or delete tc log and start mysqld with "
4573
 
                  "--tc-heuristic-recover={commit|rollback}");
 
3741
                  "or delete tc log and start drizzled with "
 
3742
                  "--tc-heuristic-recover={commit|rollback}"));
4574
3743
  return 1;
4575
3744
}
4576
3745
#endif
4597
3766
  if (!tc_heuristic_recover)
4598
3767
    return 0;
4599
3768
 
4600
 
  sql_print_information("Heuristic crash recovery mode");
 
3769
  sql_print_information(_("Heuristic crash recovery mode"));
4601
3770
  if (ha_recover(0))
4602
 
    sql_print_error("Heuristic crash recovery failed");
4603
 
  sql_print_information("Please restart mysqld without --tc-heuristic-recover");
 
3771
    sql_print_error(_("Heuristic crash recovery failed"));
 
3772
  sql_print_information(_("Please restart mysqld without --tc-heuristic-recover"));
4604
3773
  return 1;
4605
3774
}
4606
3775
 
4607
3776
/****** transaction coordinator log for 2pc - binlog() based solution ******/
4608
 
#define TC_LOG_BINLOG MYSQL_BIN_LOG
 
3777
#define TC_LOG_BINLOG DRIZZLE_BIN_LOG
4609
3778
 
4610
3779
/**
4611
3780
  @todo
4620
3789
  LOG_INFO log_info;
4621
3790
  int      error= 1;
4622
3791
 
4623
 
  DBUG_ASSERT(total_ha_2pc > 1);
4624
 
  DBUG_ASSERT(opt_name && opt_name[0]);
 
3792
  assert(total_ha_2pc > 1);
 
3793
  assert(opt_name && opt_name[0]);
4625
3794
 
4626
3795
  pthread_mutex_init(&LOCK_prep_xids, MY_MUTEX_INIT_FAST);
4627
3796
  pthread_cond_init (&COND_prep_xids, 0);
4641
3810
    return 1;
4642
3811
  }
4643
3812
 
4644
 
  if ((error= find_log_pos(&log_info, NullS, 1)))
 
3813
  if ((error= find_log_pos(&log_info, NULL, 1)))
4645
3814
  {
4646
3815
    if (error != LOG_INFO_EOF)
4647
 
      sql_print_error("find_log_pos() failed (error: %d)", error);
 
3816
      sql_print_error(_("find_log_pos() failed (error: %d)"), error);
4648
3817
    else
4649
3818
      error= 0;
4650
3819
    goto err;
4668
3837
 
4669
3838
    if (error !=  LOG_INFO_EOF)
4670
3839
    {
4671
 
      sql_print_error("find_log_pos() failed (error: %d)", error);
 
3840
      sql_print_error(_("find_log_pos() failed (error: %d)"), error);
4672
3841
      goto err;
4673
3842
    }
4674
3843
 
4682
3851
        ev->get_type_code() == FORMAT_DESCRIPTION_EVENT &&
4683
3852
        ev->flags & LOG_EVENT_BINLOG_IN_USE_F)
4684
3853
    {
4685
 
      sql_print_information("Recovering after a crash using %s", opt_name);
 
3854
      sql_print_information(_("Recovering after a crash using %s"), opt_name);
4686
3855
      error= recover(&log, (Format_description_log_event *)ev);
4687
3856
    }
4688
3857
    else
4703
3872
/** This is called on shutdown, after ha_panic. */
4704
3873
void TC_LOG_BINLOG::close()
4705
3874
{
4706
 
  DBUG_ASSERT(prepared_xids==0);
 
3875
  assert(prepared_xids==0);
4707
3876
  pthread_mutex_destroy(&LOCK_prep_xids);
4708
3877
  pthread_cond_destroy (&COND_prep_xids);
4709
3878
}
4719
3888
*/
4720
3889
int TC_LOG_BINLOG::log_xid(THD *thd, my_xid xid)
4721
3890
{
4722
 
  DBUG_ENTER("TC_LOG_BINLOG::log");
4723
3891
  Xid_log_event xle(thd, xid);
4724
3892
  binlog_trx_data *trx_data=
4725
3893
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
4727
3895
    We always commit the entire transaction when writing an XID. Also
4728
3896
    note that the return value is inverted.
4729
3897
   */
4730
 
  DBUG_RETURN(!binlog_end_trans(thd, trx_data, &xle, TRUE));
 
3898
  return(!binlog_end_trans(thd, trx_data, &xle, true));
4731
3899
}
4732
3900
 
4733
 
void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
 
3901
void TC_LOG_BINLOG::unlog(ulong cookie __attribute__((unused)),
 
3902
                          my_xid xid __attribute__((unused)))
4734
3903
{
4735
3904
  pthread_mutex_lock(&LOCK_prep_xids);
4736
 
  DBUG_ASSERT(prepared_xids > 0);
 
3905
  assert(prepared_xids > 0);
4737
3906
  if (--prepared_xids == 0) {
4738
 
    DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
4739
3907
    pthread_cond_signal(&COND_prep_xids);
4740
3908
  }
4741
3909
  pthread_mutex_unlock(&LOCK_prep_xids);
4762
3930
    if (ev->get_type_code() == XID_EVENT)
4763
3931
    {
4764
3932
      Xid_log_event *xev=(Xid_log_event *)ev;
4765
 
      uchar *x= (uchar *) memdup_root(&mem_root, (uchar*) &xev->xid,
 
3933
      unsigned char *x= (unsigned char *) memdup_root(&mem_root, (unsigned char*) &xev->xid,
4766
3934
                                      sizeof(xev->xid));
4767
3935
      if (! x)
4768
3936
        goto err2;
4782
3950
  free_root(&mem_root, MYF(0));
4783
3951
  hash_free(&xids);
4784
3952
err1:
4785
 
  sql_print_error("Crash recovery failed. Either correct the problem "
 
3953
  sql_print_error(_("Crash recovery failed. Either correct the problem "
4786
3954
                  "(if it's, for example, out of memory error) and restart, "
4787
3955
                  "or delete (or rename) binary log and start mysqld with "
4788
 
                  "--tc-heuristic-recover={commit|rollback}");
 
3956
                  "--tc-heuristic-recover={commit|rollback}"));
4789
3957
  return 1;
4790
3958
}
4791
3959
 
4805
3973
  @return byte offset from the beginning of the binlog
4806
3974
*/
4807
3975
extern "C"
4808
 
ulonglong mysql_bin_log_file_pos(void)
 
3976
uint64_t mysql_bin_log_file_pos(void)
4809
3977
{
4810
 
  return (ulonglong) mysql_bin_log.get_log_file()->pos_in_file;
 
3978
  return (uint64_t) mysql_bin_log.get_log_file()->pos_in_file;
4811
3979
}
4812
3980
#endif /* INNODB_COMPATIBILITY_HOOKS */
4813
3981
 
4814
3982
 
4815
 
struct st_mysql_storage_engine binlog_storage_engine=
4816
 
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
4817
 
 
4818
3983
mysql_declare_plugin(binlog)
4819
3984
{
4820
 
  MYSQL_STORAGE_ENGINE_PLUGIN,
4821
 
  &binlog_storage_engine,
 
3985
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
4822
3986
  "binlog",
 
3987
  "1.0",
4823
3988
  "MySQL AB",
4824
3989
  "This is a pseudo storage engine to represent the binlog in a transaction",
4825
3990
  PLUGIN_LICENSE_GPL,
4826
3991
  binlog_init, /* Plugin Init */
4827
3992
  NULL, /* Plugin Deinit */
4828
 
  0x0100 /* 1.0 */,
4829
3993
  NULL,                       /* status variables                */
4830
3994
  NULL,                       /* system variables                */
4831
3995
  NULL                        /* config options                  */