~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/log.cc

  • Committer: Brian Aker
  • Date: 2008-07-13 22:45:08 UTC
  • Revision ID: brian@tangent.org-20080713224508-hb20z4okblotb39a
longlong replacement

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 <drizzled/server_includes.h>
 
27
#include "mysql_priv.h"
28
28
#include "sql_repl.h"
29
29
#include "rpl_filter.h"
30
30
#include "rpl_rli.h"
31
31
 
32
 
#include <mysys/my_dir.h>
 
32
#include <my_dir.h>
33
33
#include <stdarg.h>
 
34
#include <m_ctype.h>                            // For test_if_number
34
35
 
35
 
#include <drizzled/plugin.h>
36
 
#include <drizzled/drizzled_error_messages.h>
37
 
#include <libdrizzle/gettext.h>
 
36
#include <mysql/plugin.h>
38
37
 
39
38
/* max size of the log message */
40
39
#define MAX_LOG_BUFFER_SIZE 1024
46
45
 
47
46
LOGGER logger;
48
47
 
49
 
DRIZZLE_BIN_LOG mysql_bin_log;
 
48
MYSQL_BIN_LOG mysql_bin_log;
50
49
ulong sync_binlog_counter= 0;
51
50
 
52
51
static bool test_if_number(const char *str,
204
203
 
205
204
 
206
205
/* Check if a given table is opened log table */
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)))
 
206
int check_if_log_table(uint db_len __attribute__((__unused__)),
 
207
                       const char *db __attribute__((__unused__)),
 
208
                       uint table_name_len __attribute__((__unused__)),
 
209
                       const char *table_name __attribute__((__unused__)),
 
210
                       uint check_if_opened __attribute__((__unused__)))
212
211
{
213
212
  return 0;
214
213
}
215
214
 
 
215
/* log event handlers */
 
216
 
 
217
bool Log_to_file_event_handler::
 
218
  log_error(enum loglevel level, const char *format,
 
219
            va_list args)
 
220
{
 
221
  return vprint_msg_to_log(level, format, args);
 
222
}
 
223
 
 
224
void Log_to_file_event_handler::init_pthread_objects()
 
225
{
 
226
  mysql_log.init_pthread_objects();
 
227
  mysql_slow_log.init_pthread_objects();
 
228
}
 
229
 
 
230
 
 
231
/** Wrapper around MYSQL_LOG::write() for slow log. */
 
232
 
 
233
bool Log_to_file_event_handler::
 
234
  log_slow(THD *thd, time_t current_time, time_t query_start_arg,
 
235
           const char *user_host, uint user_host_len,
 
236
           uint64_t query_utime, uint64_t lock_utime, bool is_command,
 
237
           const char *sql_text, uint sql_text_len)
 
238
{
 
239
  return mysql_slow_log.write(thd, current_time, query_start_arg,
 
240
                              user_host, user_host_len,
 
241
                              query_utime, lock_utime, is_command,
 
242
                              sql_text, sql_text_len);
 
243
}
 
244
 
 
245
 
 
246
/**
 
247
   Wrapper around MYSQL_LOG::write() for general log. We need it since we
 
248
   want all log event handlers to have the same signature.
 
249
*/
 
250
 
 
251
bool Log_to_file_event_handler::
 
252
  log_general(THD *thd __attribute__((__unused__)),
 
253
              time_t event_time, const char *user_host,
 
254
              uint user_host_len, int thread_id,
 
255
              const char *command_type, uint command_type_len,
 
256
              const char *sql_text, uint sql_text_len,
 
257
              CHARSET_INFO *client_cs __attribute__((__unused__)))
 
258
{
 
259
  return mysql_log.write(event_time, user_host, user_host_len,
 
260
                         thread_id, command_type, command_type_len,
 
261
                         sql_text, sql_text_len);
 
262
}
 
263
 
 
264
 
 
265
bool Log_to_file_event_handler::init()
 
266
{
 
267
  if (!is_initialized)
 
268
  {
 
269
    if (opt_slow_log)
 
270
      mysql_slow_log.open_slow_log(sys_var_slow_log_path.value);
 
271
 
 
272
    if (opt_log)
 
273
      mysql_log.open_query_log(sys_var_general_log_path.value);
 
274
 
 
275
    is_initialized= true;
 
276
  }
 
277
 
 
278
  return false;
 
279
}
 
280
 
 
281
 
 
282
void Log_to_file_event_handler::cleanup()
 
283
{
 
284
  mysql_log.cleanup();
 
285
  mysql_slow_log.cleanup();
 
286
}
 
287
 
 
288
void Log_to_file_event_handler::flush()
 
289
{
 
290
  /* reopen log files */
 
291
  if (opt_log)
 
292
    mysql_log.reopen_file();
 
293
  if (opt_slow_log)
 
294
    mysql_slow_log.reopen_file();
 
295
}
 
296
 
216
297
/*
217
298
  Log error with all enabled log event handlers
218
299
 
247
328
{
248
329
  assert(inited == 1);
249
330
  rwlock_destroy(&LOCK_logger);
 
331
  if (file_log_handler)
 
332
    file_log_handler->cleanup();
250
333
}
251
334
 
252
335
 
253
336
void LOGGER::cleanup_end()
254
337
{
255
338
  assert(inited == 1);
 
339
  if (file_log_handler)
 
340
    delete file_log_handler;
256
341
}
257
342
 
258
343
 
265
350
  assert(inited == 0);
266
351
  inited= 1;
267
352
 
 
353
  /*
 
354
    Here we create file log handler. We don't do it for the table log handler
 
355
    here as it cannot be created so early. The reason is THD initialization,
 
356
    which depends on the system variables (parsed later).
 
357
  */
 
358
  if (!file_log_handler)
 
359
    file_log_handler= new Log_to_file_event_handler;
 
360
 
268
361
  /* by default we use traditional error log */
269
362
  init_error_log(LOG_FILE);
270
363
 
 
364
  file_log_handler->init_pthread_objects();
271
365
  my_rwlock_init(&LOCK_logger, NULL);
272
366
}
273
367
 
274
368
 
275
 
bool LOGGER::flush_logs(THD *thd __attribute__((unused)))
 
369
bool LOGGER::flush_logs(THD *thd __attribute__((__unused__)))
276
370
{
277
371
  int rc= 0;
278
372
 
282
376
  */
283
377
  logger.lock_exclusive();
284
378
 
 
379
  /* reopen log files */
 
380
  file_log_handler->flush();
 
381
 
285
382
  /* end of log flush */
286
383
  logger.unlock();
287
384
  return rc;
288
385
}
289
386
 
290
 
void LOGGER::init_error_log(uint32_t error_log_printer)
 
387
 
 
388
/*
 
389
  Log slow query with all enabled log event handlers
 
390
 
 
391
  SYNOPSIS
 
392
    slow_log_print()
 
393
 
 
394
    thd                 THD of the query being logged
 
395
    query               The query being logged
 
396
    query_length        The length of the query string
 
397
    current_utime       Current time in microseconds (from undefined start)
 
398
 
 
399
  RETURN
 
400
    FALSE   OK
 
401
    TRUE    error occured
 
402
*/
 
403
 
 
404
bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
 
405
                            uint64_t current_utime)
 
406
 
 
407
{
 
408
  bool error= false;
 
409
  Log_event_handler **current_handler;
 
410
  bool is_command= false;
 
411
  char user_host_buff[MAX_USER_HOST_SIZE];
 
412
  Security_context *sctx= thd->security_ctx;
 
413
  uint user_host_len= 0;
 
414
  uint64_t query_utime, lock_utime;
 
415
 
 
416
  /*
 
417
    Print the message to the buffer if we have slow log enabled
 
418
  */
 
419
 
 
420
  if (*slow_log_handler_list)
 
421
  {
 
422
    time_t current_time;
 
423
 
 
424
    /* do not log slow queries from replication threads */
 
425
    if (thd->slave_thread && !opt_log_slow_slave_statements)
 
426
      return 0;
 
427
 
 
428
    lock_shared();
 
429
    if (!opt_slow_log)
 
430
    {
 
431
      unlock();
 
432
      return 0;
 
433
    }
 
434
 
 
435
    /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
 
436
    user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
 
437
                             sctx->priv_user ? sctx->priv_user : "", "[",
 
438
                             sctx->user ? sctx->user : "", "] @ ",
 
439
                             sctx->host ? sctx->host : "", " [",
 
440
                             sctx->ip ? sctx->ip : "", "]", NullS) -
 
441
                    user_host_buff);
 
442
 
 
443
    current_time= my_time_possible_from_micro(current_utime);
 
444
    if (thd->start_utime)
 
445
    {
 
446
      query_utime= (current_utime - thd->start_utime);
 
447
      lock_utime=  (thd->utime_after_lock - thd->start_utime);
 
448
    }
 
449
    else
 
450
    {
 
451
      query_utime= lock_utime= 0;
 
452
    }
 
453
 
 
454
    if (!query)
 
455
    {
 
456
      is_command= true;
 
457
      query= command_name[thd->command].str;
 
458
      query_length= command_name[thd->command].length;
 
459
    }
 
460
 
 
461
    for (current_handler= slow_log_handler_list; *current_handler ;)
 
462
      error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
 
463
                                            user_host_buff, user_host_len,
 
464
                                            query_utime, lock_utime, is_command,
 
465
                                            query, query_length) || error;
 
466
 
 
467
    unlock();
 
468
  }
 
469
  return error;
 
470
}
 
471
 
 
472
bool LOGGER::general_log_write(THD *thd, enum enum_server_command command,
 
473
                               const char *query, uint query_length)
 
474
{
 
475
  bool error= false;
 
476
  Log_event_handler **current_handler= general_log_handler_list;
 
477
  char user_host_buff[MAX_USER_HOST_SIZE];
 
478
  Security_context *sctx= thd->security_ctx;
 
479
  ulong id;
 
480
  uint user_host_len= 0;
 
481
  time_t current_time;
 
482
 
 
483
  if (thd)
 
484
    id= thd->thread_id;                 /* Normal thread */
 
485
  else
 
486
    id= 0;                              /* Log from connect handler */
 
487
 
 
488
  lock_shared();
 
489
  if (!opt_log)
 
490
  {
 
491
    unlock();
 
492
    return 0;
 
493
  }
 
494
  user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
 
495
                          sctx->priv_user ? sctx->priv_user : "", "[",
 
496
                          sctx->user ? sctx->user : "", "] @ ",
 
497
                          sctx->host ? sctx->host : "", " [",
 
498
                          sctx->ip ? sctx->ip : "", "]", NullS) -
 
499
                                                          user_host_buff;
 
500
 
 
501
  current_time= my_time(0);
 
502
 
 
503
  while (*current_handler)
 
504
    error|= (*current_handler++)->
 
505
      log_general(thd, current_time, user_host_buff,
 
506
                  user_host_len, id,
 
507
                  command_name[(uint) command].str,
 
508
                  command_name[(uint) command].length,
 
509
                  query, query_length,
 
510
                  thd->variables.character_set_client) || error;
 
511
  unlock();
 
512
 
 
513
  return error;
 
514
}
 
515
 
 
516
bool LOGGER::general_log_print(THD *thd, enum enum_server_command command,
 
517
                               const char *format, va_list args)
 
518
{
 
519
  uint message_buff_len= 0;
 
520
  char message_buff[MAX_LOG_BUFFER_SIZE];
 
521
 
 
522
  /* prepare message */
 
523
  if (format)
 
524
    message_buff_len= vsnprintf(message_buff, sizeof(message_buff),
 
525
                                   format, args);
 
526
  else
 
527
    message_buff[0]= '\0';
 
528
 
 
529
  return general_log_write(thd, command, message_buff, message_buff_len);
 
530
}
 
531
 
 
532
void LOGGER::init_error_log(uint error_log_printer)
291
533
{
292
534
  if (error_log_printer & LOG_NONE)
293
535
  {
295
537
    return;
296
538
  }
297
539
 
298
 
}
299
 
 
300
 
int LOGGER::set_handlers(uint32_t error_log_printer)
 
540
  switch (error_log_printer) {
 
541
  case LOG_FILE:
 
542
    error_log_handler_list[0]= file_log_handler;
 
543
    error_log_handler_list[1]= 0;
 
544
    break;
 
545
    /* these two are disabled for now */
 
546
  case LOG_TABLE:
 
547
    assert(0);
 
548
    break;
 
549
  case LOG_TABLE|LOG_FILE:
 
550
    assert(0);
 
551
    break;
 
552
  }
 
553
}
 
554
 
 
555
void LOGGER::init_slow_log(uint slow_log_printer)
 
556
{
 
557
  if (slow_log_printer & LOG_NONE)
 
558
  {
 
559
    slow_log_handler_list[0]= 0;
 
560
    return;
 
561
  }
 
562
 
 
563
  slow_log_handler_list[0]= file_log_handler;
 
564
  slow_log_handler_list[1]= 0;
 
565
}
 
566
 
 
567
void LOGGER::init_general_log(uint general_log_printer)
 
568
{
 
569
  if (general_log_printer & LOG_NONE)
 
570
  {
 
571
    general_log_handler_list[0]= 0;
 
572
    return;
 
573
  }
 
574
 
 
575
  general_log_handler_list[0]= file_log_handler;
 
576
  general_log_handler_list[1]= 0;
 
577
}
 
578
 
 
579
 
 
580
bool LOGGER::activate_log_handler(THD* thd __attribute__((__unused__)),
 
581
                                  uint log_type)
 
582
{
 
583
  MYSQL_QUERY_LOG *file_log;
 
584
  bool res= false;
 
585
  lock_exclusive();
 
586
  switch (log_type) {
 
587
  case QUERY_LOG_SLOW:
 
588
    if (!opt_slow_log)
 
589
    {
 
590
      file_log= file_log_handler->get_mysql_slow_log();
 
591
 
 
592
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
593
      init_slow_log(log_output_options);
 
594
      opt_slow_log= true;
 
595
    }
 
596
    break;
 
597
  case QUERY_LOG_GENERAL:
 
598
    if (!opt_log)
 
599
    {
 
600
      file_log= file_log_handler->get_mysql_log();
 
601
 
 
602
      file_log->open_query_log(sys_var_general_log_path.value);
 
603
      init_general_log(log_output_options);
 
604
      opt_log= true;
 
605
    }
 
606
    break;
 
607
  default:
 
608
    assert(0);
 
609
  }
 
610
  unlock();
 
611
  return res;
 
612
}
 
613
 
 
614
 
 
615
void LOGGER::deactivate_log_handler(THD *thd __attribute__((__unused__)),
 
616
                                    uint log_type)
 
617
{
 
618
  bool *tmp_opt= 0;
 
619
  MYSQL_LOG *file_log;
 
620
 
 
621
  switch (log_type) {
 
622
  case QUERY_LOG_SLOW:
 
623
    tmp_opt= &opt_slow_log;
 
624
    file_log= file_log_handler->get_mysql_slow_log();
 
625
    break;
 
626
  case QUERY_LOG_GENERAL:
 
627
    tmp_opt= &opt_log;
 
628
    file_log= file_log_handler->get_mysql_log();
 
629
    break;
 
630
  default:
 
631
    assert(0);                                  // Impossible
 
632
  }
 
633
 
 
634
  if (!(*tmp_opt))
 
635
    return;
 
636
 
 
637
  lock_exclusive();
 
638
  file_log->close(0);
 
639
  *tmp_opt= false;
 
640
  unlock();
 
641
}
 
642
 
 
643
int LOGGER::set_handlers(uint error_log_printer,
 
644
                         uint slow_log_printer,
 
645
                         uint general_log_printer)
301
646
{
302
647
  /* error log table is not supported yet */
 
648
  assert(error_log_printer < LOG_TABLE);
 
649
 
303
650
  lock_exclusive();
304
651
 
305
652
  init_error_log(error_log_printer);
 
653
  init_slow_log(slow_log_printer);
 
654
  init_general_log(general_log_printer);
 
655
 
306
656
  unlock();
307
657
 
308
658
  return 0;
369
719
 
370
720
/*
371
721
  this function is mostly a placeholder.
372
 
  conceptually, binlog initialization (now mostly done in DRIZZLE_BIN_LOG::open)
 
722
  conceptually, binlog initialization (now mostly done in MYSQL_BIN_LOG::open)
373
723
  should be moved here.
374
724
*/
375
725
 
377
727
{
378
728
  binlog_hton= (handlerton *)p;
379
729
  binlog_hton->state=opt_bin_log ? SHOW_OPTION_YES : SHOW_OPTION_NO;
 
730
  binlog_hton->db_type=DB_TYPE_BINLOG;
380
731
  binlog_hton->savepoint_offset= sizeof(my_off_t);
381
732
  binlog_hton->close_connection= binlog_close_connection;
382
733
  binlog_hton->savepoint_set= binlog_savepoint_set;
385
736
  binlog_hton->rollback= binlog_rollback;
386
737
  binlog_hton->prepare= binlog_prepare;
387
738
  binlog_hton->flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN;
388
 
 
389
739
  return 0;
390
740
}
391
741
 
392
 
static int binlog_close_connection(handlerton *hton __attribute__((unused)),
 
742
static int binlog_close_connection(handlerton *hton __attribute__((__unused__)),
393
743
                                   THD *thd)
394
744
{
395
745
  binlog_trx_data *const trx_data=
397
747
  assert(trx_data->empty());
398
748
  thd_set_ha_data(thd, binlog_hton, NULL);
399
749
  trx_data->~binlog_trx_data();
400
 
  free((unsigned char*)trx_data);
 
750
  my_free((uchar*)trx_data, MYF(0));
401
751
  return 0;
402
752
}
403
753
 
496
846
  return(error);
497
847
}
498
848
 
499
 
static int binlog_prepare(handlerton *hton __attribute__((unused)),
500
 
                          THD *thd __attribute__((unused)),
501
 
                          bool all __attribute__((unused)))
 
849
static int binlog_prepare(handlerton *hton __attribute__((__unused__)),
 
850
                          THD *thd __attribute__((__unused__)),
 
851
                          bool all __attribute__((__unused__)))
502
852
{
503
853
  /*
504
854
    do nothing.
505
855
    just pretend we can do 2pc, so that MySQL won't
506
856
    switch to 1pc.
507
 
    real work will be done in DRIZZLE_BIN_LOG::log_xid()
 
857
    real work will be done in MYSQL_BIN_LOG::log_xid()
508
858
  */
509
859
  return 0;
510
860
}
524
874
 
525
875
  @see handlerton::commit
526
876
*/
527
 
static int binlog_commit(handlerton *hton __attribute__((unused)),
 
877
static int binlog_commit(handlerton *hton __attribute__((__unused__)),
528
878
                         THD *thd, bool all)
529
879
{
530
880
  binlog_trx_data *const trx_data=
532
882
 
533
883
  if (trx_data->empty())
534
884
  {
535
 
    // we're here because trans_log was flushed in DRIZZLE_BIN_LOG::log_xid()
 
885
    // we're here because trans_log was flushed in MYSQL_BIN_LOG::log_xid()
536
886
    trx_data->reset();
537
887
    return(0);
538
888
  }
600
950
  if ((in_transaction && (all || (!trx_data->at_least_one_stmt && thd->transaction.stmt.modified_non_trans_table))) || (!in_transaction && !all))
601
951
  {
602
952
    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)
 
953
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
604
954
    int error= binlog_end_trans(thd, trx_data, &qev, all);
605
955
    return(error);
606
956
  }
622
972
 
623
973
  @see handlerton::rollback
624
974
*/
625
 
static int binlog_rollback(handlerton *hton __attribute__((unused)),
 
975
static int binlog_rollback(handlerton *hton __attribute__((__unused__)),
626
976
                           THD *thd, bool all)
627
977
{
628
978
  int error=0;
647
997
      rolled back on the slave.
648
998
    */
649
999
    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)
 
1000
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
651
1001
    error= binlog_end_trans(thd, trx_data, &qev, all);
652
1002
  }
653
1003
  else if ((all && !thd->transaction.all.modified_non_trans_table) ||
687
1037
  that case there is no need to have it in the binlog).
688
1038
*/
689
1039
 
690
 
static int binlog_savepoint_set(handlerton *hton __attribute__((unused)),
 
1040
static int binlog_savepoint_set(handlerton *hton __attribute__((__unused__)),
691
1041
                                THD *thd, void *sv)
692
1042
{
693
1043
  binlog_trans_log_savepos(thd, (my_off_t*) sv);
699
1049
  return(error);
700
1050
}
701
1051
 
702
 
static int binlog_savepoint_rollback(handlerton *hton __attribute__((unused)),
 
1052
static int binlog_savepoint_rollback(handlerton *hton __attribute__((__unused__)),
703
1053
                                     THD *thd, void *sv)
704
1054
{
705
1055
  /*
725
1075
  char magic[4];
726
1076
  assert(my_b_tell(log) == 0);
727
1077
 
728
 
  if (my_b_read(log, (unsigned char*) magic, sizeof(magic)))
 
1078
  if (my_b_read(log, (uchar*) magic, sizeof(magic)))
729
1079
  {
730
 
    *errmsg = _("I/O error reading the header from the binary log");
 
1080
    *errmsg = "I/O error reading the header from the binary log";
731
1081
    sql_print_error("%s, errno=%d, io cache code=%d", *errmsg, my_errno,
732
1082
                    log->error);
733
1083
    return 1;
734
1084
  }
735
1085
  if (memcmp(magic, BINLOG_MAGIC, sizeof(magic)))
736
1086
  {
737
 
    *errmsg = _("Binlog has bad magic number;  It's not a binary log file "
738
 
                "that can be used by this version of Drizzle");
 
1087
    *errmsg = "Binlog has bad magic number;  It's not a binary log file that can be used by this version of MySQL";
739
1088
    return 1;
740
1089
  }
741
1090
  return 0;
749
1098
  if ((file = my_open(log_file_name, O_RDONLY | O_BINARY | O_SHARE, 
750
1099
                      MYF(MY_WME))) < 0)
751
1100
  {
752
 
    sql_print_error(_("Failed to open log (file '%s', errno %d)"),
 
1101
    sql_print_error("Failed to open log (file '%s', errno %d)",
753
1102
                    log_file_name, my_errno);
754
 
    *errmsg = _("Could not open log file");
 
1103
    *errmsg = "Could not open log file";
755
1104
    goto err;
756
1105
  }
757
1106
  if (init_io_cache(log, file, IO_SIZE*2, READ_CACHE, 0, 0,
758
1107
                    MYF(MY_WME|MY_DONT_CHECK_FILESIZE)))
759
1108
  {
760
 
    sql_print_error(_("Failed to create a cache on log (file '%s')"),
 
1109
    sql_print_error("Failed to create a cache on log (file '%s')",
761
1110
                    log_file_name);
762
 
    *errmsg = _("Could not open log file");
 
1111
    *errmsg = "Could not open log file";
763
1112
    goto err;
764
1113
  }
765
1114
  if (check_binlog_magic(log,errmsg))
788
1137
static int find_uniq_filename(char *name)
789
1138
{
790
1139
  long                  number;
791
 
  uint32_t                  i;
 
1140
  uint                  i;
792
1141
  char                  buff[FN_REFLEN];
793
1142
  struct st_my_dir     *dir_info;
794
1143
  register struct fileinfo *file_info;
798
1147
 
799
1148
  length= dirname_part(buff, name, &buf_length);
800
1149
  start=  name + length;
801
 
  end= strchr(start, '\0');
 
1150
  end=    strend(start);
802
1151
 
803
1152
  *end='.';
804
1153
  length= (size_t) (end-start+1);
805
1154
 
806
1155
  if (!(dir_info = my_dir(buff,MYF(MY_DONT_SORT))))
807
1156
  {                                             // This shouldn't happen
808
 
    my_stpcpy(end,".1");                                // use name+1
 
1157
    strmov(end,".1");                           // use name+1
809
1158
    return(0);
810
1159
  }
811
1160
  file_info= dir_info->dir_entry;
812
1161
  for (i=dir_info->number_off_files ; i-- ; file_info++)
813
1162
  {
814
 
    if (memcmp(file_info->name, start, length) == 0 &&
 
1163
    if (bcmp((uchar*) file_info->name, (uchar*) start, length) == 0 &&
815
1164
        test_if_number(file_info->name+length, &number,0))
816
1165
    {
817
1166
      set_if_bigger(max_found,(ulong) number);
825
1174
}
826
1175
 
827
1176
 
828
 
void DRIZZLE_LOG::init(enum_log_type log_type_arg,
 
1177
void MYSQL_LOG::init(enum_log_type log_type_arg,
829
1178
                     enum cache_type io_cache_type_arg)
830
1179
{
831
1180
  log_type= log_type_arg;
855
1204
    1   error
856
1205
*/
857
1206
 
858
 
bool DRIZZLE_LOG::open(const char *log_name, enum_log_type log_type_arg,
 
1207
bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
859
1208
                     const char *new_name, enum cache_type io_cache_type_arg)
860
1209
{
861
1210
  char buff[FN_REFLEN];
873
1222
  }
874
1223
 
875
1224
  if (new_name)
876
 
    my_stpcpy(log_file_name, new_name);
 
1225
    strmov(log_file_name, new_name);
877
1226
  else if (generate_new_name(log_file_name, name))
878
1227
    goto err;
879
1228
 
897
1246
    char *end;
898
1247
    int len=snprintf(buff, sizeof(buff), "%s, Version: %s (%s). "
899
1248
                     "started with:\nTCP Port: %d, Named Pipe: %s\n",
900
 
                     my_progname, server_version, DRIZZLE_COMPILATION_COMMENT,
 
1249
                     my_progname, server_version, MYSQL_COMPILATION_COMMENT,
901
1250
                     mysqld_port, ""
902
1251
                     );
903
 
    end= my_stpncpy(buff + len, "Time                 Id Command    Argument\n",
 
1252
    end= strnmov(buff + len, "Time                 Id Command    Argument\n",
904
1253
                 sizeof(buff) - len);
905
 
    if (my_b_write(&log_file, (unsigned char*) buff, (uint) (end-buff)) ||
 
1254
    if (my_b_write(&log_file, (uchar*) buff, (uint) (end-buff)) ||
906
1255
        flush_io_cache(&log_file))
907
1256
      goto err;
908
1257
  }
911
1260
  return(0);
912
1261
 
913
1262
err:
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);
 
1263
  sql_print_error("Could not use %s for logging (error %d). \
 
1264
Turning logging off for the whole duration of the MySQL server process. \
 
1265
To turn it on again: fix the cause, \
 
1266
shutdown the MySQL server and restart it.", name, errno);
920
1267
  if (file >= 0)
921
1268
    my_close(file, MYF(0));
922
1269
  end_io_cache(&log_file);
923
 
  if (name)
924
 
  {
925
 
    free(name);
926
 
    name= NULL;
927
 
  }
 
1270
  safeFree(name);
928
1271
  log_state= LOG_CLOSED;
929
1272
  return(1);
930
1273
}
931
1274
 
932
 
DRIZZLE_LOG::DRIZZLE_LOG()
 
1275
MYSQL_LOG::MYSQL_LOG()
933
1276
  : name(0), write_error(false), inited(false), log_type(LOG_UNKNOWN),
934
1277
    log_state(LOG_CLOSED)
935
1278
{
939
1282
    called only in main(). Doing initialization here would make it happen
940
1283
    before main().
941
1284
  */
942
 
  memset(&log_file, 0, sizeof(log_file));
 
1285
  bzero((char*) &log_file, sizeof(log_file));
943
1286
}
944
1287
 
945
 
void DRIZZLE_LOG::init_pthread_objects()
 
1288
void MYSQL_LOG::init_pthread_objects()
946
1289
{
947
1290
  assert(inited == 0);
948
1291
  inited= 1;
963
1306
    The internal structures are not freed until cleanup() is called
964
1307
*/
965
1308
 
966
 
void DRIZZLE_LOG::close(uint32_t exiting)
 
1309
void MYSQL_LOG::close(uint exiting)
967
1310
{                                       // One can't set log_type here!
968
1311
  if (log_state == LOG_OPENED)
969
1312
  {
983
1326
  }
984
1327
 
985
1328
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
986
 
  if (name)
987
 
  {
988
 
    free(name);
989
 
    name= NULL;
990
 
  }
 
1329
  safeFree(name);
991
1330
  return;
992
1331
}
993
1332
 
994
1333
/** This is called only once. */
995
1334
 
996
 
void DRIZZLE_LOG::cleanup()
 
1335
void MYSQL_LOG::cleanup()
997
1336
{
998
1337
  if (inited)
999
1338
  {
1005
1344
}
1006
1345
 
1007
1346
 
1008
 
int DRIZZLE_LOG::generate_new_name(char *new_name, const char *log_name)
 
1347
int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name)
1009
1348
{
1010
1349
  fn_format(new_name, log_name, mysql_data_home, "", 4);
1011
1350
  if (log_type == LOG_BIN)
1023
1362
}
1024
1363
 
1025
1364
 
 
1365
/*
 
1366
  Reopen the log file
 
1367
 
 
1368
  SYNOPSIS
 
1369
    reopen_file()
 
1370
 
 
1371
  DESCRIPTION
 
1372
    Reopen the log file. The method is used during FLUSH LOGS
 
1373
    and locks LOCK_log mutex
 
1374
*/
 
1375
 
 
1376
 
 
1377
void MYSQL_QUERY_LOG::reopen_file()
 
1378
{
 
1379
  char *save_name;
 
1380
 
 
1381
  if (!is_open())
 
1382
  {
 
1383
    return;
 
1384
  }
 
1385
 
 
1386
  pthread_mutex_lock(&LOCK_log);
 
1387
 
 
1388
  save_name= name;
 
1389
  name= 0;                              // Don't free name
 
1390
  close(LOG_CLOSE_TO_BE_OPENED);
 
1391
 
 
1392
  /*
 
1393
     Note that at this point, log_state != LOG_CLOSED (important for is_open()).
 
1394
  */
 
1395
 
 
1396
  open(save_name, log_type, 0, io_cache_type);
 
1397
  my_free(save_name, MYF(0));
 
1398
 
 
1399
  pthread_mutex_unlock(&LOCK_log);
 
1400
 
 
1401
  return;
 
1402
}
 
1403
 
 
1404
 
 
1405
/*
 
1406
  Write a command to traditional general log file
 
1407
 
 
1408
  SYNOPSIS
 
1409
    write()
 
1410
 
 
1411
    event_time        command start timestamp
 
1412
    user_host         the pointer to the string with user@host info
 
1413
    user_host_len     length of the user_host string. this is computed once
 
1414
                      and passed to all general log  event handlers
 
1415
    thread_id         Id of the thread, issued a query
 
1416
    command_type      the type of the command being logged
 
1417
    command_type_len  the length of the string above
 
1418
    sql_text          the very text of the query being executed
 
1419
    sql_text_len      the length of sql_text string
 
1420
 
 
1421
  DESCRIPTION
 
1422
 
 
1423
   Log given command to to normal (not rotable) log file
 
1424
 
 
1425
  RETURN
 
1426
    FASE - OK
 
1427
    TRUE - error occured
 
1428
*/
 
1429
 
 
1430
bool MYSQL_QUERY_LOG::write(time_t event_time,
 
1431
                            const char *user_host __attribute__((__unused__)),
 
1432
                            uint user_host_len __attribute__((__unused__)),
 
1433
                            int thread_id,
 
1434
                            const char *command_type, uint command_type_len,
 
1435
                            const char *sql_text, uint sql_text_len)
 
1436
{
 
1437
  char buff[32];
 
1438
  uint length= 0;
 
1439
  char local_time_buff[MAX_TIME_SIZE];
 
1440
  struct tm start;
 
1441
  uint time_buff_len= 0;
 
1442
 
 
1443
  (void) pthread_mutex_lock(&LOCK_log);
 
1444
 
 
1445
  /* Test if someone closed between the is_open test and lock */
 
1446
  if (is_open())
 
1447
  {
 
1448
    /* Note that my_b_write() assumes it knows the length for this */
 
1449
      if (event_time != last_time)
 
1450
      {
 
1451
        last_time= event_time;
 
1452
 
 
1453
        localtime_r(&event_time, &start);
 
1454
 
 
1455
        time_buff_len= snprintf(local_time_buff, MAX_TIME_SIZE,
 
1456
                                "%02d%02d%02d %2d:%02d:%02d",
 
1457
                                start.tm_year % 100, start.tm_mon + 1,
 
1458
                                start.tm_mday, start.tm_hour,
 
1459
                                start.tm_min, start.tm_sec);
 
1460
 
 
1461
        if (my_b_write(&log_file, (uchar*) local_time_buff, time_buff_len))
 
1462
          goto err;
 
1463
      }
 
1464
      else
 
1465
        if (my_b_write(&log_file, (uchar*) "\t\t" ,2) < 0)
 
1466
          goto err;
 
1467
 
 
1468
      /* command_type, thread_id */
 
1469
      length= snprintf(buff, 32, "%5ld ", (long) thread_id);
 
1470
 
 
1471
    if (my_b_write(&log_file, (uchar*) buff, length))
 
1472
      goto err;
 
1473
 
 
1474
    if (my_b_write(&log_file, (uchar*) command_type, command_type_len))
 
1475
      goto err;
 
1476
 
 
1477
    if (my_b_write(&log_file, (uchar*) "\t", 1))
 
1478
      goto err;
 
1479
 
 
1480
    /* sql_text */
 
1481
    if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len))
 
1482
      goto err;
 
1483
 
 
1484
    if (my_b_write(&log_file, (uchar*) "\n", 1) ||
 
1485
        flush_io_cache(&log_file))
 
1486
      goto err;
 
1487
  }
 
1488
 
 
1489
  (void) pthread_mutex_unlock(&LOCK_log);
 
1490
  return false;
 
1491
err:
 
1492
 
 
1493
  if (!write_error)
 
1494
  {
 
1495
    write_error= 1;
 
1496
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
 
1497
  }
 
1498
  (void) pthread_mutex_unlock(&LOCK_log);
 
1499
  return true;
 
1500
}
 
1501
 
 
1502
 
 
1503
/*
 
1504
  Log a query to the traditional slow log file
 
1505
 
 
1506
  SYNOPSIS
 
1507
    write()
 
1508
 
 
1509
    thd               THD of the query
 
1510
    current_time      current timestamp
 
1511
    query_start_arg   command start timestamp
 
1512
    user_host         the pointer to the string with user@host info
 
1513
    user_host_len     length of the user_host string. this is computed once
 
1514
                      and passed to all general log event handlers
 
1515
    query_utime       Amount of time the query took to execute (in microseconds)
 
1516
    lock_utime        Amount of time the query was locked (in microseconds)
 
1517
    is_command        The flag, which determines, whether the sql_text is a
 
1518
                      query or an administrator command.
 
1519
    sql_text          the very text of the query or administrator command
 
1520
                      processed
 
1521
    sql_text_len      the length of sql_text string
 
1522
 
 
1523
  DESCRIPTION
 
1524
 
 
1525
   Log a query to the slow log file.
 
1526
 
 
1527
  RETURN
 
1528
    FALSE - OK
 
1529
    TRUE - error occured
 
1530
*/
 
1531
 
 
1532
bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
 
1533
                            time_t query_start_arg __attribute__((__unused__)),
 
1534
                            const char *user_host,
 
1535
                            uint user_host_len, uint64_t query_utime,
 
1536
                            uint64_t lock_utime, bool is_command,
 
1537
                            const char *sql_text, uint sql_text_len)
 
1538
{
 
1539
  bool error= 0;
 
1540
 
 
1541
  (void) pthread_mutex_lock(&LOCK_log);
 
1542
 
 
1543
  if (!is_open())
 
1544
  {
 
1545
    (void) pthread_mutex_unlock(&LOCK_log);
 
1546
    return(0);
 
1547
  }
 
1548
 
 
1549
  if (is_open())
 
1550
  {                                             // Safety agains reopen
 
1551
    int tmp_errno= 0;
 
1552
    char buff[80], *end;
 
1553
    char query_time_buff[22+7], lock_time_buff[22+7];
 
1554
    uint buff_len;
 
1555
    end= buff;
 
1556
 
 
1557
    if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
 
1558
    {
 
1559
      if (current_time != last_time)
 
1560
      {
 
1561
        last_time= current_time;
 
1562
        struct tm start;
 
1563
        localtime_r(&current_time, &start);
 
1564
 
 
1565
        buff_len= snprintf(buff, sizeof buff,
 
1566
                           "# Time: %02d%02d%02d %2d:%02d:%02d\n",
 
1567
                           start.tm_year % 100, start.tm_mon + 1,
 
1568
                           start.tm_mday, start.tm_hour,
 
1569
                           start.tm_min, start.tm_sec);
 
1570
 
 
1571
        /* Note that my_b_write() assumes it knows the length for this */
 
1572
        if (my_b_write(&log_file, (uchar*) buff, buff_len))
 
1573
          tmp_errno= errno;
 
1574
      }
 
1575
      const uchar uh[]= "# User@Host: ";
 
1576
      if (my_b_write(&log_file, uh, sizeof(uh) - 1))
 
1577
        tmp_errno= errno;
 
1578
      if (my_b_write(&log_file, (uchar*) user_host, user_host_len))
 
1579
        tmp_errno= errno;
 
1580
      if (my_b_write(&log_file, (uchar*) "\n", 1))
 
1581
        tmp_errno= errno;
 
1582
    }
 
1583
    /* For slow query log */
 
1584
    sprintf(query_time_buff, "%.6f", uint64_t2double(query_utime)/1000000.0);
 
1585
    sprintf(lock_time_buff,  "%.6f", uint64_t2double(lock_utime)/1000000.0);
 
1586
    if (my_b_printf(&log_file,
 
1587
                    "# Query_time: %s  Lock_time: %s"
 
1588
                    " Rows_sent: %lu  Rows_examined: %lu\n",
 
1589
                    query_time_buff, lock_time_buff,
 
1590
                    (ulong) thd->sent_row_count,
 
1591
                    (ulong) thd->examined_row_count) == (uint) -1)
 
1592
      tmp_errno= errno;
 
1593
    if (thd->db && strcmp(thd->db, db))
 
1594
    {                                           // Database changed
 
1595
      if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
 
1596
        tmp_errno= errno;
 
1597
      strmov(db,thd->db);
 
1598
    }
 
1599
    if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
 
1600
    {
 
1601
      end=strmov(end, ",last_insert_id=");
 
1602
      end=int64_t10_to_str((int64_t)
 
1603
                            thd->first_successful_insert_id_in_prev_stmt_for_binlog,
 
1604
                            end, -10);
 
1605
    }
 
1606
    // Save value if we do an insert.
 
1607
    if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
 
1608
    {
 
1609
      if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
 
1610
      {
 
1611
        end=strmov(end,",insert_id=");
 
1612
        end=int64_t10_to_str((int64_t)
 
1613
                              thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(),
 
1614
                              end, -10);
 
1615
      }
 
1616
    }
 
1617
 
 
1618
    /*
 
1619
      This info used to show up randomly, depending on whether the query
 
1620
      checked the query start time or not. now we always write current
 
1621
      timestamp to the slow log
 
1622
    */
 
1623
    end= strmov(end, ",timestamp=");
 
1624
    end= int10_to_str((long) current_time, end, 10);
 
1625
 
 
1626
    if (end != buff)
 
1627
    {
 
1628
      *end++=';';
 
1629
      *end='\n';
 
1630
      if (my_b_write(&log_file, (uchar*) "SET ", 4) ||
 
1631
          my_b_write(&log_file, (uchar*) buff + 1, (uint) (end-buff)))
 
1632
        tmp_errno= errno;
 
1633
    }
 
1634
    if (is_command)
 
1635
    {
 
1636
      end= strxmov(buff, "# administrator command: ", NullS);
 
1637
      buff_len= (ulong) (end - buff);
 
1638
      my_b_write(&log_file, (uchar*) buff, buff_len);
 
1639
    }
 
1640
    if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len) ||
 
1641
        my_b_write(&log_file, (uchar*) ";\n",2) ||
 
1642
        flush_io_cache(&log_file))
 
1643
      tmp_errno= errno;
 
1644
    if (tmp_errno)
 
1645
    {
 
1646
      error= 1;
 
1647
      if (! write_error)
 
1648
      {
 
1649
        write_error= 1;
 
1650
        sql_print_error(ER(ER_ERROR_ON_WRITE), name, error);
 
1651
      }
 
1652
    }
 
1653
  }
 
1654
  (void) pthread_mutex_unlock(&LOCK_log);
 
1655
  return(error);
 
1656
}
 
1657
 
 
1658
 
1026
1659
/**
1027
1660
  @todo
1028
1661
  The following should be using fn_format();  We just need to
1029
1662
  first change fn_format() to cut the file name if it's too long.
1030
1663
*/
1031
 
const char *DRIZZLE_LOG::generate_name(const char *log_name,
 
1664
const char *MYSQL_LOG::generate_name(const char *log_name,
1032
1665
                                      const char *suffix,
1033
1666
                                      bool strip_ext, char *buff)
1034
1667
{
1042
1675
  if (strip_ext)
1043
1676
  {
1044
1677
    char *p= fn_ext(log_name);
1045
 
    uint32_t length= (uint) (p - log_name);
1046
 
    strmake(buff, log_name, cmin(length, (uint)FN_REFLEN));
 
1678
    uint length= (uint) (p - log_name);
 
1679
    strmake(buff, log_name, min(length, FN_REFLEN));
1047
1680
    return (const char*)buff;
1048
1681
  }
1049
1682
  return log_name;
1051
1684
 
1052
1685
 
1053
1686
 
1054
 
DRIZZLE_BIN_LOG::DRIZZLE_BIN_LOG()
 
1687
MYSQL_BIN_LOG::MYSQL_BIN_LOG()
1055
1688
  :bytes_written(0), prepared_xids(0), file_id(1), open_count(1),
1056
1689
   need_start_event(true), m_table_map_version(0),
1057
1690
   description_event_for_exec(0), description_event_for_queue(0)
1063
1696
    before main().
1064
1697
  */
1065
1698
  index_file_name[0] = 0;
1066
 
  memset(&index_file, 0, sizeof(index_file));
 
1699
  bzero((char*) &index_file, sizeof(index_file));
1067
1700
}
1068
1701
 
1069
1702
/* this is called only once */
1070
1703
 
1071
 
void DRIZZLE_BIN_LOG::cleanup()
 
1704
void MYSQL_BIN_LOG::cleanup()
1072
1705
{
1073
1706
  if (inited)
1074
1707
  {
1085
1718
 
1086
1719
 
1087
1720
/* Init binlog-specific vars */
1088
 
void DRIZZLE_BIN_LOG::init(bool no_auto_events_arg, ulong max_size_arg)
 
1721
void MYSQL_BIN_LOG::init(bool no_auto_events_arg, ulong max_size_arg)
1089
1722
{
1090
1723
  no_auto_events= no_auto_events_arg;
1091
1724
  max_size= max_size_arg;
1093
1726
}
1094
1727
 
1095
1728
 
1096
 
void DRIZZLE_BIN_LOG::init_pthread_objects()
 
1729
void MYSQL_BIN_LOG::init_pthread_objects()
1097
1730
{
1098
1731
  assert(inited == 0);
1099
1732
  inited= 1;
1103
1736
}
1104
1737
 
1105
1738
 
1106
 
bool DRIZZLE_BIN_LOG::open_index_file(const char *index_file_name_arg,
 
1739
bool MYSQL_BIN_LOG::open_index_file(const char *index_file_name_arg,
1107
1740
                                const char *log_name)
1108
1741
{
1109
1742
  File index_file_nr= -1;
1158
1791
    1   error
1159
1792
*/
1160
1793
 
1161
 
bool DRIZZLE_BIN_LOG::open(const char *log_name,
 
1794
bool MYSQL_BIN_LOG::open(const char *log_name,
1162
1795
                         enum_log_type log_type_arg,
1163
1796
                         const char *new_name,
1164
1797
                         enum cache_type io_cache_type_arg,
1171
1804
  write_error=0;
1172
1805
 
1173
1806
  /* open the main log file */
1174
 
  if (DRIZZLE_LOG::open(log_name, log_type_arg, new_name, io_cache_type_arg))
 
1807
  if (MYSQL_LOG::open(log_name, log_type_arg, new_name, io_cache_type_arg))
1175
1808
    return(1);                            /* all warnings issued */
1176
1809
 
1177
1810
  init(no_auto_events_arg, max_size_arg);
1191
1824
        an extension for the binary log files.
1192
1825
        In this case we write a standard header to it.
1193
1826
      */
1194
 
      if (my_b_safe_write(&log_file, (unsigned char*) BINLOG_MAGIC,
 
1827
      if (my_b_safe_write(&log_file, (uchar*) BINLOG_MAGIC,
1195
1828
                          BIN_LOG_HEADER_SIZE))
1196
1829
        goto err;
1197
1830
      bytes_written+= BIN_LOG_HEADER_SIZE;
1262
1895
        As this is a new log file, we write the file name to the index
1263
1896
        file. As every time we write to the index file, we sync it.
1264
1897
      */
1265
 
      if (my_b_write(&index_file, (unsigned char*) log_file_name,
 
1898
      if (my_b_write(&index_file, (uchar*) log_file_name,
1266
1899
                     strlen(log_file_name)) ||
1267
 
          my_b_write(&index_file, (unsigned char*) "\n", 1) ||
 
1900
          my_b_write(&index_file, (uchar*) "\n", 1) ||
1268
1901
          flush_io_cache(&index_file) ||
1269
1902
          my_sync(index_file.file, MYF(MY_WME)))
1270
1903
        goto err;
1275
1908
  return(0);
1276
1909
 
1277
1910
err:
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);
 
1911
  sql_print_error("Could not use %s for logging (error %d). \
 
1912
Turning logging off for the whole duration of the MySQL server process. \
 
1913
To turn it on again: fix the cause, \
 
1914
shutdown the MySQL server and restart it.", name, errno);
1284
1915
  if (file >= 0)
1285
1916
    my_close(file,MYF(0));
1286
1917
  end_io_cache(&log_file);
1287
1918
  end_io_cache(&index_file);
1288
 
  if (name)
1289
 
  {
1290
 
    free(name);
1291
 
    name= NULL;
1292
 
  }
 
1919
  safeFree(name);
1293
1920
  log_state= LOG_CLOSED;
1294
1921
  return(1);
1295
1922
}
1296
1923
 
1297
1924
 
1298
 
int DRIZZLE_BIN_LOG::get_current_log(LOG_INFO* linfo)
 
1925
int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo)
1299
1926
{
1300
1927
  pthread_mutex_lock(&LOCK_log);
1301
1928
  int ret = raw_get_current_log(linfo);
1303
1930
  return ret;
1304
1931
}
1305
1932
 
1306
 
int DRIZZLE_BIN_LOG::raw_get_current_log(LOG_INFO* linfo)
 
1933
int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO* linfo)
1307
1934
{
1308
1935
  strmake(linfo->log_file_name, log_file_name, sizeof(linfo->log_file_name)-1);
1309
1936
  linfo->pos = my_b_tell(&log_file);
1327
1954
    0   ok
1328
1955
*/
1329
1956
 
 
1957
#ifdef HAVE_REPLICATION
 
1958
 
1330
1959
static bool copy_up_file_and_fill(IO_CACHE *index_file, my_off_t offset)
1331
1960
{
1332
1961
  int bytes_read;
1333
1962
  my_off_t init_offset= offset;
1334
1963
  File file= index_file->file;
1335
 
  unsigned char io_buf[IO_SIZE*2];
 
1964
  uchar io_buf[IO_SIZE*2];
1336
1965
 
1337
1966
  for (;; offset+= bytes_read)
1338
1967
  {
1358
1987
  return(1);
1359
1988
}
1360
1989
 
 
1990
#endif /* HAVE_REPLICATION */
 
1991
 
1361
1992
/**
1362
1993
  Find the position in the log-index-file for the given log name.
1363
1994
 
1380
2011
    LOG_INFO_IO         Got IO error while reading file
1381
2012
*/
1382
2013
 
1383
 
int DRIZZLE_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
 
2014
int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
1384
2015
                            bool need_lock)
1385
2016
{
1386
2017
  int error= 0;
1387
2018
  char *fname= linfo->log_file_name;
1388
 
  uint32_t log_name_len= log_name ? (uint) strlen(log_name) : 0;
 
2019
  uint log_name_len= log_name ? (uint) strlen(log_name) : 0;
1389
2020
 
1390
2021
  /*
1391
2022
    Mutex needed because we need to make sure the file pointer does not
1400
2031
 
1401
2032
  for (;;)
1402
2033
  {
1403
 
    uint32_t length;
 
2034
    uint length;
1404
2035
    my_off_t offset= my_b_tell(&index_file);
1405
2036
    /* If we get 0 or 1 characters, this is the end of the file */
1406
2037
 
1453
2084
    LOG_INFO_IO         Got IO error while reading file
1454
2085
*/
1455
2086
 
1456
 
int DRIZZLE_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
 
2087
int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
1457
2088
{
1458
2089
  int error= 0;
1459
 
  uint32_t length;
 
2090
  uint length;
1460
2091
  char *fname= linfo->log_file_name;
1461
2092
 
1462
2093
  if (need_lock)
1500
2131
    1   error
1501
2132
*/
1502
2133
 
1503
 
bool DRIZZLE_BIN_LOG::reset_logs(THD* thd)
 
2134
bool MYSQL_BIN_LOG::reset_logs(THD* thd)
1504
2135
{
1505
2136
  LOG_INFO linfo;
1506
2137
  bool error=0;
1507
2138
  const char* save_name;
1508
2139
 
 
2140
  ha_reset_logs(thd);
1509
2141
  /*
1510
2142
    We need to get both locks to be sure that no one is trying to
1511
2143
    write to the index log file.
1519
2151
    thread. If the transaction involved MyISAM tables, it should go
1520
2152
    into binlog even on rollback.
1521
2153
  */
1522
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2154
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1523
2155
 
1524
2156
  /* Save variables so that we can reopen the log */
1525
2157
  save_name=name;
1528
2160
 
1529
2161
  /* First delete all old log files */
1530
2162
 
1531
 
  if (find_log_pos(&linfo, NULL, 0))
 
2163
  if (find_log_pos(&linfo, NullS, 0))
1532
2164
  {
1533
2165
    error=1;
1534
2166
    goto err;
1540
2172
    {
1541
2173
      if (my_errno == ENOENT) 
1542
2174
      {
1543
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2175
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1544
2176
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1545
2177
                            linfo.log_file_name);
1546
 
        sql_print_information(_("Failed to delete file '%s'"),
 
2178
        sql_print_information("Failed to delete file '%s'",
1547
2179
                              linfo.log_file_name);
1548
2180
        my_errno= 0;
1549
2181
        error= 0;
1550
2182
      }
1551
2183
      else
1552
2184
      {
1553
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2185
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1554
2186
                            ER_BINLOG_PURGE_FATAL_ERR,
1555
 
                            _("a problem with deleting %s; "
 
2187
                            "a problem with deleting %s; "
1556
2188
                            "consider examining correspondence "
1557
2189
                            "of your binlog index file "
1558
 
                            "to the actual binlog files"),
 
2190
                            "to the actual binlog files",
1559
2191
                            linfo.log_file_name);
1560
2192
        error= 1;
1561
2193
        goto err;
1571
2203
  {
1572
2204
    if (my_errno == ENOENT) 
1573
2205
    {
1574
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2206
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1575
2207
                          ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1576
2208
                          index_file_name);
1577
 
      sql_print_information(_("Failed to delete file '%s'"),
 
2209
      sql_print_information("Failed to delete file '%s'",
1578
2210
                            index_file_name);
1579
2211
      my_errno= 0;
1580
2212
      error= 0;
1581
2213
    }
1582
2214
    else
1583
2215
    {
1584
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2216
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1585
2217
                          ER_BINLOG_PURGE_FATAL_ERR,
1586
2218
                          "a problem with deleting %s; "
1587
2219
                          "consider examining correspondence "
1596
2228
    need_start_event=1;
1597
2229
  if (!open_index_file(index_file_name, 0))
1598
2230
    open(save_name, log_type, 0, io_cache_type, no_auto_events, max_size, 0);
1599
 
  free((unsigned char*) save_name);
 
2231
  my_free((uchar*) save_name, MYF(0));
1600
2232
 
1601
2233
err:
1602
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
2234
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1603
2235
  pthread_mutex_unlock(&LOCK_index);
1604
2236
  pthread_mutex_unlock(&LOCK_log);
1605
2237
  return(error);
1643
2275
    LOG_INFO_IO         Got IO error while reading file
1644
2276
*/
1645
2277
 
 
2278
#ifdef HAVE_REPLICATION
1646
2279
 
1647
 
int DRIZZLE_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
 
2280
int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
1648
2281
{
1649
2282
  int error;
1650
2283
 
1673
2306
    If included is true, we want the first relay log;
1674
2307
    otherwise we want the one after event_relay_log_name.
1675
2308
  */
1676
 
  if ((included && (error=find_log_pos(&rli->linfo, NULL, 0))) ||
 
2309
  if ((included && (error=find_log_pos(&rli->linfo, NullS, 0))) ||
1677
2310
      (!included &&
1678
2311
       ((error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0)) ||
1679
2312
        (error=find_next_log(&rli->linfo, 0)))))
1680
2313
  {
1681
2314
    char buff[22];
1682
 
    sql_print_error(_("next log error: %d  offset: %s  log: %s included: %d"),
 
2315
    sql_print_error("next log error: %d  offset: %s  log: %s included: %d",
1683
2316
                    error,
1684
2317
                    llstr(rli->linfo.index_file_offset,buff),
1685
2318
                    rli->group_relay_log_name,
1719
2352
  Update log index_file.
1720
2353
*/
1721
2354
 
1722
 
int DRIZZLE_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads)
 
2355
int MYSQL_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads)
1723
2356
{
1724
2357
  if (copy_up_file_and_fill(&index_file, log_info->index_file_start_offset))
1725
2358
    return LOG_INFO_IO;
1754
2387
                                stat() or my_delete()
1755
2388
*/
1756
2389
 
1757
 
int DRIZZLE_BIN_LOG::purge_logs(const char *to_log, 
 
2390
int MYSQL_BIN_LOG::purge_logs(const char *to_log, 
1758
2391
                          bool included,
1759
2392
                          bool need_mutex, 
1760
2393
                          bool need_update_threads, 
1774
2407
    File name exists in index file; delete until we find this file
1775
2408
    or a file that is used.
1776
2409
  */
1777
 
  if ((error=find_log_pos(&log_info, NULL, 0 /*no mutex*/)))
 
2410
  if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
1778
2411
    goto err;
1779
2412
  while ((strcmp(to_log,log_info.log_file_name) || (exit_loop=included)) &&
1780
2413
         !log_in_use(log_info.log_file_name))
1788
2421
          It's not fatal if we can't stat a log file that does not exist;
1789
2422
          If we could not stat, we won't delete.
1790
2423
        */     
1791
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2424
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1792
2425
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1793
2426
                            log_info.log_file_name);
1794
 
        sql_print_information(_("Failed to execute stat() on file '%s'"),
 
2427
        sql_print_information("Failed to execute stat on file '%s'",
1795
2428
                              log_info.log_file_name);
1796
2429
        my_errno= 0;
1797
2430
      }
1800
2433
        /*
1801
2434
          Other than ENOENT are fatal
1802
2435
        */
1803
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2436
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1804
2437
                            ER_BINLOG_PURGE_FATAL_ERR,
1805
 
                            _("a problem with getting info on being purged %s; "
 
2438
                            "a problem with getting info on being purged %s; "
1806
2439
                            "consider examining correspondence "
1807
2440
                            "of your binlog index file "
1808
 
                            "to the actual binlog files"),
 
2441
                            "to the actual binlog files",
1809
2442
                            log_info.log_file_name);
1810
2443
        error= LOG_INFO_FATAL;
1811
2444
        goto err;
1822
2455
      {
1823
2456
        if (my_errno == ENOENT) 
1824
2457
        {
1825
 
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2458
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1826
2459
                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1827
2460
                              log_info.log_file_name);
1828
 
          sql_print_information(_("Failed to delete file '%s'"),
 
2461
          sql_print_information("Failed to delete file '%s'",
1829
2462
                                log_info.log_file_name);
1830
2463
          my_errno= 0;
1831
2464
        }
1832
2465
        else
1833
2466
        {
1834
 
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2467
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1835
2468
                              ER_BINLOG_PURGE_FATAL_ERR,
1836
 
                              _("a problem with deleting %s; "
 
2469
                              "a problem with deleting %s; "
1837
2470
                              "consider examining correspondence "
1838
2471
                              "of your binlog index file "
1839
 
                              "to the actual binlog files"),
 
2472
                              "to the actual binlog files",
1840
2473
                              log_info.log_file_name);
1841
2474
          if (my_errno == EMFILE)
1842
2475
          {
1848
2481
      }
1849
2482
    }
1850
2483
 
 
2484
    ha_binlog_index_purge_file(current_thd, log_info.log_file_name);
 
2485
 
1851
2486
    if (find_next_log(&log_info, 0) || exit_loop)
1852
2487
      break;
1853
2488
  }
1886
2521
                                stat() or my_delete()
1887
2522
*/
1888
2523
 
1889
 
int DRIZZLE_BIN_LOG::purge_logs_before_date(time_t purge_time)
 
2524
int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time)
1890
2525
{
1891
2526
  int error;
1892
2527
  LOG_INFO log_info;
1899
2534
    or a file that is used or a file
1900
2535
    that is older than purge_time.
1901
2536
  */
1902
 
  if ((error=find_log_pos(&log_info, NULL, 0 /*no mutex*/)))
 
2537
  if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
1903
2538
    goto err;
1904
2539
 
1905
2540
  while (strcmp(log_file_name, log_info.log_file_name) &&
1912
2547
        /*
1913
2548
          It's not fatal if we can't stat a log file that does not exist.
1914
2549
        */     
1915
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2550
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1916
2551
                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1917
2552
                            log_info.log_file_name);
1918
 
        sql_print_information(_("Failed to execute stat() on file '%s'"),
 
2553
        sql_print_information("Failed to execute stat on file '%s'",
1919
2554
                              log_info.log_file_name);
1920
2555
        my_errno= 0;
1921
2556
      }
1924
2559
        /*
1925
2560
          Other than ENOENT are fatal
1926
2561
        */
1927
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2562
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1928
2563
                            ER_BINLOG_PURGE_FATAL_ERR,
1929
 
                            _("a problem with getting info on being purged %s; "
 
2564
                            "a problem with getting info on being purged %s; "
1930
2565
                            "consider examining correspondence "
1931
2566
                            "of your binlog index file "
1932
 
                            "to the actual binlog files"),
 
2567
                            "to the actual binlog files",
1933
2568
                            log_info.log_file_name);
1934
2569
        error= LOG_INFO_FATAL;
1935
2570
        goto err;
1944
2579
        if (my_errno == ENOENT) 
1945
2580
        {
1946
2581
          /* It's not fatal even if we can't delete a log file */
1947
 
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2582
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1948
2583
                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
1949
2584
                              log_info.log_file_name);
1950
 
          sql_print_information(_("Failed to delete file '%s'"),
 
2585
          sql_print_information("Failed to delete file '%s'",
1951
2586
                                log_info.log_file_name);
1952
2587
          my_errno= 0;
1953
2588
        }
1954
2589
        else
1955
2590
        {
1956
 
          push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
2591
          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
1957
2592
                              ER_BINLOG_PURGE_FATAL_ERR,
1958
 
                              _("a problem with deleting %s; "
 
2593
                              "a problem with deleting %s; "
1959
2594
                              "consider examining correspondence "
1960
2595
                              "of your binlog index file "
1961
 
                              "to the actual binlog files"),
 
2596
                              "to the actual binlog files",
1962
2597
                              log_info.log_file_name);
1963
2598
          error= LOG_INFO_FATAL;
1964
2599
          goto err;
1965
2600
        }
1966
2601
      }
 
2602
      ha_binlog_index_purge_file(current_thd, log_info.log_file_name);
1967
2603
    }
1968
2604
    if (find_next_log(&log_info, 0))
1969
2605
      break;
1979
2615
  pthread_mutex_unlock(&LOCK_index);
1980
2616
  return(error);
1981
2617
}
 
2618
#endif /* HAVE_REPLICATION */
1982
2619
 
1983
2620
 
1984
2621
/**
1990
2627
    If file name will be longer then FN_REFLEN it will be truncated
1991
2628
*/
1992
2629
 
1993
 
void DRIZZLE_BIN_LOG::make_log_name(char* buf, const char* log_ident)
 
2630
void MYSQL_BIN_LOG::make_log_name(char* buf, const char* log_ident)
1994
2631
{
1995
 
  uint32_t dir_len = dirname_length(log_file_name); 
 
2632
  uint dir_len = dirname_length(log_file_name); 
1996
2633
  if (dir_len >= FN_REFLEN)
1997
2634
    dir_len=FN_REFLEN-1;
1998
 
  my_stpncpy(buf, log_file_name, dir_len);
 
2635
  strnmov(buf, log_file_name, dir_len);
1999
2636
  strmake(buf+dir_len, log_ident, FN_REFLEN - dir_len -1);
2000
2637
}
2001
2638
 
2004
2641
  Check if we are writing/reading to the given log file.
2005
2642
*/
2006
2643
 
2007
 
bool DRIZZLE_BIN_LOG::is_active(const char *log_file_name_arg)
 
2644
bool MYSQL_BIN_LOG::is_active(const char *log_file_name_arg)
2008
2645
{
2009
2646
  return !strcmp(log_file_name, log_file_name_arg);
2010
2647
}
2018
2655
  method).
2019
2656
*/
2020
2657
 
2021
 
void DRIZZLE_BIN_LOG::new_file()
 
2658
void MYSQL_BIN_LOG::new_file()
2022
2659
{
2023
2660
  new_file_impl(1);
2024
2661
}
2025
2662
 
2026
2663
 
2027
 
void DRIZZLE_BIN_LOG::new_file_without_locking()
 
2664
void MYSQL_BIN_LOG::new_file_without_locking()
2028
2665
{
2029
2666
  new_file_impl(0);
2030
2667
}
2039
2676
    The new file name is stored last in the index file
2040
2677
*/
2041
2678
 
2042
 
void DRIZZLE_BIN_LOG::new_file_impl(bool need_lock)
 
2679
void MYSQL_BIN_LOG::new_file_impl(bool need_lock)
2043
2680
{
2044
2681
  char new_name[FN_REFLEN], *new_name_ptr, *old_name;
2045
2682
 
2125
2762
 
2126
2763
  open(old_name, log_type, new_name_ptr,
2127
2764
       io_cache_type, no_auto_events, max_size, 1);
2128
 
  free(old_name);
 
2765
  my_free(old_name,MYF(0));
2129
2766
 
2130
2767
end:
2131
2768
  if (need_lock)
2136
2773
}
2137
2774
 
2138
2775
 
2139
 
bool DRIZZLE_BIN_LOG::append(Log_event* ev)
 
2776
bool MYSQL_BIN_LOG::append(Log_event* ev)
2140
2777
{
2141
2778
  bool error = 0;
2142
2779
  pthread_mutex_lock(&LOCK_log);
2162
2799
}
2163
2800
 
2164
2801
 
2165
 
bool DRIZZLE_BIN_LOG::appendv(const char* buf, uint32_t len,...)
 
2802
bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
2166
2803
{
2167
2804
  bool error= 0;
2168
2805
  va_list(args);
2173
2810
  safe_mutex_assert_owner(&LOCK_log);
2174
2811
  do
2175
2812
  {
2176
 
    if (my_b_append(&log_file,(unsigned char*) buf,len))
 
2813
    if (my_b_append(&log_file,(uchar*) buf,len))
2177
2814
    {
2178
2815
      error= 1;
2179
2816
      goto err;
2190
2827
}
2191
2828
 
2192
2829
 
2193
 
bool DRIZZLE_BIN_LOG::flush_and_sync()
 
2830
bool MYSQL_BIN_LOG::flush_and_sync()
2194
2831
{
2195
2832
  int err=0, fd=log_file.file;
2196
2833
  safe_mutex_assert_owner(&LOCK_log);
2204
2841
  return err;
2205
2842
}
2206
2843
 
2207
 
void DRIZZLE_BIN_LOG::start_union_events(THD *thd, query_id_t query_id_param)
 
2844
void MYSQL_BIN_LOG::start_union_events(THD *thd, query_id_t query_id_param)
2208
2845
{
2209
2846
  assert(!thd->binlog_evt_union.do_union);
2210
2847
  thd->binlog_evt_union.do_union= true;
2213
2850
  thd->binlog_evt_union.first_query_id= query_id_param;
2214
2851
}
2215
2852
 
2216
 
void DRIZZLE_BIN_LOG::stop_union_events(THD *thd)
 
2853
void MYSQL_BIN_LOG::stop_union_events(THD *thd)
2217
2854
{
2218
2855
  assert(thd->binlog_evt_union.do_union);
2219
2856
  thd->binlog_evt_union.do_union= false;
2220
2857
}
2221
2858
 
2222
 
bool DRIZZLE_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
 
2859
bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
2223
2860
{
2224
2861
  return (thd->binlog_evt_union.do_union && 
2225
2862
          query_id_param >= thd->binlog_evt_union.first_query_id);
2244
2881
      open_cached_file(&trx_data->trans_log, mysql_tmpdir,
2245
2882
                       LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
2246
2883
  {
2247
 
    free((unsigned char*)trx_data);
 
2884
    my_free((uchar*)trx_data, MYF(MY_ALLOW_ZERO_PTR));
2248
2885
    return(1);                      // Didn't manage to set it up
2249
2886
  }
2250
2887
  thd_set_ha_data(this, binlog_hton, trx_data);
2329
2966
  Write a table map to the binary log.
2330
2967
 */
2331
2968
 
2332
 
int THD::binlog_write_table_map(Table *table, bool is_trans)
 
2969
int THD::binlog_write_table_map(TABLE *table, bool is_trans)
2333
2970
{
2334
2971
  int error;
2335
2972
 
2336
2973
  /* Pre-conditions */
2337
2974
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2338
 
  assert(table->s->table_map_id != UINT32_MAX);
 
2975
  assert(table->s->table_map_id != ULONG_MAX);
2339
2976
 
2340
2977
  Table_map_log_event::flag_set const
2341
2978
    flags= Table_map_log_event::TM_NO_FLAGS;
2388
3025
  event.
2389
3026
*/
2390
3027
int
2391
 
DRIZZLE_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
 
3028
MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
2392
3029
                                                Rows_log_event* event)
2393
3030
{
2394
3031
  assert(mysql_bin_log.is_open());
2470
3107
  Write an event to the binary log.
2471
3108
*/
2472
3109
 
2473
 
bool DRIZZLE_BIN_LOG::write(Log_event *event_info)
 
3110
bool MYSQL_BIN_LOG::write(Log_event *event_info)
2474
3111
{
2475
3112
  THD *thd= event_info->thd;
2476
3113
  bool error= 1;
2518
3155
    if ((thd && !(thd->options & OPTION_BIN_LOG)) ||
2519
3156
        (!binlog_filter->db_ok(local_db)))
2520
3157
    {
2521
 
      pthread_mutex_unlock(&LOCK_log);
 
3158
      VOID(pthread_mutex_unlock(&LOCK_log));
2522
3159
      return(0);
2523
3160
    }
2524
3161
 
2574
3211
      {
2575
3212
        if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
2576
3213
        {
2577
 
          Intvar_log_event e(thd,(unsigned char) LAST_INSERT_ID_EVENT,
 
3214
          Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
2578
3215
                             thd->first_successful_insert_id_in_prev_stmt_for_binlog);
2579
3216
          if (e.write(file))
2580
3217
            goto err;
2586
3223
            MyISAM or BDB) (table->next_number_keypart != 0), such event is
2587
3224
            in fact not necessary. We could avoid logging it.
2588
3225
          */
2589
 
          Intvar_log_event e(thd, (unsigned char) INSERT_ID_EVENT,
 
3226
          Intvar_log_event e(thd, (uchar) INSERT_ID_EVENT,
2590
3227
                             thd->auto_inc_intervals_in_cur_stmt_for_binlog.
2591
3228
                             minimum());
2592
3229
          if (e.write(file))
2600
3237
        }
2601
3238
        if (thd->user_var_events.elements)
2602
3239
        {
2603
 
          for (uint32_t i= 0; i < thd->user_var_events.elements; i++)
 
3240
          for (uint i= 0; i < thd->user_var_events.elements; i++)
2604
3241
          {
2605
3242
            BINLOG_USER_VAR_EVENT *user_var_event;
2606
 
            get_dynamic(&thd->user_var_events,(unsigned char*) &user_var_event, i);
 
3243
            get_dynamic(&thd->user_var_events,(uchar*) &user_var_event, i);
2607
3244
            User_var_log_event e(thd, user_var_event->user_var_event->name.str,
2608
3245
                                 user_var_event->user_var_event->name.length,
2609
3246
                                 user_var_event->value,
2658
3295
  return logger.error_log_print(level, format, args);
2659
3296
}
2660
3297
 
2661
 
void DRIZZLE_BIN_LOG::rotate_and_purge(uint32_t flags)
 
3298
 
 
3299
bool slow_log_print(THD *thd, const char *query, uint query_length,
 
3300
                    uint64_t current_utime)
 
3301
{
 
3302
  return logger.slow_log_print(thd, query, query_length, current_utime);
 
3303
}
 
3304
 
 
3305
 
 
3306
bool LOGGER::log_command(THD *thd, enum enum_server_command command)
 
3307
{
 
3308
  /*
 
3309
    Log command if we have at least one log event handler enabled and want
 
3310
    to log this king of commands
 
3311
  */
 
3312
  if (*general_log_handler_list && (what_to_log & (1L << (uint) command)))
 
3313
  {
 
3314
    if (thd->options & OPTION_LOG_OFF)
 
3315
    {
 
3316
      /* No logging */
 
3317
      return false;
 
3318
    }
 
3319
 
 
3320
    return true;
 
3321
  }
 
3322
 
 
3323
  return false;
 
3324
}
 
3325
 
 
3326
 
 
3327
bool general_log_print(THD *thd, enum enum_server_command command,
 
3328
                       const char *format, ...)
 
3329
{
 
3330
  va_list args;
 
3331
  uint error= 0;
 
3332
 
 
3333
  /* Print the message to the buffer if we want to log this king of commands */
 
3334
  if (! logger.log_command(thd, command))
 
3335
    return false;
 
3336
 
 
3337
  va_start(args, format);
 
3338
  error= logger.general_log_print(thd, command, format, args);
 
3339
  va_end(args);
 
3340
 
 
3341
  return error;
 
3342
}
 
3343
 
 
3344
bool general_log_write(THD *thd, enum enum_server_command command,
 
3345
                       const char *query, uint query_length)
 
3346
{
 
3347
  /* Write the message to the log if we want to log this king of commands */
 
3348
  if (logger.log_command(thd, command))
 
3349
    return logger.general_log_write(thd, command, query, query_length);
 
3350
 
 
3351
  return false;
 
3352
}
 
3353
 
 
3354
void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
2662
3355
{
2663
3356
  if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
2664
3357
    pthread_mutex_lock(&LOCK_log);
2666
3359
      (my_b_tell(&log_file) >= (my_off_t) max_size))
2667
3360
  {
2668
3361
    new_file_without_locking();
 
3362
#ifdef HAVE_REPLICATION
2669
3363
    if (expire_logs_days)
2670
3364
    {
2671
3365
      time_t purge_time= my_time(0) - expire_logs_days*24*60*60;
2672
3366
      if (purge_time >= 0)
2673
3367
        purge_logs_before_date(purge_time);
2674
3368
    }
 
3369
#endif
2675
3370
  }
2676
3371
  if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
2677
3372
    pthread_mutex_unlock(&LOCK_log);
2678
3373
}
2679
3374
 
2680
 
uint32_t DRIZZLE_BIN_LOG::next_file_id()
 
3375
uint MYSQL_BIN_LOG::next_file_id()
2681
3376
{
2682
 
  uint32_t res;
 
3377
  uint res;
2683
3378
  pthread_mutex_lock(&LOCK_log);
2684
3379
  res = file_id++;
2685
3380
  pthread_mutex_unlock(&LOCK_log);
2701
3396
    be reset as a READ_CACHE to be able to read the contents from it.
2702
3397
 */
2703
3398
 
2704
 
int DRIZZLE_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
 
3399
int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
2705
3400
{
2706
3401
  Mutex_sentry sentry(lock_log ? &LOCK_log : NULL);
2707
3402
 
2708
3403
  if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0))
2709
3404
    return ER_ERROR_ON_WRITE;
2710
 
  uint32_t length= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
 
3405
  uint length= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
2711
3406
  long val;
2712
 
  unsigned char header[LOG_EVENT_HEADER_LEN];
 
3407
  uchar header[LOG_EVENT_HEADER_LEN];
2713
3408
 
2714
3409
  /*
2715
3410
    The events in the buffer have incorrect end_log_pos data
2740
3435
      assert(carry < LOG_EVENT_HEADER_LEN);
2741
3436
 
2742
3437
      /* assemble both halves */
2743
 
      memcpy(&header[carry], cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
 
3438
      memcpy(&header[carry], (char *)cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
2744
3439
 
2745
3440
      /* fix end_log_pos */
2746
3441
      val= uint4korr(&header[LOG_POS_OFFSET]) + group;
2754
3449
        copy fixed second half of header to cache so the correct
2755
3450
        version will be written later.
2756
3451
      */
2757
 
      memcpy(cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
 
3452
      memcpy((char *)cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
2758
3453
 
2759
3454
      /* next event header at ... */
2760
3455
      hdr_offs = uint4korr(&header[EVENT_LEN_OFFSET]) - carry;
2783
3478
        if (hdr_offs + LOG_EVENT_HEADER_LEN > length)
2784
3479
        {
2785
3480
          carry= length - hdr_offs;
2786
 
          memcpy(header, cache->read_pos + hdr_offs, carry);
 
3481
          memcpy(header, (char *)cache->read_pos + hdr_offs, carry);
2787
3482
          length= hdr_offs;
2788
3483
        }
2789
3484
        else
2790
3485
        {
2791
3486
          /* we've got a full event-header, and it came in one piece */
2792
3487
 
2793
 
          unsigned char *log_pos= (unsigned char *)cache->read_pos + hdr_offs + LOG_POS_OFFSET;
 
3488
          uchar *log_pos= (uchar *)cache->read_pos + hdr_offs + LOG_POS_OFFSET;
2794
3489
 
2795
3490
          /* fix end_log_pos */
2796
3491
          val= uint4korr(log_pos) + group;
2797
3492
          int4store(log_pos, val);
2798
3493
 
2799
3494
          /* next event header at ... */
2800
 
          log_pos= (unsigned char *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET;
 
3495
          log_pos= (uchar *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET;
2801
3496
          hdr_offs += uint4korr(log_pos);
2802
3497
 
2803
3498
        }
2849
3544
    'cache' needs to be reinitialized after this functions returns.
2850
3545
*/
2851
3546
 
2852
 
bool DRIZZLE_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
 
3547
bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
2853
3548
{
2854
 
  pthread_mutex_lock(&LOCK_log);
 
3549
  VOID(pthread_mutex_lock(&LOCK_log));
2855
3550
 
2856
3551
  /* NULL would represent nothing to replicate after ROLLBACK */
2857
3552
  assert(commit_event != NULL);
2927
3622
    else
2928
3623
      rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
2929
3624
  }
2930
 
  pthread_mutex_unlock(&LOCK_log);
 
3625
  VOID(pthread_mutex_unlock(&LOCK_log));
2931
3626
 
2932
3627
  return(0);
2933
3628
 
2937
3632
    write_error= 1;
2938
3633
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
2939
3634
  }
2940
 
  pthread_mutex_unlock(&LOCK_log);
 
3635
  VOID(pthread_mutex_unlock(&LOCK_log));
2941
3636
  return(1);
2942
3637
}
2943
3638
 
2951
3646
    It will be released at the end of the function.
2952
3647
*/
2953
3648
 
2954
 
void DRIZZLE_BIN_LOG::wait_for_update_relay_log(THD* thd)
 
3649
void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
2955
3650
{
2956
3651
  const char *old_msg;
2957
3652
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
2980
3675
    LOCK_log is released by the caller.
2981
3676
*/
2982
3677
 
2983
 
int DRIZZLE_BIN_LOG::wait_for_update_bin_log(THD* thd,
 
3678
int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd,
2984
3679
                                           const struct timespec *timeout)
2985
3680
{
2986
3681
  int ret= 0;
2987
 
  const char* old_msg = thd->get_proc_info();
 
3682
  const char* old_msg = thd->proc_info;
2988
3683
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
2989
3684
                           "Master has sent all binlog to slave; "
2990
3685
                           "waiting for binlog to be updated");
3011
3706
    The internal structures are not freed until cleanup() is called
3012
3707
*/
3013
3708
 
3014
 
void DRIZZLE_BIN_LOG::close(uint32_t exiting)
 
3709
void MYSQL_BIN_LOG::close(uint exiting)
3015
3710
{                                       // One can't set log_type here!
3016
3711
  if (log_state == LOG_OPENED)
3017
3712
  {
 
3713
#ifdef HAVE_REPLICATION
3018
3714
    if (log_type == LOG_BIN && !no_auto_events &&
3019
3715
        (exiting & LOG_CLOSE_STOP_EVENT))
3020
3716
    {
3023
3719
      bytes_written+= s.data_written;
3024
3720
      signal_update();
3025
3721
    }
 
3722
#endif /* HAVE_REPLICATION */
3026
3723
 
3027
3724
    /* don't pwrite in a file opened with O_APPEND - it doesn't work */
3028
3725
    if (log_file.type == WRITE_CACHE && log_type == LOG_BIN)
3029
3726
    {
3030
3727
      my_off_t offset= BIN_LOG_HEADER_SIZE + FLAGS_OFFSET;
3031
 
      unsigned char flags= 0;            // clearing LOG_EVENT_BINLOG_IN_USE_F
 
3728
      uchar flags= 0;            // clearing LOG_EVENT_BINLOG_IN_USE_F
3032
3729
      pwrite(log_file.file, &flags, 1, offset);
3033
3730
    }
3034
3731
 
3035
3732
    /* this will cleanup IO_CACHE, sync and close the file */
3036
 
    DRIZZLE_LOG::close(exiting);
 
3733
    MYSQL_LOG::close(exiting);
3037
3734
  }
3038
3735
 
3039
3736
  /*
3051
3748
    }
3052
3749
  }
3053
3750
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
3054
 
  if (name)
3055
 
  {
3056
 
    free(name);
3057
 
    name= NULL;
3058
 
  }
 
3751
  safeFree(name);
3059
3752
  return;
3060
3753
}
3061
3754
 
3062
3755
 
3063
 
void DRIZZLE_BIN_LOG::set_max_size(ulong max_size_arg)
 
3756
void MYSQL_BIN_LOG::set_max_size(ulong max_size_arg)
3064
3757
{
3065
3758
  /*
3066
3759
    We need to take locks, otherwise this may happen:
3128
3821
 
3129
3822
void sql_perror(const char *message)
3130
3823
{
 
3824
#ifdef HAVE_STRERROR
3131
3825
  sql_print_error("%s: %s",message, strerror(errno));
 
3826
#else
 
3827
  perror(message);
 
3828
#endif
3132
3829
}
3133
3830
 
3134
3831
 
3139
3836
  {
3140
3837
    char err_renamed[FN_REFLEN], *end;
3141
3838
    end= strmake(err_renamed,log_error_file,FN_REFLEN-4);
3142
 
    my_stpcpy(end, "-old");
3143
 
    pthread_mutex_lock(&LOCK_error_log);
 
3839
    strmov(end, "-old");
 
3840
    VOID(pthread_mutex_lock(&LOCK_error_log));
3144
3841
    char err_temp[FN_REFLEN+4];
3145
3842
    /*
3146
3843
     On Windows is necessary a temporary file for to rename
3147
3844
     the current error file.
3148
3845
    */
3149
 
    strxmov(err_temp, err_renamed,"-tmp",NULL);
 
3846
    strxmov(err_temp, err_renamed,"-tmp",NullS);
3150
3847
    (void) my_delete(err_temp, MYF(0)); 
3151
3848
    if (freopen(err_temp,"a+",stdout))
3152
3849
    {
3153
3850
      int fd;
3154
3851
      size_t bytes;
3155
 
      unsigned char buf[IO_SIZE];
 
3852
      uchar buf[IO_SIZE];
3156
3853
 
3157
3854
      freopen(err_temp,"a+",stderr);
3158
3855
      (void) my_delete(err_renamed, MYF(0));
3171
3868
    }
3172
3869
    else
3173
3870
     result= 1;
3174
 
    pthread_mutex_unlock(&LOCK_error_log);
 
3871
    VOID(pthread_mutex_unlock(&LOCK_error_log));
3175
3872
  }
3176
3873
   return result;
3177
3874
}
3178
3875
 
3179
 
void DRIZZLE_BIN_LOG::signal_update()
 
3876
void MYSQL_BIN_LOG::signal_update()
3180
3877
{
3181
3878
  pthread_cond_broadcast(&update_cond);
3182
3879
  return;
3199
3896
    return an error (e.g. logging to the log tables)
3200
3897
*/
3201
3898
static void print_buffer_to_file(enum loglevel level,
3202
 
                                 int error_code __attribute__((unused)),
 
3899
                                 int error_code __attribute__((__unused__)),
3203
3900
                                 const char *buffer,
3204
 
                                 size_t buffer_length __attribute__((unused)))
 
3901
                                 size_t buffer_length __attribute__((__unused__)))
3205
3902
{
3206
3903
  time_t skr;
3207
3904
  struct tm tm_tmp;
3208
3905
  struct tm *start;
3209
3906
 
3210
 
  pthread_mutex_lock(&LOCK_error_log);
 
3907
  VOID(pthread_mutex_lock(&LOCK_error_log));
3211
3908
 
3212
3909
  skr= my_time(0);
3213
3910
  localtime_r(&skr, &tm_tmp);
3226
3923
 
3227
3924
  fflush(stderr);
3228
3925
 
3229
 
  pthread_mutex_unlock(&LOCK_error_log);
 
3926
  VOID(pthread_mutex_unlock(&LOCK_error_log));
3230
3927
  return;
3231
3928
}
3232
3929
 
3332
4029
 
3333
4030
int TC_LOG_MMAP::open(const char *opt_name)
3334
4031
{
3335
 
  uint32_t i;
 
4032
  uint i;
3336
4033
  bool crashed= false;
3337
4034
  PAGE *pg;
3338
4035
 
3339
4036
  assert(total_ha_2pc > 1);
3340
4037
  assert(opt_name && opt_name[0]);
3341
4038
 
3342
 
  tc_log_page_size= getpagesize();
 
4039
  tc_log_page_size= my_getpagesize();
3343
4040
  assert(TC_LOG_PAGE_SIZE % tc_log_page_size == 0);
3344
4041
 
3345
4042
  fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME);
3360
4057
  {
3361
4058
    inited= 1;
3362
4059
    crashed= true;
3363
 
    sql_print_information(_("Recovering after a crash using %s"), opt_name);
 
4060
    sql_print_information("Recovering after a crash using %s", opt_name);
3364
4061
    if (tc_heuristic_recover)
3365
4062
    {
3366
 
      sql_print_error(_("Cannot perform automatic crash recovery when "
3367
 
                      "--tc-heuristic-recover is used"));
 
4063
      sql_print_error("Cannot perform automatic crash recovery when "
 
4064
                      "--tc-heuristic-recover is used");
3368
4065
      goto err;
3369
4066
    }
3370
4067
    file_length= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE));
3372
4069
      goto err;
3373
4070
  }
3374
4071
 
3375
 
  data= (unsigned char *)my_mmap(0, (size_t)file_length, PROT_READ|PROT_WRITE,
 
4072
  data= (uchar *)my_mmap(0, (size_t)file_length, PROT_READ|PROT_WRITE,
3376
4073
                        MAP_NOSYNC|MAP_SHARED, fd, 0);
3377
4074
  if (data == MAP_FAILED)
3378
4075
  {
3408
4105
      goto err;
3409
4106
 
3410
4107
  memcpy(data, tc_log_magic, sizeof(tc_log_magic));
3411
 
  data[sizeof(tc_log_magic)]= (unsigned char)total_ha_2pc;
 
4108
  data[sizeof(tc_log_magic)]= (uchar)total_ha_2pc;
3412
4109
  msync(data, tc_log_page_size, MS_SYNC);
3413
4110
  my_sync(fd, MYF(0));
3414
4111
  inited=5;
3516
4213
    threads waiting for a page, but then all these threads will be waiting
3517
4214
    for a fsync() anyway
3518
4215
 
3519
 
   If tc_log == DRIZZLE_LOG then tc_log writes transaction to binlog and
 
4216
   If tc_log == MYSQL_LOG then tc_log writes transaction to binlog and
3520
4217
   records XID in a special Xid_log_event.
3521
4218
   If tc_log = TC_LOG_MMAP then xid is written in a special memory-mapped
3522
4219
   log.
3530
4227
    to the position in memory where xid was logged to.
3531
4228
*/
3532
4229
 
3533
 
int TC_LOG_MMAP::log_xid(THD *thd __attribute__((unused)), my_xid xid)
 
4230
int TC_LOG_MMAP::log_xid(THD *thd __attribute__((__unused__)), my_xid xid)
3534
4231
{
3535
4232
  int err;
3536
4233
  PAGE *p;
3563
4260
  }
3564
4261
 
3565
4262
  /* found! store xid there and mark the page dirty */
3566
 
  cookie= (ulong)((unsigned char *)p->ptr - data);      // can never be zero
 
4263
  cookie= (ulong)((uchar *)p->ptr - data);      // can never be zero
3567
4264
  *p->ptr++= xid;
3568
4265
  p->free--;
3569
4266
  p->state= DIRTY;
3642
4339
  cookie points directly to the memory where xid was logged.
3643
4340
*/
3644
4341
 
3645
 
void TC_LOG_MMAP::unlog(ulong cookie, my_xid xid __attribute__((unused)))
 
4342
void TC_LOG_MMAP::unlog(ulong cookie, my_xid xid __attribute__((__unused__)))
3646
4343
{
3647
4344
  PAGE *p=pages+(cookie/tc_log_page_size);
3648
4345
  my_xid *x=(my_xid *)(data+cookie);
3664
4361
 
3665
4362
void TC_LOG_MMAP::close()
3666
4363
{
3667
 
  uint32_t i;
 
4364
  uint i;
3668
4365
  switch (inited) {
3669
4366
  case 6:
3670
4367
    pthread_mutex_destroy(&LOCK_sync);
3682
4379
      pthread_cond_destroy(&pages[i].cond);
3683
4380
    }
3684
4381
  case 3:
3685
 
    free((unsigned char*)pages);
 
4382
    my_free((uchar*)pages, MYF(0));
3686
4383
  case 2:
3687
4384
    my_munmap((char*)data, (size_t)file_length);
3688
4385
  case 1:
3700
4397
 
3701
4398
  if (memcmp(data, tc_log_magic, sizeof(tc_log_magic)))
3702
4399
  {
3703
 
    sql_print_error(_("Bad magic header in tc log"));
 
4400
    sql_print_error("Bad magic header in tc log");
3704
4401
    goto err1;
3705
4402
  }
3706
4403
 
3710
4407
  */
3711
4408
  if (data[sizeof(tc_log_magic)] != total_ha_2pc)
3712
4409
  {
3713
 
    sql_print_error(_("Recovery failed! You must enable "
 
4410
    sql_print_error("Recovery failed! You must enable "
3714
4411
                    "exactly %d storage engines that support "
3715
 
                    "two-phase commit protocol"),
 
4412
                    "two-phase commit protocol",
3716
4413
                    data[sizeof(tc_log_magic)]);
3717
4414
    goto err1;
3718
4415
  }
3724
4421
  for ( ; p < end_p ; p++)
3725
4422
  {
3726
4423
    for (my_xid *x=p->start; x < p->end; x++)
3727
 
      if (*x && my_hash_insert(&xids, (unsigned char *)x))
 
4424
      if (*x && my_hash_insert(&xids, (uchar *)x))
3728
4425
        goto err2; // OOM
3729
4426
  }
3730
4427
 
3732
4429
    goto err2;
3733
4430
 
3734
4431
  hash_free(&xids);
3735
 
  memset(data, 0, (size_t)file_length);
 
4432
  bzero(data, (size_t)file_length);
3736
4433
  return 0;
3737
4434
 
3738
4435
err2:
3739
4436
  hash_free(&xids);
3740
4437
err1:
3741
 
  sql_print_error(_("Crash recovery failed. Either correct the problem "
 
4438
  sql_print_error("Crash recovery failed. Either correct the problem "
3742
4439
                  "(if it's, for example, out of memory error) and restart, "
3743
 
                  "or delete tc log and start drizzled with "
3744
 
                  "--tc-heuristic-recover={commit|rollback}"));
 
4440
                  "or delete tc log and start mysqld with "
 
4441
                  "--tc-heuristic-recover={commit|rollback}");
3745
4442
  return 1;
3746
4443
}
3747
4444
#endif
3768
4465
  if (!tc_heuristic_recover)
3769
4466
    return 0;
3770
4467
 
3771
 
  sql_print_information(_("Heuristic crash recovery mode"));
 
4468
  sql_print_information("Heuristic crash recovery mode");
3772
4469
  if (ha_recover(0))
3773
 
    sql_print_error(_("Heuristic crash recovery failed"));
3774
 
  sql_print_information(_("Please restart mysqld without --tc-heuristic-recover"));
 
4470
    sql_print_error("Heuristic crash recovery failed");
 
4471
  sql_print_information("Please restart mysqld without --tc-heuristic-recover");
3775
4472
  return 1;
3776
4473
}
3777
4474
 
3778
4475
/****** transaction coordinator log for 2pc - binlog() based solution ******/
3779
 
#define TC_LOG_BINLOG DRIZZLE_BIN_LOG
 
4476
#define TC_LOG_BINLOG MYSQL_BIN_LOG
3780
4477
 
3781
4478
/**
3782
4479
  @todo
3812
4509
    return 1;
3813
4510
  }
3814
4511
 
3815
 
  if ((error= find_log_pos(&log_info, NULL, 1)))
 
4512
  if ((error= find_log_pos(&log_info, NullS, 1)))
3816
4513
  {
3817
4514
    if (error != LOG_INFO_EOF)
3818
 
      sql_print_error(_("find_log_pos() failed (error: %d)"), error);
 
4515
      sql_print_error("find_log_pos() failed (error: %d)", error);
3819
4516
    else
3820
4517
      error= 0;
3821
4518
    goto err;
3839
4536
 
3840
4537
    if (error !=  LOG_INFO_EOF)
3841
4538
    {
3842
 
      sql_print_error(_("find_log_pos() failed (error: %d)"), error);
 
4539
      sql_print_error("find_log_pos() failed (error: %d)", error);
3843
4540
      goto err;
3844
4541
    }
3845
4542
 
3853
4550
        ev->get_type_code() == FORMAT_DESCRIPTION_EVENT &&
3854
4551
        ev->flags & LOG_EVENT_BINLOG_IN_USE_F)
3855
4552
    {
3856
 
      sql_print_information(_("Recovering after a crash using %s"), opt_name);
 
4553
      sql_print_information("Recovering after a crash using %s", opt_name);
3857
4554
      error= recover(&log, (Format_description_log_event *)ev);
3858
4555
    }
3859
4556
    else
3900
4597
  return(!binlog_end_trans(thd, trx_data, &xle, true));
3901
4598
}
3902
4599
 
3903
 
void TC_LOG_BINLOG::unlog(ulong cookie __attribute__((unused)),
3904
 
                          my_xid xid __attribute__((unused)))
 
4600
void TC_LOG_BINLOG::unlog(ulong cookie __attribute__((__unused__)),
 
4601
                          my_xid xid __attribute__((__unused__)))
3905
4602
{
3906
4603
  pthread_mutex_lock(&LOCK_prep_xids);
3907
4604
  assert(prepared_xids > 0);
3932
4629
    if (ev->get_type_code() == XID_EVENT)
3933
4630
    {
3934
4631
      Xid_log_event *xev=(Xid_log_event *)ev;
3935
 
      unsigned char *x= (unsigned char *) memdup_root(&mem_root, (unsigned char*) &xev->xid,
 
4632
      uchar *x= (uchar *) memdup_root(&mem_root, (uchar*) &xev->xid,
3936
4633
                                      sizeof(xev->xid));
3937
4634
      if (! x)
3938
4635
        goto err2;
3952
4649
  free_root(&mem_root, MYF(0));
3953
4650
  hash_free(&xids);
3954
4651
err1:
3955
 
  sql_print_error(_("Crash recovery failed. Either correct the problem "
 
4652
  sql_print_error("Crash recovery failed. Either correct the problem "
3956
4653
                  "(if it's, for example, out of memory error) and restart, "
3957
4654
                  "or delete (or rename) binary log and start mysqld with "
3958
 
                  "--tc-heuristic-recover={commit|rollback}"));
 
4655
                  "--tc-heuristic-recover={commit|rollback}");
3959
4656
  return 1;
3960
4657
}
3961
4658
 
3982
4679
#endif /* INNODB_COMPATIBILITY_HOOKS */
3983
4680
 
3984
4681
 
 
4682
struct st_mysql_storage_engine binlog_storage_engine=
 
4683
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
 
4684
 
3985
4685
mysql_declare_plugin(binlog)
3986
4686
{
3987
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
4687
  MYSQL_STORAGE_ENGINE_PLUGIN,
 
4688
  &binlog_storage_engine,
3988
4689
  "binlog",
3989
 
  "1.0",
3990
4690
  "MySQL AB",
3991
4691
  "This is a pseudo storage engine to represent the binlog in a transaction",
3992
4692
  PLUGIN_LICENSE_GPL,
3993
4693
  binlog_init, /* Plugin Init */
3994
4694
  NULL, /* Plugin Deinit */
 
4695
  0x0100 /* 1.0 */,
3995
4696
  NULL,                       /* status variables                */
3996
4697
  NULL,                       /* system variables                */
3997
4698
  NULL                        /* config options                  */