~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/log.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
                                       THD * /* thd */)
90
90
{
91
91
  strmake(m_message, message_arg, sizeof(m_message)-1);
92
 
  return TRUE;
 
92
  return true;
93
93
}
94
94
 
95
95
 
130
130
  {
131
131
    if (m_mutex)
132
132
      pthread_mutex_unlock(m_mutex);
133
 
#ifndef DBUG_OFF
134
133
    m_mutex= 0;
135
 
#endif
136
134
  }
137
135
 
138
136
private:
156
154
 
157
155
  ~binlog_trx_data()
158
156
  {
159
 
    DBUG_ASSERT(pending() == NULL);
 
157
    assert(pending() == NULL);
160
158
    close_cached_file(&trans_log);
161
159
  }
162
160
 
175
173
   */
176
174
  void truncate(my_off_t pos)
177
175
  {
178
 
    DBUG_PRINT("info", ("truncating to position %lu", (ulong) pos));
179
 
    DBUG_PRINT("info", ("before_stmt_pos=%lu", (ulong) pos));
180
176
    delete pending();
181
177
    set_pending(0);
182
178
    reinit_io_cache(&trans_log, WRITE_CACHE, pos, 0, 0);
310
306
    if (opt_log)
311
307
      mysql_log.open_query_log(sys_var_general_log_path.value);
312
308
 
313
 
    is_initialized= TRUE;
 
309
    is_initialized= true;
314
310
  }
315
311
 
316
 
  return FALSE;
 
312
  return false;
317
313
}
318
314
 
319
315
 
351
347
bool LOGGER::error_log_print(enum loglevel level, const char *format,
352
348
                             va_list args)
353
349
{
354
 
  bool error= FALSE;
 
350
  bool error= false;
355
351
  Log_event_handler **current_handler;
356
352
 
357
353
  /* currently we don't need locking here as there is no error_log table */
364
360
 
365
361
void LOGGER::cleanup_base()
366
362
{
367
 
  DBUG_ASSERT(inited == 1);
 
363
  assert(inited == 1);
368
364
  rwlock_destroy(&LOCK_logger);
369
365
  if (file_log_handler)
370
366
    file_log_handler->cleanup();
373
369
 
374
370
void LOGGER::cleanup_end()
375
371
{
376
 
  DBUG_ASSERT(inited == 1);
 
372
  assert(inited == 1);
377
373
  if (file_log_handler)
378
374
    delete file_log_handler;
379
375
}
385
381
*/
386
382
void LOGGER::init_base()
387
383
{
388
 
  DBUG_ASSERT(inited == 0);
 
384
  assert(inited == 0);
389
385
  inited= 1;
390
386
 
391
387
  /*
443
439
                            ulonglong current_utime)
444
440
 
445
441
{
446
 
  bool error= FALSE;
 
442
  bool error= false;
447
443
  Log_event_handler **current_handler;
448
 
  bool is_command= FALSE;
 
444
  bool is_command= false;
449
445
  char user_host_buff[MAX_USER_HOST_SIZE];
450
446
  Security_context *sctx= thd->security_ctx;
451
447
  uint user_host_len= 0;
491
487
 
492
488
    if (!query)
493
489
    {
494
 
      is_command= TRUE;
 
490
      is_command= true;
495
491
      query= command_name[thd->command].str;
496
492
      query_length= command_name[thd->command].length;
497
493
    }
510
506
bool LOGGER::general_log_write(THD *thd, enum enum_server_command command,
511
507
                               const char *query, uint query_length)
512
508
{
513
 
  bool error= FALSE;
 
509
  bool error= false;
514
510
  Log_event_handler **current_handler= general_log_handler_list;
515
511
  char user_host_buff[MAX_USER_HOST_SIZE];
516
512
  Security_context *sctx= thd->security_ctx;
582
578
    break;
583
579
    /* these two are disabled for now */
584
580
  case LOG_TABLE:
585
 
    DBUG_ASSERT(0);
 
581
    assert(0);
586
582
    break;
587
583
  case LOG_TABLE|LOG_FILE:
588
 
    DBUG_ASSERT(0);
 
584
    assert(0);
589
585
    break;
590
586
  }
591
587
}
619
615
                                  uint log_type)
620
616
{
621
617
  MYSQL_QUERY_LOG *file_log;
622
 
  bool res= FALSE;
 
618
  bool res= false;
623
619
  lock_exclusive();
624
620
  switch (log_type) {
625
621
  case QUERY_LOG_SLOW:
629
625
 
630
626
      file_log->open_slow_log(sys_var_slow_log_path.value);
631
627
      init_slow_log(log_output_options);
632
 
      opt_slow_log= TRUE;
 
628
      opt_slow_log= true;
633
629
    }
634
630
    break;
635
631
  case QUERY_LOG_GENERAL:
639
635
 
640
636
      file_log->open_query_log(sys_var_general_log_path.value);
641
637
      init_general_log(log_output_options);
642
 
      opt_log= TRUE;
 
638
      opt_log= true;
643
639
    }
644
640
    break;
645
641
  default:
646
 
    DBUG_ASSERT(0);
 
642
    assert(0);
647
643
  }
648
644
  unlock();
649
645
  return res;
674
670
 
675
671
  lock_exclusive();
676
672
  file_log->close(0);
677
 
  *tmp_opt= FALSE;
 
673
  *tmp_opt= false;
678
674
  unlock();
679
675
}
680
676
 
683
679
                         uint general_log_printer)
684
680
{
685
681
  /* error log table is not supported yet */
686
 
  DBUG_ASSERT(error_log_printer < LOG_TABLE);
 
682
  assert(error_log_printer < LOG_TABLE);
687
683
 
688
684
  lock_exclusive();
689
685
 
715
711
static void
716
712
binlog_trans_log_savepos(THD *thd, my_off_t *pos)
717
713
{
718
 
  DBUG_ENTER("binlog_trans_log_savepos");
719
 
  DBUG_ASSERT(pos != NULL);
 
714
  assert(pos != NULL);
720
715
  if (thd_get_ha_data(thd, binlog_hton) == NULL)
721
716
    thd->binlog_setup_trx_data();
722
717
  binlog_trx_data *const trx_data=
723
718
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
724
 
  DBUG_ASSERT(mysql_bin_log.is_open());
 
719
  assert(mysql_bin_log.is_open());
725
720
  *pos= trx_data->position();
726
 
  DBUG_PRINT("return", ("*pos: %lu", (ulong) *pos));
727
 
  DBUG_VOID_RETURN;
 
721
  return;
728
722
}
729
723
 
730
724
 
746
740
static void
747
741
binlog_trans_log_truncate(THD *thd, my_off_t pos)
748
742
{
749
 
  DBUG_ENTER("binlog_trans_log_truncate");
750
 
  DBUG_PRINT("enter", ("pos: %lu", (ulong) pos));
751
 
 
752
 
  DBUG_ASSERT(thd_get_ha_data(thd, binlog_hton) != NULL);
 
743
  assert(thd_get_ha_data(thd, binlog_hton) != NULL);
753
744
  /* Only true if binlog_trans_log_savepos() wasn't called before */
754
 
  DBUG_ASSERT(pos != ~(my_off_t) 0);
 
745
  assert(pos != ~(my_off_t) 0);
755
746
 
756
747
  binlog_trx_data *const trx_data=
757
748
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
758
749
  trx_data->truncate(pos);
759
 
  DBUG_VOID_RETURN;
 
750
  return;
760
751
}
761
752
 
762
753
 
787
778
{
788
779
  binlog_trx_data *const trx_data=
789
780
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
790
 
  DBUG_ASSERT(trx_data->empty());
 
781
  assert(trx_data->empty());
791
782
  thd_set_ha_data(thd, binlog_hton, NULL);
792
783
  trx_data->~binlog_trx_data();
793
784
  my_free((uchar*)trx_data, MYF(0));
821
812
binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
822
813
                 Log_event *end_ev, bool all)
823
814
{
824
 
  DBUG_ENTER("binlog_end_trans");
825
815
  int error=0;
826
816
  IO_CACHE *trans_log= &trx_data->trans_log;
827
 
  DBUG_PRINT("enter", ("transaction: %s  end_ev: 0x%lx",
828
 
                       all ? "all" : "stmt", (long) end_ev));
829
 
  DBUG_PRINT("info", ("thd->options={ %s%s}",
830
 
                      FLAGSTR(thd->options, OPTION_NOT_AUTOCOMMIT),
831
 
                      FLAGSTR(thd->options, OPTION_BEGIN)));
832
817
 
833
818
  /*
834
819
    NULL denotes ROLLBACK with nothing to replicate: i.e., rollback of
848
833
      were, we would have to ensure that we're not ending a statement
849
834
      inside a stored function.
850
835
     */
851
 
    thd->binlog_flush_pending_rows_event(TRUE);
 
836
    thd->binlog_flush_pending_rows_event(true);
852
837
 
853
838
    error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev);
854
839
    trx_data->reset();
878
863
    {
879
864
      trx_data->reset();
880
865
 
881
 
      DBUG_ASSERT(!thd->binlog_get_pending_rows_event());
 
866
      assert(!thd->binlog_get_pending_rows_event());
882
867
      thd->clear_binlog_table_maps();
883
868
    }
884
869
    else                                        // ...statement
892
877
    mysql_bin_log.update_table_map_version();
893
878
  }
894
879
 
895
 
  DBUG_RETURN(error);
 
880
  return(error);
896
881
}
897
882
 
898
883
static int binlog_prepare(handlerton *hton __attribute__((__unused__)),
926
911
static int binlog_commit(handlerton *hton __attribute__((__unused__)),
927
912
                         THD *thd, bool all)
928
913
{
929
 
  DBUG_ENTER("binlog_commit");
930
914
  binlog_trx_data *const trx_data=
931
915
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
932
916
 
934
918
  {
935
919
    // we're here because trans_log was flushed in MYSQL_BIN_LOG::log_xid()
936
920
    trx_data->reset();
937
 
    DBUG_RETURN(0);
 
921
    return(0);
938
922
  }
939
923
 
940
924
  /*
997
981
  */
998
982
  ulonglong const in_transaction=
999
983
    thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
1000
 
  DBUG_PRINT("debug",
1001
 
             ("all: %d, empty: %s, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
1002
 
              all,
1003
 
              YESNO(trx_data->empty()),
1004
 
              YESNO(in_transaction),
1005
 
              YESNO(thd->transaction.all.modified_non_trans_table),
1006
 
              YESNO(thd->transaction.stmt.modified_non_trans_table)));
1007
984
  if ((in_transaction && (all || (!trx_data->at_least_one_stmt && thd->transaction.stmt.modified_non_trans_table))) || (!in_transaction && !all))
1008
985
  {
1009
 
    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE);
 
986
    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), true, false);
1010
987
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
1011
988
    int error= binlog_end_trans(thd, trx_data, &qev, all);
1012
 
    DBUG_RETURN(error);
 
989
    return(error);
1013
990
  }
1014
 
  DBUG_RETURN(0);
 
991
  return(0);
1015
992
}
1016
993
 
1017
994
/**
1032
1009
static int binlog_rollback(handlerton *hton __attribute__((__unused__)),
1033
1010
                           THD *thd, bool all)
1034
1011
{
1035
 
  DBUG_ENTER("binlog_rollback");
1036
1012
  int error=0;
1037
1013
  binlog_trx_data *const trx_data=
1038
1014
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
1039
1015
 
1040
1016
  if (trx_data->empty()) {
1041
1017
    trx_data->reset();
1042
 
    DBUG_RETURN(0);
 
1018
    return(0);
1043
1019
  }
1044
1020
 
1045
 
  DBUG_PRINT("debug", ("all: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
1046
 
                       YESNO(all),
1047
 
                       YESNO(thd->transaction.all.modified_non_trans_table),
1048
 
                       YESNO(thd->transaction.stmt.modified_non_trans_table)));
1049
1021
  if ((all && thd->transaction.all.modified_non_trans_table) ||
1050
1022
      (!all && thd->transaction.stmt.modified_non_trans_table) ||
1051
1023
      (thd->options & OPTION_KEEP_LOG))
1058
1030
      transactional table in that statement as well, which needs to be
1059
1031
      rolled back on the slave.
1060
1032
    */
1061
 
    Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE);
 
1033
    Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), true, false);
1062
1034
    qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE)
1063
1035
    error= binlog_end_trans(thd, trx_data, &qev, all);
1064
1036
  }
1072
1044
     */
1073
1045
    error= binlog_end_trans(thd, trx_data, 0, all);
1074
1046
  }
1075
 
  DBUG_RETURN(error);
 
1047
  return(error);
1076
1048
}
1077
1049
 
1078
1050
/**
1102
1074
static int binlog_savepoint_set(handlerton *hton __attribute__((__unused__)),
1103
1075
                                THD *thd, void *sv)
1104
1076
{
1105
 
  DBUG_ENTER("binlog_savepoint_set");
1106
 
 
1107
1077
  binlog_trans_log_savepos(thd, (my_off_t*) sv);
1108
1078
  /* Write it to the binary log */
1109
1079
  
1110
1080
  int const error=
1111
1081
    thd->binlog_query(THD::STMT_QUERY_TYPE,
1112
 
                      thd->query, thd->query_length, TRUE, FALSE);
1113
 
  DBUG_RETURN(error);
 
1082
                      thd->query, thd->query_length, true, false);
 
1083
  return(error);
1114
1084
}
1115
1085
 
1116
1086
static int binlog_savepoint_rollback(handlerton *hton __attribute__((__unused__)),
1117
1087
                                     THD *thd, void *sv)
1118
1088
{
1119
 
  DBUG_ENTER("binlog_savepoint_rollback");
1120
 
 
1121
1089
  /*
1122
1090
    Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
1123
1091
    non-transactional table. Otherwise, truncate the binlog cache starting
1128
1096
  {
1129
1097
    int error=
1130
1098
      thd->binlog_query(THD::STMT_QUERY_TYPE,
1131
 
                        thd->query, thd->query_length, TRUE, FALSE);
1132
 
    DBUG_RETURN(error);
 
1099
                        thd->query, thd->query_length, true, false);
 
1100
    return(error);
1133
1101
  }
1134
1102
  binlog_trans_log_truncate(thd, *(my_off_t*)sv);
1135
 
  DBUG_RETURN(0);
 
1103
  return(0);
1136
1104
}
1137
1105
 
1138
1106
 
1139
1107
int check_binlog_magic(IO_CACHE* log, const char** errmsg)
1140
1108
{
1141
1109
  char magic[4];
1142
 
  DBUG_ASSERT(my_b_tell(log) == 0);
 
1110
  assert(my_b_tell(log) == 0);
1143
1111
 
1144
1112
  if (my_b_read(log, (uchar*) magic, sizeof(magic)))
1145
1113
  {
1160
1128
File open_binlog(IO_CACHE *log, const char *log_file_name, const char **errmsg)
1161
1129
{
1162
1130
  File file;
1163
 
  DBUG_ENTER("open_binlog");
1164
1131
 
1165
1132
  if ((file = my_open(log_file_name, O_RDONLY | O_BINARY | O_SHARE, 
1166
1133
                      MYF(MY_WME))) < 0)
1180
1147
  }
1181
1148
  if (check_binlog_magic(log,errmsg))
1182
1149
    goto err;
1183
 
  DBUG_RETURN(file);
 
1150
  return(file);
1184
1151
 
1185
1152
err:
1186
1153
  if (file >= 0)
1188
1155
    my_close(file,MYF(0));
1189
1156
    end_io_cache(log);
1190
1157
  }
1191
 
  DBUG_RETURN(-1);
 
1158
  return(-1);
1192
1159
}
1193
1160
 
1194
1161
 
1211
1178
  ulong                 max_found=0;
1212
1179
  size_t                buf_length, length;
1213
1180
  char                  *start, *end;
1214
 
  DBUG_ENTER("find_uniq_filename");
1215
1181
 
1216
1182
  length= dirname_part(buff, name, &buf_length);
1217
1183
  start=  name + length;
1223
1189
  if (!(dir_info = my_dir(buff,MYF(MY_DONT_SORT))))
1224
1190
  {                                             // This shouldn't happen
1225
1191
    strmov(end,".1");                           // use name+1
1226
 
    DBUG_RETURN(0);
 
1192
    return(0);
1227
1193
  }
1228
1194
  file_info= dir_info->dir_entry;
1229
1195
  for (i=dir_info->number_off_files ; i-- ; file_info++)
1238
1204
 
1239
1205
  *end++='.';
1240
1206
  sprintf(end,"%06ld",max_found+1);
1241
 
  DBUG_RETURN(0);
 
1207
  return(0);
1242
1208
}
1243
1209
 
1244
1210
 
1245
1211
void MYSQL_LOG::init(enum_log_type log_type_arg,
1246
1212
                     enum cache_type io_cache_type_arg)
1247
1213
{
1248
 
  DBUG_ENTER("MYSQL_LOG::init");
1249
1214
  log_type= log_type_arg;
1250
1215
  io_cache_type= io_cache_type_arg;
1251
 
  DBUG_PRINT("info",("log_type: %d", log_type));
1252
 
  DBUG_VOID_RETURN;
 
1216
  return;
1253
1217
}
1254
1218
 
1255
1219
 
1280
1244
  char buff[FN_REFLEN];
1281
1245
  File file= -1;
1282
1246
  int open_flags= O_CREAT | O_BINARY;
1283
 
  DBUG_ENTER("MYSQL_LOG::open");
1284
 
  DBUG_PRINT("enter", ("log_type: %d", (int) log_type_arg));
1285
1247
 
1286
1248
  write_error= 0;
1287
1249
 
1329
1291
  }
1330
1292
 
1331
1293
  log_state= LOG_OPENED;
1332
 
  DBUG_RETURN(0);
 
1294
  return(0);
1333
1295
 
1334
1296
err:
1335
1297
  sql_print_error("Could not use %s for logging (error %d). \
1341
1303
  end_io_cache(&log_file);
1342
1304
  safeFree(name);
1343
1305
  log_state= LOG_CLOSED;
1344
 
  DBUG_RETURN(1);
 
1306
  return(1);
1345
1307
}
1346
1308
 
1347
1309
MYSQL_LOG::MYSQL_LOG()
1348
 
  : name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN),
 
1310
  : name(0), write_error(false), inited(false), log_type(LOG_UNKNOWN),
1349
1311
    log_state(LOG_CLOSED)
1350
1312
{
1351
1313
  /*
1359
1321
 
1360
1322
void MYSQL_LOG::init_pthread_objects()
1361
1323
{
1362
 
  DBUG_ASSERT(inited == 0);
 
1324
  assert(inited == 0);
1363
1325
  inited= 1;
1364
1326
  (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW);
1365
1327
}
1380
1342
 
1381
1343
void MYSQL_LOG::close(uint exiting)
1382
1344
{                                       // One can't set log_type here!
1383
 
  DBUG_ENTER("MYSQL_LOG::close");
1384
 
  DBUG_PRINT("enter",("exiting: %d", (int) exiting));
1385
1345
  if (log_state == LOG_OPENED)
1386
1346
  {
1387
1347
    end_io_cache(&log_file);
1401
1361
 
1402
1362
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
1403
1363
  safeFree(name);
1404
 
  DBUG_VOID_RETURN;
 
1364
  return;
1405
1365
}
1406
1366
 
1407
1367
/** This is called only once. */
1408
1368
 
1409
1369
void MYSQL_LOG::cleanup()
1410
1370
{
1411
 
  DBUG_ENTER("cleanup");
1412
1371
  if (inited)
1413
1372
  {
1414
1373
    inited= 0;
1415
1374
    (void) pthread_mutex_destroy(&LOCK_log);
1416
1375
    close(0);
1417
1376
  }
1418
 
  DBUG_VOID_RETURN;
 
1377
  return;
1419
1378
}
1420
1379
 
1421
1380
 
1453
1412
{
1454
1413
  char *save_name;
1455
1414
 
1456
 
  DBUG_ENTER("MYSQL_LOG::reopen_file");
1457
1415
  if (!is_open())
1458
1416
  {
1459
 
    DBUG_PRINT("info",("log is closed"));
1460
 
    DBUG_VOID_RETURN;
 
1417
    return;
1461
1418
  }
1462
1419
 
1463
1420
  pthread_mutex_lock(&LOCK_log);
1475
1432
 
1476
1433
  pthread_mutex_unlock(&LOCK_log);
1477
1434
 
1478
 
  DBUG_VOID_RETURN;
 
1435
  return;
1479
1436
}
1480
1437
 
1481
1438
 
1564
1521
  }
1565
1522
 
1566
1523
  (void) pthread_mutex_unlock(&LOCK_log);
1567
 
  return FALSE;
 
1524
  return false;
1568
1525
err:
1569
1526
 
1570
1527
  if (!write_error)
1573
1530
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
1574
1531
  }
1575
1532
  (void) pthread_mutex_unlock(&LOCK_log);
1576
 
  return TRUE;
 
1533
  return true;
1577
1534
}
1578
1535
 
1579
1536
 
1614
1571
                            const char *sql_text, uint sql_text_len)
1615
1572
{
1616
1573
  bool error= 0;
1617
 
  DBUG_ENTER("MYSQL_QUERY_LOG::write");
1618
1574
 
1619
1575
  (void) pthread_mutex_lock(&LOCK_log);
1620
1576
 
1621
1577
  if (!is_open())
1622
1578
  {
1623
1579
    (void) pthread_mutex_unlock(&LOCK_log);
1624
 
    DBUG_RETURN(0);
 
1580
    return(0);
1625
1581
  }
1626
1582
 
1627
1583
  if (is_open())
1730
1686
    }
1731
1687
  }
1732
1688
  (void) pthread_mutex_unlock(&LOCK_log);
1733
 
  DBUG_RETURN(error);
 
1689
  return(error);
1734
1690
}
1735
1691
 
1736
1692
 
1764
1720
 
1765
1721
MYSQL_BIN_LOG::MYSQL_BIN_LOG()
1766
1722
  :bytes_written(0), prepared_xids(0), file_id(1), open_count(1),
1767
 
   need_start_event(TRUE), m_table_map_version(0),
 
1723
   need_start_event(true), m_table_map_version(0),
1768
1724
   description_event_for_exec(0), description_event_for_queue(0)
1769
1725
{
1770
1726
  /*
1781
1737
 
1782
1738
void MYSQL_BIN_LOG::cleanup()
1783
1739
{
1784
 
  DBUG_ENTER("cleanup");
1785
1740
  if (inited)
1786
1741
  {
1787
1742
    inited= 0;
1792
1747
    (void) pthread_mutex_destroy(&LOCK_index);
1793
1748
    (void) pthread_cond_destroy(&update_cond);
1794
1749
  }
1795
 
  DBUG_VOID_RETURN;
 
1750
  return;
1796
1751
}
1797
1752
 
1798
1753
 
1799
1754
/* Init binlog-specific vars */
1800
1755
void MYSQL_BIN_LOG::init(bool no_auto_events_arg, ulong max_size_arg)
1801
1756
{
1802
 
  DBUG_ENTER("MYSQL_BIN_LOG::init");
1803
1757
  no_auto_events= no_auto_events_arg;
1804
1758
  max_size= max_size_arg;
1805
 
  DBUG_PRINT("info",("max_size: %lu", max_size));
1806
 
  DBUG_VOID_RETURN;
 
1759
  return;
1807
1760
}
1808
1761
 
1809
1762
 
1810
1763
void MYSQL_BIN_LOG::init_pthread_objects()
1811
1764
{
1812
 
  DBUG_ASSERT(inited == 0);
 
1765
  assert(inited == 0);
1813
1766
  inited= 1;
1814
1767
  (void) pthread_mutex_init(&LOCK_log, MY_MUTEX_INIT_SLOW);
1815
1768
  (void) pthread_mutex_init(&LOCK_index, MY_MUTEX_INIT_SLOW);
1821
1774
                                const char *log_name)
1822
1775
{
1823
1776
  File index_file_nr= -1;
1824
 
  DBUG_ASSERT(!my_b_inited(&index_file));
 
1777
  assert(!my_b_inited(&index_file));
1825
1778
 
1826
1779
  /*
1827
1780
    First open of this class instance
1852
1805
    */
1853
1806
    if (index_file_nr >= 0)
1854
1807
      my_close(index_file_nr,MYF(0));
1855
 
    return TRUE;
 
1808
    return true;
1856
1809
  }
1857
 
  return FALSE;
 
1810
  return false;
1858
1811
}
1859
1812
 
1860
1813
 
1881
1834
                         bool null_created_arg)
1882
1835
{
1883
1836
  File file= -1;
1884
 
  DBUG_ENTER("MYSQL_BIN_LOG::open");
1885
 
  DBUG_PRINT("enter",("log_type: %d",(int) log_type_arg));
1886
1837
 
1887
1838
  write_error=0;
1888
1839
 
1889
1840
  /* open the main log file */
1890
1841
  if (MYSQL_LOG::open(log_name, log_type_arg, new_name, io_cache_type_arg))
1891
 
    DBUG_RETURN(1);                            /* all warnings issued */
 
1842
    return(1);                            /* all warnings issued */
1892
1843
 
1893
1844
  init(no_auto_events_arg, max_size_arg);
1894
1845
 
1895
1846
  open_count++;
1896
1847
 
1897
 
  DBUG_ASSERT(log_type == LOG_BIN);
 
1848
  assert(log_type == LOG_BIN);
1898
1849
 
1899
1850
  {
1900
1851
    bool write_file_name_to_index_file=0;
1914
1865
      write_file_name_to_index_file= 1;
1915
1866
    }
1916
1867
 
1917
 
    DBUG_ASSERT(my_b_inited(&index_file) != 0);
 
1868
    assert(my_b_inited(&index_file) != 0);
1918
1869
    reinit_io_cache(&index_file, WRITE_CACHE,
1919
1870
                    my_b_filelength(&index_file), 0, 0);
1920
1871
    if (need_start_event && !no_auto_events)
1988
1939
  }
1989
1940
  log_state= LOG_OPENED;
1990
1941
 
1991
 
  DBUG_RETURN(0);
 
1942
  return(0);
1992
1943
 
1993
1944
err:
1994
1945
  sql_print_error("Could not use %s for logging (error %d). \
2001
1952
  end_io_cache(&index_file);
2002
1953
  safeFree(name);
2003
1954
  log_state= LOG_CLOSED;
2004
 
  DBUG_RETURN(1);
 
1955
  return(1);
2005
1956
}
2006
1957
 
2007
1958
 
2045
1996
  my_off_t init_offset= offset;
2046
1997
  File file= index_file->file;
2047
1998
  uchar io_buf[IO_SIZE*2];
2048
 
  DBUG_ENTER("copy_up_file_and_fill");
2049
1999
 
2050
2000
  for (;; offset+= bytes_read)
2051
2001
  {
2065
2015
 
2066
2016
  /* Reset data in old index cache */
2067
2017
  reinit_io_cache(index_file, READ_CACHE, (my_off_t) 0, 0, 1);
2068
 
  DBUG_RETURN(0);
 
2018
  return(0);
2069
2019
 
2070
2020
err:
2071
 
  DBUG_RETURN(1);
 
2021
  return(1);
2072
2022
}
2073
2023
 
2074
2024
#endif /* HAVE_REPLICATION */
2101
2051
  int error= 0;
2102
2052
  char *fname= linfo->log_file_name;
2103
2053
  uint log_name_len= log_name ? (uint) strlen(log_name) : 0;
2104
 
  DBUG_ENTER("find_log_pos");
2105
 
  DBUG_PRINT("enter",("log_name: %s", log_name ? log_name : "NULL"));
2106
2054
 
2107
2055
  /*
2108
2056
    Mutex needed because we need to make sure the file pointer does not
2133
2081
        (log_name_len == length-1 && fname[log_name_len] == '\n' &&
2134
2082
         !memcmp(fname, log_name, log_name_len)))
2135
2083
    {
2136
 
      DBUG_PRINT("info",("Found log file entry"));
2137
2084
      fname[length-1]=0;                        // remove last \n
2138
2085
      linfo->index_file_start_offset= offset;
2139
2086
      linfo->index_file_offset = my_b_tell(&index_file);
2143
2090
 
2144
2091
  if (need_lock)
2145
2092
    pthread_mutex_unlock(&LOCK_index);
2146
 
  DBUG_RETURN(error);
 
2093
  return(error);
2147
2094
}
2148
2095
 
2149
2096
 
2223
2170
  LOG_INFO linfo;
2224
2171
  bool error=0;
2225
2172
  const char* save_name;
2226
 
  DBUG_ENTER("reset_logs");
2227
2173
 
2228
2174
  ha_reset_logs(thd);
2229
2175
  /*
2322
2268
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
2323
2269
  pthread_mutex_unlock(&LOCK_index);
2324
2270
  pthread_mutex_unlock(&LOCK_log);
2325
 
  DBUG_RETURN(error);
 
2271
  return(error);
2326
2272
}
2327
2273
 
2328
2274
 
2368
2314
int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
2369
2315
{
2370
2316
  int error;
2371
 
  DBUG_ENTER("purge_first_log");
2372
2317
 
2373
 
  DBUG_ASSERT(is_open());
2374
 
  DBUG_ASSERT(rli->slave_running == 1);
2375
 
  DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name));
 
2318
  assert(is_open());
 
2319
  assert(rli->slave_running == 1);
 
2320
  assert(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name));
2376
2321
 
2377
2322
  pthread_mutex_lock(&LOCK_index);
2378
2323
  pthread_mutex_lock(&rli->log_space_lock);
2434
2379
 
2435
2380
err:
2436
2381
  pthread_mutex_unlock(&LOCK_index);
2437
 
  DBUG_RETURN(error);
 
2382
  return(error);
2438
2383
}
2439
2384
 
2440
2385
/**
2486
2431
  int ret = 0;
2487
2432
  bool exit_loop= 0;
2488
2433
  LOG_INFO log_info;
2489
 
  DBUG_ENTER("purge_logs");
2490
 
  DBUG_PRINT("info",("to_log= %s",to_log));
2491
2434
 
2492
2435
  if (need_mutex)
2493
2436
    pthread_mutex_lock(&LOCK_index);
2537
2480
    }
2538
2481
    else
2539
2482
    {
2540
 
      DBUG_PRINT("info",("purging %s",log_info.log_file_name));
2541
2483
      if (!my_delete(log_info.log_file_name, MYF(0)))
2542
2484
      {
2543
2485
        if (decrease_log_space)
2565
2507
                              log_info.log_file_name);
2566
2508
          if (my_errno == EMFILE)
2567
2509
          {
2568
 
            DBUG_PRINT("info",
2569
 
                       ("my_errno: %d, set ret = LOG_INFO_EMFILE", my_errno));
2570
2510
            error= LOG_INFO_EMFILE;
2571
2511
          }
2572
2512
          error= LOG_INFO_FATAL;
2593
2533
err:
2594
2534
  if (need_mutex)
2595
2535
    pthread_mutex_unlock(&LOCK_index);
2596
 
  DBUG_RETURN(error);
 
2536
  return(error);
2597
2537
}
2598
2538
 
2599
2539
/**
2621
2561
  LOG_INFO log_info;
2622
2562
  struct stat stat_area;
2623
2563
 
2624
 
  DBUG_ENTER("purge_logs_before_date");
2625
 
 
2626
2564
  pthread_mutex_lock(&LOCK_index);
2627
2565
 
2628
2566
  /*
2709
2647
 
2710
2648
err:
2711
2649
  pthread_mutex_unlock(&LOCK_index);
2712
 
  DBUG_RETURN(error);
 
2650
  return(error);
2713
2651
}
2714
2652
#endif /* HAVE_REPLICATION */
2715
2653
 
2776
2714
{
2777
2715
  char new_name[FN_REFLEN], *new_name_ptr, *old_name;
2778
2716
 
2779
 
  DBUG_ENTER("MYSQL_BIN_LOG::new_file_impl");
2780
2717
  if (!is_open())
2781
2718
  {
2782
 
    DBUG_PRINT("info",("log is closed"));
2783
 
    DBUG_VOID_RETURN;
 
2719
    return;
2784
2720
  }
2785
2721
 
2786
2722
  if (need_lock)
2804
2740
    tc_log_page_waits++;
2805
2741
    pthread_mutex_lock(&LOCK_prep_xids);
2806
2742
    while (prepared_xids) {
2807
 
      DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
2808
2743
      pthread_cond_wait(&COND_prep_xids, &LOCK_prep_xids);
2809
2744
    }
2810
2745
    pthread_mutex_unlock(&LOCK_prep_xids);
2868
2803
    pthread_mutex_unlock(&LOCK_log);
2869
2804
  pthread_mutex_unlock(&LOCK_index);
2870
2805
 
2871
 
  DBUG_VOID_RETURN;
 
2806
  return;
2872
2807
}
2873
2808
 
2874
2809
 
2876
2811
{
2877
2812
  bool error = 0;
2878
2813
  pthread_mutex_lock(&LOCK_log);
2879
 
  DBUG_ENTER("MYSQL_BIN_LOG::append");
2880
2814
 
2881
 
  DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
 
2815
  assert(log_file.type == SEQ_READ_APPEND);
2882
2816
  /*
2883
2817
    Log_event::write() is smart enough to use my_b_write() or
2884
2818
    my_b_append() depending on the kind of cache we have.
2889
2823
    goto err;
2890
2824
  }
2891
2825
  bytes_written+= ev->data_written;
2892
 
  DBUG_PRINT("info",("max_size: %lu",max_size));
2893
2826
  if ((uint) my_b_append_tell(&log_file) > max_size)
2894
2827
    new_file_without_locking();
2895
2828
 
2896
2829
err:
2897
2830
  pthread_mutex_unlock(&LOCK_log);
2898
2831
  signal_update();                              // Safe as we don't call close
2899
 
  DBUG_RETURN(error);
 
2832
  return(error);
2900
2833
}
2901
2834
 
2902
2835
 
2903
2836
bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
2904
2837
{
2905
2838
  bool error= 0;
2906
 
  DBUG_ENTER("MYSQL_BIN_LOG::appendv");
2907
2839
  va_list(args);
2908
2840
  va_start(args,len);
2909
2841
 
2910
 
  DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
 
2842
  assert(log_file.type == SEQ_READ_APPEND);
2911
2843
 
2912
2844
  safe_mutex_assert_owner(&LOCK_log);
2913
2845
  do
2919
2851
    }
2920
2852
    bytes_written += len;
2921
2853
  } while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
2922
 
  DBUG_PRINT("info",("max_size: %lu",max_size));
2923
2854
  if ((uint) my_b_append_tell(&log_file) > max_size)
2924
2855
    new_file_without_locking();
2925
2856
 
2926
2857
err:
2927
2858
  if (!error)
2928
2859
    signal_update();
2929
 
  DBUG_RETURN(error);
 
2860
  return(error);
2930
2861
}
2931
2862
 
2932
2863
 
2946
2877
 
2947
2878
void MYSQL_BIN_LOG::start_union_events(THD *thd, query_id_t query_id_param)
2948
2879
{
2949
 
  DBUG_ASSERT(!thd->binlog_evt_union.do_union);
2950
 
  thd->binlog_evt_union.do_union= TRUE;
2951
 
  thd->binlog_evt_union.unioned_events= FALSE;
2952
 
  thd->binlog_evt_union.unioned_events_trans= FALSE;
 
2880
  assert(!thd->binlog_evt_union.do_union);
 
2881
  thd->binlog_evt_union.do_union= true;
 
2882
  thd->binlog_evt_union.unioned_events= false;
 
2883
  thd->binlog_evt_union.unioned_events_trans= false;
2953
2884
  thd->binlog_evt_union.first_query_id= query_id_param;
2954
2885
}
2955
2886
 
2956
2887
void MYSQL_BIN_LOG::stop_union_events(THD *thd)
2957
2888
{
2958
 
  DBUG_ASSERT(thd->binlog_evt_union.do_union);
2959
 
  thd->binlog_evt_union.do_union= FALSE;
 
2889
  assert(thd->binlog_evt_union.do_union);
 
2890
  thd->binlog_evt_union.do_union= false;
2960
2891
}
2961
2892
 
2962
2893
bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
2973
2904
 
2974
2905
int THD::binlog_setup_trx_data()
2975
2906
{
2976
 
  DBUG_ENTER("THD::binlog_setup_trx_data");
2977
2907
  binlog_trx_data *trx_data=
2978
2908
    (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
2979
2909
 
2980
2910
  if (trx_data)
2981
 
    DBUG_RETURN(0);                             // Already set up
 
2911
    return(0);                             // Already set up
2982
2912
 
2983
2913
  trx_data= (binlog_trx_data*) my_malloc(sizeof(binlog_trx_data), MYF(MY_ZEROFILL));
2984
2914
  if (!trx_data ||
2986
2916
                       LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
2987
2917
  {
2988
2918
    my_free((uchar*)trx_data, MYF(MY_ALLOW_ZERO_PTR));
2989
 
    DBUG_RETURN(1);                      // Didn't manage to set it up
 
2919
    return(1);                      // Didn't manage to set it up
2990
2920
  }
2991
2921
  thd_set_ha_data(this, binlog_hton, trx_data);
2992
2922
 
2993
2923
  trx_data= new (thd_get_ha_data(this, binlog_hton)) binlog_trx_data;
2994
2924
 
2995
 
  DBUG_RETURN(0);
 
2925
  return(0);
2996
2926
}
2997
2927
 
2998
2928
/*
3027
2957
THD::binlog_start_trans_and_stmt()
3028
2958
{
3029
2959
  binlog_trx_data *trx_data= (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
3030
 
  DBUG_ENTER("binlog_start_trans_and_stmt");
3031
 
  DBUG_PRINT("enter", ("trx_data: 0x%lx  trx_data->before_stmt_pos: %lu",
3032
 
                       (long) trx_data,
3033
 
                       (trx_data ? (ulong) trx_data->before_stmt_pos :
3034
 
                        (ulong) 0)));
3035
2960
 
3036
2961
  if (trx_data == NULL ||
3037
2962
      trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
3038
2963
  {
3039
2964
    this->binlog_set_stmt_begin();
3040
2965
    if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
3041
 
      trans_register_ha(this, TRUE, binlog_hton);
3042
 
    trans_register_ha(this, FALSE, binlog_hton);
 
2966
      trans_register_ha(this, true, binlog_hton);
 
2967
    trans_register_ha(this, false, binlog_hton);
3043
2968
    /*
3044
2969
      Mark statement transaction as read/write. We never start
3045
2970
      a binary log transaction and keep it read-only,
3051
2976
    */
3052
2977
    ha_data[binlog_hton->slot].ha_info[0].set_trx_read_write();
3053
2978
  }
3054
 
  DBUG_VOID_RETURN;
 
2979
  return;
3055
2980
}
3056
2981
 
3057
2982
void THD::binlog_set_stmt_begin() {
3078
3003
int THD::binlog_write_table_map(TABLE *table, bool is_trans)
3079
3004
{
3080
3005
  int error;
3081
 
  DBUG_ENTER("THD::binlog_write_table_map");
3082
 
  DBUG_PRINT("enter", ("table: 0x%lx  (%s: #%lu)",
3083
 
                       (long) table, table->s->table_name.str,
3084
 
                       table->s->table_map_id));
3085
3006
 
3086
3007
  /* Pre-conditions */
3087
 
  DBUG_ASSERT(current_stmt_binlog_row_based && mysql_bin_log.is_open());
3088
 
  DBUG_ASSERT(table->s->table_map_id != ULONG_MAX);
 
3008
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
 
3009
  assert(table->s->table_map_id != ULONG_MAX);
3089
3010
 
3090
3011
  Table_map_log_event::flag_set const
3091
3012
    flags= Table_map_log_event::TM_NO_FLAGS;
3097
3018
    binlog_start_trans_and_stmt();
3098
3019
 
3099
3020
  if ((error= mysql_bin_log.write(&the_event)))
3100
 
    DBUG_RETURN(error);
 
3021
    return(error);
3101
3022
 
3102
3023
  binlog_table_maps++;
3103
3024
  table->s->table_map_version= mysql_bin_log.table_map_version();
3104
 
  DBUG_RETURN(0);
 
3025
  return(0);
3105
3026
}
3106
3027
 
3107
3028
Rows_log_event*
3127
3048
  binlog_trx_data *const trx_data=
3128
3049
    (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
3129
3050
 
3130
 
  DBUG_ASSERT(trx_data);
 
3051
  assert(trx_data);
3131
3052
  trx_data->set_pending(ev);
3132
3053
}
3133
3054
 
3141
3062
MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
3142
3063
                                                Rows_log_event* event)
3143
3064
{
3144
 
  DBUG_ENTER("MYSQL_BIN_LOG::flush_and_set_pending_rows_event(event)");
3145
 
  DBUG_ASSERT(mysql_bin_log.is_open());
3146
 
  DBUG_PRINT("enter", ("event: 0x%lx", (long) event));
 
3065
  assert(mysql_bin_log.is_open());
3147
3066
 
3148
3067
  int error= 0;
3149
3068
 
3150
3069
  binlog_trx_data *const trx_data=
3151
3070
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
3152
3071
 
3153
 
  DBUG_ASSERT(trx_data);
3154
 
 
3155
 
  DBUG_PRINT("info", ("trx_data->pending(): 0x%lx", (long) trx_data->pending()));
 
3072
  assert(trx_data);
3156
3073
 
3157
3074
  if (Rows_log_event* pending= trx_data->pending())
3158
3075
  {
3179
3096
    if (pending->write(file))
3180
3097
    {
3181
3098
      pthread_mutex_unlock(&LOCK_log);
3182
 
      DBUG_RETURN(1);
 
3099
      return(1);
3183
3100
    }
3184
3101
 
3185
3102
    /*
3217
3134
 
3218
3135
  thd->binlog_set_pending_rows_event(event);
3219
3136
 
3220
 
  DBUG_RETURN(error);
 
3137
  return(error);
3221
3138
}
3222
3139
 
3223
3140
/**
3228
3145
{
3229
3146
  THD *thd= event_info->thd;
3230
3147
  bool error= 1;
3231
 
  DBUG_ENTER("MYSQL_BIN_LOG::write(Log_event *)");
3232
3148
 
3233
3149
  if (thd->binlog_evt_union.do_union)
3234
3150
  {
3236
3152
      In Stored function; Remember that function call caused an update.
3237
3153
      We will log the function call to the binary log on function exit
3238
3154
    */
3239
 
    thd->binlog_evt_union.unioned_events= TRUE;
 
3155
    thd->binlog_evt_union.unioned_events= true;
3240
3156
    thd->binlog_evt_union.unioned_events_trans |= event_info->cache_stmt;
3241
 
    DBUG_RETURN(0);
 
3157
    return(0);
3242
3158
  }
3243
3159
 
3244
3160
  /*
3274
3190
        (!binlog_filter->db_ok(local_db)))
3275
3191
    {
3276
3192
      VOID(pthread_mutex_unlock(&LOCK_log));
3277
 
      DBUG_RETURN(0);
 
3193
      return(0);
3278
3194
    }
3279
3195
 
3280
3196
    /*
3297
3213
      my_off_t trans_log_pos= my_b_tell(trans_log);
3298
3214
      if (event_info->get_cache_stmt() || trans_log_pos != 0)
3299
3215
      {
3300
 
        DBUG_PRINT("info", ("Using trans_log: cache: %d, trans_log_pos: %lu",
3301
 
                            event_info->get_cache_stmt(),
3302
 
                            (ulong) trans_log_pos));
3303
3216
        if (trans_log_pos == 0)
3304
3217
          thd->binlog_start_trans_and_stmt();
3305
3218
        file= trans_log;
3311
3224
        LOCK_log.
3312
3225
      */
3313
3226
    }
3314
 
    DBUG_PRINT("info",("event type: %d",event_info->get_type_code()));
3315
3227
 
3316
3228
    /*
3317
3229
      No check for auto events flag here - this write method should
3340
3252
        }
3341
3253
        if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
3342
3254
        {
3343
 
          DBUG_PRINT("info",("number of auto_inc intervals: %u",
3344
 
                             thd->auto_inc_intervals_in_cur_stmt_for_binlog.
3345
 
                             nb_elements()));
3346
3255
          /*
3347
3256
            If the auto_increment was second in a table's index (possible with
3348
3257
            MyISAM or BDB) (table->next_number_keypart != 0), such event is
3410
3319
    ++m_table_map_version;
3411
3320
 
3412
3321
  pthread_mutex_unlock(&LOCK_log);
3413
 
  DBUG_RETURN(error);
 
3322
  return(error);
3414
3323
}
3415
3324
 
3416
3325
 
3439
3348
    if (thd->options & OPTION_LOG_OFF)
3440
3349
    {
3441
3350
      /* No logging */
3442
 
      return FALSE;
 
3351
      return false;
3443
3352
    }
3444
3353
 
3445
 
    return TRUE;
 
3354
    return true;
3446
3355
  }
3447
3356
 
3448
 
  return FALSE;
 
3357
  return false;
3449
3358
}
3450
3359
 
3451
3360
 
3457
3366
 
3458
3367
  /* Print the message to the buffer if we want to log this king of commands */
3459
3368
  if (! logger.log_command(thd, command))
3460
 
    return FALSE;
 
3369
    return false;
3461
3370
 
3462
3371
  va_start(args, format);
3463
3372
  error= logger.general_log_print(thd, command, format, args);
3473
3382
  if (logger.log_command(thd, command))
3474
3383
    return logger.general_log_write(thd, command, query, query_length);
3475
3384
 
3476
 
  return FALSE;
 
3385
  return false;
3477
3386
}
3478
3387
 
3479
3388
void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
3557
3466
    */
3558
3467
    if (unlikely(carry > 0))
3559
3468
    {
3560
 
      DBUG_ASSERT(carry < LOG_EVENT_HEADER_LEN);
 
3469
      assert(carry < LOG_EVENT_HEADER_LEN);
3561
3470
 
3562
3471
      /* assemble both halves */
3563
3472
      memcpy(&header[carry], (char *)cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
3640
3549
    cache->read_pos=cache->read_end;            // Mark buffer used up
3641
3550
  } while ((length= my_b_fill(cache)));
3642
3551
 
3643
 
  DBUG_ASSERT(carry == 0);
 
3552
  assert(carry == 0);
3644
3553
 
3645
3554
  if (sync_log)
3646
3555
    flush_and_sync();
3671
3580
 
3672
3581
bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
3673
3582
{
3674
 
  DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)");
3675
3583
  VOID(pthread_mutex_lock(&LOCK_log));
3676
3584
 
3677
3585
  /* NULL would represent nothing to replicate after ROLLBACK */
3678
 
  DBUG_ASSERT(commit_event != NULL);
 
3586
  assert(commit_event != NULL);
3679
3587
 
3680
 
  DBUG_ASSERT(is_open());
 
3588
  assert(is_open());
3681
3589
  if (likely(is_open()))                       // Should always be true
3682
3590
  {
3683
3591
    /*
3691
3599
        transaction is either a BEGIN..COMMIT block or a single
3692
3600
        statement in autocommit mode.
3693
3601
      */
3694
 
      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE);
 
3602
      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), true, false);
3695
3603
      /*
3696
3604
        Imagine this is rollback due to net timeout, after all
3697
3605
        statements of the transaction succeeded. Then we want a
3715
3623
      if (qinfo.write(&log_file))
3716
3624
        goto err;
3717
3625
 
3718
 
      DBUG_EXECUTE_IF("crash_before_writing_xid",
3719
 
                      {
3720
 
                        if ((write_error= write_cache(cache, false, true)))
3721
 
                          DBUG_PRINT("info", ("error writing binlog cache: %d",
3722
 
                                               write_error));
3723
 
                        DBUG_PRINT("info", ("crashing before writing xid"));
3724
 
                        abort();
3725
 
                      });
3726
 
 
3727
3626
      if ((write_error= write_cache(cache, false, false)))
3728
3627
        goto err;
3729
3628
 
3731
3630
        goto err;
3732
3631
      if (flush_and_sync())
3733
3632
        goto err;
3734
 
      DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
3735
3633
      if (cache->error)                         // Error on read
3736
3634
      {
3737
3635
        sql_print_error(ER(ER_ERROR_ON_READ), cache->file_name, errno);
3760
3658
  }
3761
3659
  VOID(pthread_mutex_unlock(&LOCK_log));
3762
3660
 
3763
 
  DBUG_RETURN(0);
 
3661
  return(0);
3764
3662
 
3765
3663
err:
3766
3664
  if (!write_error)
3769
3667
    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
3770
3668
  }
3771
3669
  VOID(pthread_mutex_unlock(&LOCK_log));
3772
 
  DBUG_RETURN(1);
 
3670
  return(1);
3773
3671
}
3774
3672
 
3775
3673
 
3785
3683
void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
3786
3684
{
3787
3685
  const char *old_msg;
3788
 
  DBUG_ENTER("wait_for_update_relay_log");
3789
3686
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
3790
3687
                           "Slave has read all relay log; " 
3791
3688
                           "waiting for the slave I/O "
3792
3689
                           "thread to update it" );
3793
3690
  pthread_cond_wait(&update_cond, &LOCK_log);
3794
3691
  thd->exit_cond(old_msg);
3795
 
  DBUG_VOID_RETURN;
 
3692
  return;
3796
3693
}
3797
3694
 
3798
3695
 
3817
3714
{
3818
3715
  int ret= 0;
3819
3716
  const char* old_msg = thd->proc_info;
3820
 
  DBUG_ENTER("wait_for_update_bin_log");
3821
3717
  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
3822
3718
                           "Master has sent all binlog to slave; "
3823
3719
                           "waiting for binlog to be updated");
3826
3722
  else
3827
3723
    ret= pthread_cond_timedwait(&update_cond, &LOCK_log,
3828
3724
                                const_cast<struct timespec *>(timeout));
3829
 
  DBUG_RETURN(ret);
 
3725
  return(ret);
3830
3726
}
3831
3727
 
3832
3728
 
3846
3742
 
3847
3743
void MYSQL_BIN_LOG::close(uint exiting)
3848
3744
{                                       // One can't set log_type here!
3849
 
  DBUG_ENTER("MYSQL_BIN_LOG::close");
3850
 
  DBUG_PRINT("enter",("exiting: %d", (int) exiting));
3851
3745
  if (log_state == LOG_OPENED)
3852
3746
  {
3853
3747
#ifdef HAVE_REPLICATION
3889
3783
  }
3890
3784
  log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
3891
3785
  safeFree(name);
3892
 
  DBUG_VOID_RETURN;
 
3786
  return;
3893
3787
}
3894
3788
 
3895
3789
 
3902
3796
    uses the old_max_size argument, so max_size_arg has been overwritten and
3903
3797
    it's like if the SET command was never run.
3904
3798
  */
3905
 
  DBUG_ENTER("MYSQL_BIN_LOG::set_max_size");
3906
3799
  pthread_mutex_lock(&LOCK_log);
3907
3800
  if (is_open())
3908
3801
    max_size= max_size_arg;
3909
3802
  pthread_mutex_unlock(&LOCK_log);
3910
 
  DBUG_VOID_RETURN;
 
3803
  return;
3911
3804
}
3912
3805
 
3913
3806
 
3933
3826
{
3934
3827
  register int flag;
3935
3828
  const char *start;
3936
 
  DBUG_ENTER("test_if_number");
3937
3829
 
3938
3830
  flag= 0; 
3939
3831
  start= str;
3954
3846
         str++, flag=1) ;
3955
3847
  }
3956
3848
  if (*str != 0 || flag == 0)
3957
 
    DBUG_RETURN(0);
 
3849
    return(0);
3958
3850
  if (res)
3959
3851
    *res=atol(start);
3960
 
  DBUG_RETURN(1);                       /* Number ok */
 
3852
  return(1);                    /* Number ok */
3961
3853
} /* test_if_number */
3962
3854
 
3963
3855
 
4017
3909
 
4018
3910
void MYSQL_BIN_LOG::signal_update()
4019
3911
{
4020
 
  DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
4021
3912
  pthread_cond_broadcast(&update_cond);
4022
 
  DBUG_VOID_RETURN;
 
3913
  return;
4023
3914
}
4024
3915
 
4025
3916
/**
4046
3937
  time_t skr;
4047
3938
  struct tm tm_tmp;
4048
3939
  struct tm *start;
4049
 
  DBUG_ENTER("print_buffer_to_file");
4050
 
  DBUG_PRINT("enter",("buffer: %s", buffer));
4051
3940
 
4052
3941
  VOID(pthread_mutex_lock(&LOCK_error_log));
4053
3942
 
4069
3958
  fflush(stderr);
4070
3959
 
4071
3960
  VOID(pthread_mutex_unlock(&LOCK_error_log));
4072
 
  DBUG_VOID_RETURN;
 
3961
  return;
4073
3962
}
4074
3963
 
4075
3964
 
4078
3967
  char   buff[1024];
4079
3968
  size_t length;
4080
3969
  int error_code= errno;
4081
 
  DBUG_ENTER("vprint_msg_to_log");
4082
3970
 
4083
3971
  length= vsnprintf(buff, sizeof(buff), format, args);
4084
3972
 
4085
3973
  print_buffer_to_file(level, error_code, buff, length);
4086
3974
 
4087
 
  DBUG_RETURN(0);
 
3975
  return(0);
4088
3976
}
4089
3977
 
4090
3978
 
4091
3979
void sql_print_error(const char *format, ...) 
4092
3980
{
4093
3981
  va_list args;
4094
 
  DBUG_ENTER("sql_print_error");
4095
3982
 
4096
3983
  va_start(args, format);
4097
3984
  error_log_print(ERROR_LEVEL, format, args);
4098
3985
  va_end(args);
4099
3986
 
4100
 
  DBUG_VOID_RETURN;
 
3987
  return;
4101
3988
}
4102
3989
 
4103
3990
 
4104
3991
void sql_print_warning(const char *format, ...) 
4105
3992
{
4106
3993
  va_list args;
4107
 
  DBUG_ENTER("sql_print_warning");
4108
3994
 
4109
3995
  va_start(args, format);
4110
3996
  error_log_print(WARNING_LEVEL, format, args);
4111
3997
  va_end(args);
4112
3998
 
4113
 
  DBUG_VOID_RETURN;
 
3999
  return;
4114
4000
}
4115
4001
 
4116
4002
 
4117
4003
void sql_print_information(const char *format, ...) 
4118
4004
{
4119
4005
  va_list args;
4120
 
  DBUG_ENTER("sql_print_information");
4121
4006
 
4122
4007
  va_start(args, format);
4123
4008
  error_log_print(INFORMATION_LEVEL, format, args);
4124
4009
  va_end(args);
4125
4010
 
4126
 
  DBUG_VOID_RETURN;
 
4011
  return;
4127
4012
}
4128
4013
 
4129
4014
 
4179
4064
int TC_LOG_MMAP::open(const char *opt_name)
4180
4065
{
4181
4066
  uint i;
4182
 
  bool crashed=FALSE;
 
4067
  bool crashed= false;
4183
4068
  PAGE *pg;
4184
4069
 
4185
 
  DBUG_ASSERT(total_ha_2pc > 1);
4186
 
  DBUG_ASSERT(opt_name && opt_name[0]);
 
4070
  assert(total_ha_2pc > 1);
 
4071
  assert(opt_name && opt_name[0]);
4187
4072
 
4188
4073
  tc_log_page_size= my_getpagesize();
4189
 
  DBUG_ASSERT(TC_LOG_PAGE_SIZE % tc_log_page_size == 0);
 
4074
  assert(TC_LOG_PAGE_SIZE % tc_log_page_size == 0);
4190
4075
 
4191
4076
  fn_format(logname,opt_name,mysql_data_home,"",MY_UNPACK_FILENAME);
4192
4077
  if ((fd= my_open(logname, O_RDWR, MYF(0))) < 0)
4205
4090
  else
4206
4091
  {
4207
4092
    inited= 1;
4208
 
    crashed= TRUE;
 
4093
    crashed= true;
4209
4094
    sql_print_information("Recovering after a crash using %s", opt_name);
4210
4095
    if (tc_heuristic_recover)
4211
4096
    {
4228
4113
  inited=2;
4229
4114
 
4230
4115
  npages=(uint)file_length/tc_log_page_size;
4231
 
  DBUG_ASSERT(npages >= 3);             // to guarantee non-empty pool
 
4116
  assert(npages >= 3);             // to guarantee non-empty pool
4232
4117
  if (!(pages=(PAGE *)my_malloc(npages*sizeof(PAGE), MYF(MY_WME|MY_ZEROFILL))))
4233
4118
    goto err;
4234
4119
  inited=3;
4405
4290
  while (*p->ptr)
4406
4291
  {
4407
4292
    p->ptr++;
4408
 
    DBUG_ASSERT(p->ptr < p->end);               // because p->free > 0
 
4293
    assert(p->ptr < p->end);               // because p->free > 0
4409
4294
  }
4410
4295
 
4411
4296
  /* found! store xid there and mark the page dirty */
4438
4323
      goto done;                             // we're done
4439
4324
    }
4440
4325
  }                                          // page was not synced! do it now
4441
 
  DBUG_ASSERT(active == p && syncing == 0);
 
4326
  assert(active == p && syncing == 0);
4442
4327
  pthread_mutex_lock(&LOCK_active);
4443
4328
  syncing=p;                                 // place is vacant - take it
4444
4329
  active=0;                                  // page is not active anymore
4455
4340
{
4456
4341
  int err;
4457
4342
 
4458
 
  DBUG_ASSERT(syncing != active);
 
4343
  assert(syncing != active);
4459
4344
 
4460
4345
  /*
4461
4346
    sit down and relax - this can take a while...
4493
4378
  PAGE *p=pages+(cookie/tc_log_page_size);
4494
4379
  my_xid *x=(my_xid *)(data+cookie);
4495
4380
 
4496
 
  DBUG_ASSERT(*x == xid);
4497
 
  DBUG_ASSERT(x >= p->start && x < p->end);
 
4381
  assert(*x == xid);
 
4382
  assert(x >= p->start && x < p->end);
4498
4383
  *x=0;
4499
4384
 
4500
4385
  pthread_mutex_lock(&p->lock);
4501
4386
  p->free++;
4502
 
  DBUG_ASSERT(p->free <= p->size);
 
4387
  assert(p->free <= p->size);
4503
4388
  set_if_smaller(p->ptr, x);
4504
4389
  if (p->free == p->size)               // the page is completely empty
4505
4390
    statistic_decrement(tc_log_cur_pages_used, &LOCK_status);
4637
4522
  LOG_INFO log_info;
4638
4523
  int      error= 1;
4639
4524
 
4640
 
  DBUG_ASSERT(total_ha_2pc > 1);
4641
 
  DBUG_ASSERT(opt_name && opt_name[0]);
 
4525
  assert(total_ha_2pc > 1);
 
4526
  assert(opt_name && opt_name[0]);
4642
4527
 
4643
4528
  pthread_mutex_init(&LOCK_prep_xids, MY_MUTEX_INIT_FAST);
4644
4529
  pthread_cond_init (&COND_prep_xids, 0);
4720
4605
/** This is called on shutdown, after ha_panic. */
4721
4606
void TC_LOG_BINLOG::close()
4722
4607
{
4723
 
  DBUG_ASSERT(prepared_xids==0);
 
4608
  assert(prepared_xids==0);
4724
4609
  pthread_mutex_destroy(&LOCK_prep_xids);
4725
4610
  pthread_cond_destroy (&COND_prep_xids);
4726
4611
}
4736
4621
*/
4737
4622
int TC_LOG_BINLOG::log_xid(THD *thd, my_xid xid)
4738
4623
{
4739
 
  DBUG_ENTER("TC_LOG_BINLOG::log");
4740
4624
  Xid_log_event xle(thd, xid);
4741
4625
  binlog_trx_data *trx_data=
4742
4626
    (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton);
4744
4628
    We always commit the entire transaction when writing an XID. Also
4745
4629
    note that the return value is inverted.
4746
4630
   */
4747
 
  DBUG_RETURN(!binlog_end_trans(thd, trx_data, &xle, TRUE));
 
4631
  return(!binlog_end_trans(thd, trx_data, &xle, true));
4748
4632
}
4749
4633
 
4750
4634
void TC_LOG_BINLOG::unlog(ulong cookie __attribute__((__unused__)),
4751
4635
                          my_xid xid __attribute__((__unused__)))
4752
4636
{
4753
4637
  pthread_mutex_lock(&LOCK_prep_xids);
4754
 
  DBUG_ASSERT(prepared_xids > 0);
 
4638
  assert(prepared_xids > 0);
4755
4639
  if (--prepared_xids == 0) {
4756
 
    DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
4757
4640
    pthread_cond_signal(&COND_prep_xids);
4758
4641
  }
4759
4642
  pthread_mutex_unlock(&LOCK_prep_xids);