329
void write_bin_log(Session *session, bool,
328
void write_bin_log(Session *session,
330
329
char const *query, size_t query_length)
332
331
ReplicationServices &replication_services= ReplicationServices::singleton();
336
/* Should should be refactored to go away */
337
static void write_bin_log_drop_table(Session *session, bool if_exists, const char *db_name, const char *table_name)
339
ReplicationServices &replication_services= ReplicationServices::singleton();
343
built_query.append("DROP Table IF EXISTS ");
345
built_query.append("DROP Table ");
347
built_query.append("`");
348
if (session->db == NULL || strcmp(db_name ,session->db) != 0)
350
built_query.append(db_name);
351
built_query.append("`.`");
354
built_query.append(table_name);
355
built_query.append("`");
356
replication_services.rawStatement(session, built_query.c_str(), built_query.length());
338
361
delete (drop) tables.
381
404
LOCK_open during wait_if_global_read_lock(), other threads could not
382
405
close their tables. This would make a pretty deadlock.
384
error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary, 0);
407
error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary, false);
386
409
if (need_start_waiting)
387
410
start_waiting_global_read_lock(session);
402
425
if_exists If set, don't give an error if table doesn't exists.
403
426
In this case we give an warning of level 'NOTE'
404
427
drop_temporary Only drop temporary tables
405
drop_view Allow to delete VIEW .frm
406
428
dont_log_query Don't write query to log files. This will also not
407
429
generate warnings if the handler files doesn't exists
430
452
uint32_t path_length= 0;
431
453
String wrong_tables;
433
int non_temp_tables_count= 0;
434
bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0;
439
built_query.set_charset(system_charset_info);
441
built_query.append("DROP Table IF EXISTS ");
443
built_query.append("DROP Table ");
455
bool foreign_key_error= false;
446
457
pthread_mutex_lock(&LOCK_open); /* Part 2 of rm a table */
492
If row-based replication is used and the table is not a
493
temporary table, we add the table name to the drop statement
494
being built. The string always end in a comma and the comma
495
will be chopped off before being written to the binary log.
499
non_temp_tables_count++;
501
Don't write the database name if it is the current one (or if
502
session->db is NULL).
504
built_query.append("`");
505
if (session->db == NULL || strcmp(db,session->db) != 0)
507
built_query.append(db);
508
built_query.append("`.`");
511
built_query.append(table->table_name);
512
built_query.append("`,");
515
501
table_type= table->db_type;
516
502
if (!drop_temporary)
535
521
/* remove .frm file and engine files */
536
522
path_length= build_table_filename(path, sizeof(path), db, table->table_name, table->internal_tmp_table);
538
525
if (drop_temporary ||
539
526
((table_type == NULL
540
527
&& (plugin::StorageEngine::getTableProto(path, NULL) != EEXIST))))
552
539
error= plugin::StorageEngine::deleteTable(session, path, db,
553
540
table->table_name,
554
541
! dont_log_query);
555
if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) &&
542
if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && if_exists)
559
545
session->clear_error();
561
548
if (error == HA_ERR_ROW_IS_REFERENCED)
563
550
/* the table is referenced by a foreign key constraint */
568
some_tables_deleted=1;
551
foreign_key_error= true;
555
if (error == 0 || (if_exists && foreign_key_error == false))
556
write_bin_log_drop_table(session, if_exists, db, table->table_name);
573
560
if (wrong_tables.length())
596
if (some_tables_deleted || tmp_table_deleted || !error)
600
if ((non_temp_tables_count > 0 && !tmp_table_deleted))
603
In this case, we are either using statement-based
604
replication or using row-based replication but have only
605
deleted one or more non-temporary tables (and no temporary
606
tables). In this case, we can write the original query into
609
write_bin_log(session, !error, session->query, session->query_length);
611
else if (non_temp_tables_count > 0 &&
615
In this case we have deleted both temporary and
616
non-temporary tables, so:
617
- since we have deleted a non-temporary table we have to
618
binlog the statement, but
619
- since we have deleted a temporary table we cannot binlog
620
the statement (since the table has not been created on the
621
slave, this might cause the slave to stop).
623
Instead, we write a built statement, only containing the
624
non-temporary tables, to the binary log
626
built_query.chop(); // Chop of the last comma
627
built_query.append(" /* generated by server */");
628
write_bin_log(session, !error, built_query.ptr(), built_query.length());
631
The remaining cases are:
632
- no tables where deleted and
633
- only temporary tables where deleted and row-based
635
In both these cases, nothing should be written to the binary
640
583
pthread_mutex_lock(&LOCK_open); /* final bit in rm table lock */
641
584
err_with_placeholders:
642
585
unlock_table_names(tables, NULL);
1828
1771
if (!internal_tmp_table &&
1829
1772
((!(create_info->options & HA_LEX_CREATE_TMP_TABLE))))
1830
write_bin_log(session, true, session->query, session->query_length);
1773
write_bin_log(session, session->query, session->query_length);
1832
1775
unlock_and_end:
1833
1776
pthread_mutex_unlock(&LOCK_open);
2606
2549
int result= store_create_info(table, &query, create_info);
2608
2551
assert(result == 0); // store_create_info() always return 0
2609
write_bin_log(session, true, query.ptr(), query.length());
2552
write_bin_log(session, query.ptr(), query.length());
2612
write_bin_log(session, true, session->query, session->query_length);
2555
write_bin_log(session, session->query, session->query_length);