2519
2533
Check if the conditions for row-based binlogging is correct for the table.
2521
2535
A row in the given table should be replicated if:
2522
- Row-based replication is enabled in the current thread
2523
- The binlog is enabled
2524
2536
- It is not a temporary table
2525
- The binary log is open
2526
- The database the table resides in shall be binlogged (binlog_*_db rules)
2527
- table is not mysql.event
2530
2539
static bool log_row_for_replication(Table* table,
2531
const unsigned char *before_record,
2532
const unsigned char *after_record)
2540
const unsigned char *before_record,
2541
const unsigned char *after_record)
2534
2543
ReplicationServices &replication_services= ReplicationServices::singleton();
2535
2544
Session *const session= table->in_use;
2546
if (table->s->tmp_table || ! replication_services.isActive())
2537
2549
switch (session->lex->sql_command)
2539
2551
case SQLCOM_REPLACE:
2552
case SQLCOM_REPLACE_SELECT:
2554
* This is a total hack because of the code that is
2555
* in write_record() in sql_insert.cc. During
2556
* a REPLACE statement, a call to ha_write_row() is
2557
* called. If it fails, then a call to ha_delete_row()
2558
* is called, followed by a repeat of the original
2559
* call to ha_write_row(). So, log_row_for_replication
2560
* could be called either once or twice for a REPLACE
2561
* statement. The below looks at the values of before_record
2562
* and after_record to determine which call to this
2563
* function is for the delete or the insert, since NULL
2564
* is passed for after_record for the delete and NULL is
2565
* passed for before_record for the insert...
2567
* In addition, there is an optimization that allows an
2568
* engine to convert the above delete + insert into an
2569
* update, so we must also check for this case below...
2571
if (after_record == NULL)
2573
replication_services.deleteRecord(session, table);
2575
* We set the "current" statement message to NULL. This triggers
2576
* the replication services component to generate a new statement
2577
* message for the inserted record which will come next.
2579
replication_services.finalizeStatement(*session->getStatementMessage(), session);
2583
if (before_record == NULL)
2584
replication_services.insertRecord(session, table);
2586
replication_services.updateRecord(session, table, before_record, after_record);
2540
2589
case SQLCOM_INSERT:
2541
case SQLCOM_REPLACE_SELECT:
2542
2590
case SQLCOM_INSERT_SELECT:
2543
case SQLCOM_CREATE_TABLE:
2544
replication_services.insertRecord(session, table);
2592
* The else block below represents an
2593
* INSERT ... ON DUPLICATE KEY UPDATE that
2594
* has hit a key conflict and actually done
2597
if (before_record == NULL)
2598
replication_services.insertRecord(session, table);
2600
replication_services.updateRecord(session, table, before_record, after_record);
2547
2603
case SQLCOM_UPDATE: