684
677
#define DDL_LOG_NUM_ENTRY_POS 0
685
678
#define DDL_LOG_NAME_LEN_POS 4
686
679
#define DDL_LOG_IO_SIZE_POS 8
689
Read one entry from ddl log file
691
read_ddl_log_file_entry()
692
entry_no Entry number to read
680
#define DDL_LOG_HEADER_SIZE 12
683
Read one entry from ddl log file.
684
@param[out] file_entry_buf Buffer to read into
685
@param entry_no Entry number to read
686
@param size Number of bytes of the entry to read
688
@return Operation status
690
@retval false Success
698
static bool read_ddl_log_file_entry(uint entry_no)
693
static bool read_ddl_log_file_entry(uchar *file_entry_buf,
700
697
bool error= FALSE;
701
698
File file_id= global_ddl_log.file_id;
702
uchar *file_entry_buf= (uchar*)global_ddl_log.file_entry_buf;
703
699
uint io_size= global_ddl_log.io_size;
704
700
DBUG_ENTER("read_ddl_log_file_entry");
701
DBUG_ASSERT(io_size >= size);
706
if (mysql_file_pread(file_id, file_entry_buf, io_size, io_size * entry_no,
707
MYF(MY_WME)) != io_size)
703
if (mysql_file_pread(file_id, file_entry_buf, size, io_size * entry_no,
704
MYF(MY_WME)) != size)
709
706
DBUG_RETURN(error);
714
Write one entry from ddl log file
716
write_ddl_log_file_entry()
717
entry_no Entry number to write
711
Write one entry to ddl log file.
713
@param file_entry_buf Buffer to write
714
@param entry_no Entry number to write
715
@param size Number of bytes of the entry to write
717
@return Operation status
719
@retval false Success
723
static bool write_ddl_log_file_entry(uint entry_no)
722
static bool write_ddl_log_file_entry(uchar *file_entry_buf,
725
726
bool error= FALSE;
726
727
File file_id= global_ddl_log.file_id;
727
char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
728
uint io_size= global_ddl_log.io_size;
728
729
DBUG_ENTER("write_ddl_log_file_entry");
730
DBUG_ASSERT(io_size >= size);
730
if (mysql_file_pwrite(file_id, (uchar*)file_entry_buf,
731
IO_SIZE, IO_SIZE * entry_no, MYF(MY_WME)) != IO_SIZE)
732
if (mysql_file_pwrite(file_id, file_entry_buf, size,
733
io_size * entry_no, MYF(MY_WME)) != size)
733
735
DBUG_RETURN(error);
748
750
uint16 const_var;
749
751
bool error= FALSE;
752
uchar file_entry_buf[DDL_LOG_HEADER_SIZE];
750
753
DBUG_ENTER("write_ddl_log_header");
754
DBUG_ASSERT((DDL_LOG_NAME_POS + 3 * global_ddl_log.name_len)
755
<= global_ddl_log.io_size);
752
int4store(&global_ddl_log.file_entry_buf[DDL_LOG_NUM_ENTRY_POS],
757
int4store(&file_entry_buf[DDL_LOG_NUM_ENTRY_POS],
753
758
global_ddl_log.num_entries);
755
int4store(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_LEN_POS],
758
int4store(&global_ddl_log.file_entry_buf[DDL_LOG_IO_SIZE_POS],
760
if (write_ddl_log_file_entry(0UL))
759
const_var= global_ddl_log.name_len;
760
int4store(&file_entry_buf[DDL_LOG_NAME_LEN_POS],
762
const_var= global_ddl_log.io_size;
763
int4store(&file_entry_buf[DDL_LOG_IO_SIZE_POS],
765
if (write_ddl_log_file_entry(file_entry_buf, 0UL, DDL_LOG_HEADER_SIZE))
762
767
sql_print_error("Error writing ddl log header");
763
768
DBUG_RETURN(TRUE);
798
803
static uint read_ddl_log_header()
800
char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
805
char file_entry_buf[DDL_LOG_HEADER_SIZE];
801
806
char file_name[FN_REFLEN];
803
808
bool successful_open= FALSE;
804
809
DBUG_ENTER("read_ddl_log_header");
810
DBUG_ASSERT(global_ddl_log.io_size <= IO_SIZE);
806
812
create_ddl_log_file_name(file_name);
807
813
if ((global_ddl_log.file_id= mysql_file_open(key_file_global_ddl_log,
809
815
O_RDWR | O_BINARY, MYF(0))) >= 0)
811
if (read_ddl_log_file_entry(0UL))
817
if (read_ddl_log_file_entry((uchar *) file_entry_buf, 0UL,
818
DDL_LOG_HEADER_SIZE))
813
820
/* Write message into error log */
814
821
sql_print_error("Failed to read ddl log file in recovery");
844
read_entry Number of entry to read
845
out:entry_info Information from entry
850
Read a specified entry in the ddl log
846
Set ddl log entry struct from buffer
847
@param read_entry Entry number
848
@param file_entry_buf Buffer to use
849
@param ddl_log_entry Entry to be set
851
@note Pointers in ddl_log_entry will point into file_entry_buf!
853
bool read_ddl_log_entry(uint read_entry, DDL_LOG_ENTRY *ddl_log_entry)
854
static void set_ddl_log_entry_from_buf(uint read_entry,
855
uchar *file_entry_buf,
856
DDL_LOG_ENTRY *ddl_log_entry)
855
char *file_entry_buf= (char*)&global_ddl_log.file_entry_buf;
857
859
uchar single_char;
858
DBUG_ENTER("read_ddl_log_entry");
860
if (read_ddl_log_file_entry(read_entry))
860
DBUG_ENTER("set_ddl_log_entry_from_buf");
864
861
ddl_log_entry->entry_pos= read_entry;
865
862
single_char= file_entry_buf[DDL_LOG_ENTRY_TYPE_POS];
866
863
ddl_log_entry->entry_type= (enum ddl_log_entry_code)single_char;
868
865
ddl_log_entry->action_type= (enum ddl_log_action_code)single_char;
869
866
ddl_log_entry->phase= file_entry_buf[DDL_LOG_PHASE_POS];
870
867
ddl_log_entry->next_entry= uint4korr(&file_entry_buf[DDL_LOG_NEXT_ENTRY_POS]);
871
ddl_log_entry->name= &file_entry_buf[DDL_LOG_NAME_POS];
868
ddl_log_entry->name= (char*) &file_entry_buf[DDL_LOG_NAME_POS];
872
869
inx= DDL_LOG_NAME_POS + global_ddl_log.name_len;
873
ddl_log_entry->from_name= &file_entry_buf[inx];
870
ddl_log_entry->from_name= (char*) &file_entry_buf[inx];
874
871
inx+= global_ddl_log.name_len;
875
ddl_log_entry->handler_name= &file_entry_buf[inx];
872
ddl_log_entry->handler_name= (char*) &file_entry_buf[inx];
881
878
Initialise ddl log
1135
1133
DDL_LOG_MEMORY_ENTRY **active_entry)
1137
1135
bool error, write_header;
1136
char file_entry_buf[IO_SIZE];
1138
1137
DBUG_ENTER("write_ddl_log_entry");
1140
1139
if (init_ddl_log())
1142
1141
DBUG_RETURN(TRUE);
1144
global_ddl_log.file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]=
1143
memset(file_entry_buf, 0, sizeof(file_entry_buf));
1144
file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]=
1145
1145
(char)DDL_LOG_ENTRY_CODE;
1146
global_ddl_log.file_entry_buf[DDL_LOG_ACTION_TYPE_POS]=
1146
file_entry_buf[DDL_LOG_ACTION_TYPE_POS]=
1147
1147
(char)ddl_log_entry->action_type;
1148
global_ddl_log.file_entry_buf[DDL_LOG_PHASE_POS]= 0;
1149
int4store(&global_ddl_log.file_entry_buf[DDL_LOG_NEXT_ENTRY_POS],
1148
file_entry_buf[DDL_LOG_PHASE_POS]= 0;
1149
int4store(&file_entry_buf[DDL_LOG_NEXT_ENTRY_POS],
1150
1150
ddl_log_entry->next_entry);
1151
DBUG_ASSERT(strlen(ddl_log_entry->name) < FN_LEN);
1152
strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS],
1153
ddl_log_entry->name, FN_LEN - 1);
1151
DBUG_ASSERT(strlen(ddl_log_entry->name) < global_ddl_log.name_len);
1152
strmake(&file_entry_buf[DDL_LOG_NAME_POS], ddl_log_entry->name,
1153
global_ddl_log.name_len - 1);
1154
1154
if (ddl_log_entry->action_type == DDL_LOG_RENAME_ACTION ||
1155
1155
ddl_log_entry->action_type == DDL_LOG_REPLACE_ACTION)
1157
DBUG_ASSERT(strlen(ddl_log_entry->from_name) < FN_LEN);
1158
strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + FN_LEN],
1159
ddl_log_entry->from_name, FN_LEN - 1);
1157
DBUG_ASSERT(strlen(ddl_log_entry->from_name) < global_ddl_log.name_len);
1158
strmake(&file_entry_buf[DDL_LOG_NAME_POS + global_ddl_log.name_len],
1159
ddl_log_entry->from_name, global_ddl_log.name_len - 1);
1162
global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + FN_LEN]= 0;
1163
DBUG_ASSERT(strlen(ddl_log_entry->handler_name) < FN_LEN);
1164
strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + (2*FN_LEN)],
1165
ddl_log_entry->handler_name, FN_LEN - 1);
1162
file_entry_buf[DDL_LOG_NAME_POS + global_ddl_log.name_len]= 0;
1163
DBUG_ASSERT(strlen(ddl_log_entry->handler_name) < global_ddl_log.name_len);
1164
strmake(&file_entry_buf[DDL_LOG_NAME_POS + (2*global_ddl_log.name_len)],
1165
ddl_log_entry->handler_name, global_ddl_log.name_len - 1);
1166
1166
if (get_free_ddl_log_entry(active_entry, &write_header))
1168
1168
DBUG_RETURN(TRUE);
1171
1171
DBUG_PRINT("ddl_log",
1172
1172
("write type %c next %u name '%s' from_name '%s' handler '%s'",
1173
(char) global_ddl_log.file_entry_buf[DDL_LOG_ACTION_TYPE_POS],
1173
(char) file_entry_buf[DDL_LOG_ACTION_TYPE_POS],
1174
1174
ddl_log_entry->next_entry,
1175
(char*) &global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS],
1176
(char*) &global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS
1178
(char*) &global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS
1180
if (write_ddl_log_file_entry((*active_entry)->entry_pos))
1175
(char*) &file_entry_buf[DDL_LOG_NAME_POS],
1176
(char*) &file_entry_buf[DDL_LOG_NAME_POS +
1177
global_ddl_log.name_len],
1178
(char*) &file_entry_buf[DDL_LOG_NAME_POS +
1179
(2*global_ddl_log.name_len)]));
1180
if (write_ddl_log_file_entry((uchar*) file_entry_buf,
1181
(*active_entry)->entry_pos, IO_SIZE))
1183
1184
sql_print_error("Failed to write entry_no = %u",
1227
1228
DDL_LOG_MEMORY_ENTRY **active_entry)
1229
1230
bool write_header= FALSE;
1230
char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
1231
char file_entry_buf[IO_SIZE];
1231
1232
DBUG_ENTER("write_execute_ddl_log_entry");
1233
1234
if (init_ddl_log())
1235
1236
DBUG_RETURN(TRUE);
1238
memset(file_entry_buf, 0, sizeof(file_entry_buf));
1249
1251
file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]= (char)DDL_IGNORE_LOG_ENTRY_CODE;
1250
file_entry_buf[DDL_LOG_ACTION_TYPE_POS]= 0; /* Ignored for execute entries */
1251
file_entry_buf[DDL_LOG_PHASE_POS]= 0;
1252
1252
int4store(&file_entry_buf[DDL_LOG_NEXT_ENTRY_POS], first_entry);
1253
file_entry_buf[DDL_LOG_NAME_POS]= 0;
1254
file_entry_buf[DDL_LOG_NAME_POS + FN_LEN]= 0;
1255
file_entry_buf[DDL_LOG_NAME_POS + 2*FN_LEN]= 0;
1256
1253
if (!(*active_entry))
1258
1255
if (get_free_ddl_log_entry(active_entry, &write_header))
1306
1305
bool deactivate_ddl_log_entry(uint entry_no)
1308
char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
1307
uchar file_entry_buf[DDL_LOG_NAME_POS];
1309
1308
DBUG_ENTER("deactivate_ddl_log_entry");
1311
if (!read_ddl_log_file_entry(entry_no))
1312
Only need to read and write the first bytes of the entry, where
1313
ENTRY_TYPE, ACTION_TYPE and PHASE reside. Using DDL_LOG_NAME_POS
1314
to include all info except for the names.
1316
if (!read_ddl_log_file_entry(file_entry_buf, entry_no, DDL_LOG_NAME_POS))
1313
1318
if (file_entry_buf[DDL_LOG_ENTRY_TYPE_POS] == DDL_LOG_ENTRY_CODE)
1417
1423
DDL_LOG_ENTRY ddl_log_entry;
1418
1424
uint read_entry= first_entry;
1425
uchar file_entry_buf[IO_SIZE];
1419
1426
DBUG_ENTER("execute_ddl_log_entry");
1421
1428
mysql_mutex_lock(&LOCK_gdl);
1424
if (read_ddl_log_entry(read_entry, &ddl_log_entry))
1431
if (read_ddl_log_file_entry(file_entry_buf, read_entry, IO_SIZE))
1426
/* Write to error log and continue with next log entry */
1433
/* Print the error to the log and continue with next log entry */
1427
1434
sql_print_error("Failed to read entry = %u from ddl log",
1438
set_ddl_log_entry_from_buf(read_entry, file_entry_buf, &ddl_log_entry);
1431
1439
DBUG_ASSERT(ddl_log_entry.entry_type == DDL_LOG_ENTRY_CODE ||
1432
1440
ddl_log_entry.entry_type == DDL_IGNORE_LOG_ENTRY_CODE);
1434
1442
if (execute_ddl_log_action(thd, &ddl_log_entry))
1436
/* Write to error log and continue with next log entry */
1444
/* Print the error to the log and continue with next log entry */
1437
1445
sql_print_error("Failed to execute action for entry = %u from ddl log",
1478
1486
uint num_entries, i;
1480
1488
DDL_LOG_ENTRY ddl_log_entry;
1489
uchar *file_entry_buf;
1481
1491
char file_name[FN_REFLEN];
1482
1492
DBUG_ENTER("execute_ddl_log_recovery");
1485
1495
Initialise global_ddl_log struct
1487
bzero(global_ddl_log.file_entry_buf, sizeof(global_ddl_log.file_entry_buf));
1488
1497
global_ddl_log.inited= FALSE;
1489
1498
global_ddl_log.recovery_phase= TRUE;
1490
1499
global_ddl_log.io_size= IO_SIZE;
1499
1508
thd->store_globals();
1501
1510
num_entries= read_ddl_log_header();
1511
io_size= global_ddl_log.io_size;
1512
file_entry_buf= (uchar*) my_malloc(io_size, MYF(0));
1513
if (!file_entry_buf)
1515
sql_print_error("Failed to allocate buffer for recover ddl log");
1502
1518
for (i= 1; i < num_entries + 1; i++)
1504
if (read_ddl_log_entry(i, &ddl_log_entry))
1520
if (read_ddl_log_file_entry(file_entry_buf, i, io_size))
1506
1522
sql_print_error("Failed to read entry no = %u from ddl log",
1527
set_ddl_log_entry_from_buf(i, file_entry_buf, &ddl_log_entry);
1510
1528
if (ddl_log_entry.entry_type == DDL_LOG_EXECUTE_CODE)
1512
1530
if (execute_ddl_log_entry(thd, ddl_log_entry.next_entry))
1538
1557
void release_ddl_log()
1540
DDL_LOG_MEMORY_ENTRY *free_list= global_ddl_log.first_free;
1541
DDL_LOG_MEMORY_ENTRY *used_list= global_ddl_log.first_used;
1559
DDL_LOG_MEMORY_ENTRY *free_list;
1560
DDL_LOG_MEMORY_ENTRY *used_list;
1542
1561
DBUG_ENTER("release_ddl_log");
1544
1563
if (!global_ddl_log.do_release)
1545
1564
DBUG_VOID_RETURN;
1547
1566
mysql_mutex_lock(&LOCK_gdl);
1567
free_list= global_ddl_log.first_free;
1568
used_list= global_ddl_log.first_used;
1548
1569
while (used_list)
1550
1571
DDL_LOG_MEMORY_ENTRY *tmp= used_list->next_log_entry;