4286
4287
- table is not mysql.event
4289
static bool check_table_binlog_row_based(Session *session, Table *table)
4291
if (table->s->cached_row_logging_check == -1)
4293
int const check(table->s->tmp_table == NO_TMP_TABLE);
4294
table->s->cached_row_logging_check= check;
4297
assert(table->s->cached_row_logging_check == 0 ||
4298
table->s->cached_row_logging_check == 1);
4300
return (table->s->cached_row_logging_check &&
4301
(session->options & OPTION_BIN_LOG) &&
4302
drizzle_bin_log.is_open());
4307
Write table maps for all (manually or automatically) locked tables
4310
This function will generate and write table maps for all tables
4311
that are locked by the thread 'session'. Either manually locked
4312
(stored in Session::locked_tables) and automatically locked (stored
4313
in Session::lock) are considered.
4315
@param session Pointer to Session structure
4318
@retval 1 Failed to write all table maps
4322
Session::locked_tables
4325
static int write_locked_table_maps(Session *session)
4327
if (session->get_binlog_table_maps() == 0)
4329
DRIZZLE_LOCK *locks[3];
4330
locks[0]= session->extra_lock;
4331
locks[1]= session->lock;
4332
locks[2]= session->locked_tables;
4333
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4335
DRIZZLE_LOCK const *const lock= locks[i];
4339
Table **const end_ptr= lock->table + lock->table_count;
4340
for (Table **table_ptr= lock->table ;
4341
table_ptr != end_ptr ;
4344
Table *const table= *table_ptr;
4345
if (table->current_lock == F_WRLCK &&
4346
check_table_binlog_row_based(session, table))
4348
int const has_trans= table->file->has_transactions();
4349
int const error= session->binlog_write_table_map(table, has_trans);
4351
If an error occurs, it is the responsibility of the caller to
4352
roll back the transaction.
4354
if (unlikely(error))
4364
typedef bool Log_func(Session*, Table*, bool, const unsigned char*, const unsigned char*);
4366
static int binlog_log_row(Table* table,
4367
const unsigned char *before_record,
4368
const unsigned char *after_record,
4371
if (table->no_replicate)
4290
static bool binlog_log_row(Table* table,
4291
const unsigned char *before_record,
4292
const unsigned char *after_record)
4375
4295
Session *const session= table->in_use;
4377
if (check_table_binlog_row_based(session, table))
4380
If there are no table maps written to the binary log, this is
4381
the first row handled in this statement. In that case, we need
4382
to write table maps for all locked tables to the binary log.
4297
if (table->no_replicate)
4300
if (session->getReplicationData() == NULL)
4302
error= replicator_session_init(session);
4305
switch (session->lex->sql_command)
4307
case SQLCOM_REPLACE:
4309
case SQLCOM_REPLACE_SELECT:
4310
case SQLCOM_INSERT_SELECT:
4311
error= replicator_write_row(session, table);
4315
case SQLCOM_UPDATE_MULTI:
4316
error= replicator_update_row(session, table, before_record, after_record);
4320
case SQLCOM_DELETE_MULTI:
4321
error= replicator_delete_row(session, table);
4325
For everything else we ignore the event (since it just involves a temp table)
4384
if (likely(!(error= write_locked_table_maps(session))))
4386
bool const has_trans= table->file->has_transactions();
4387
error= (*log_func)(session, table, has_trans, before_record, after_record);
4391
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
4394
4334
int handler::ha_external_lock(Session *session, int lock_type)
4437
4377
int handler::ha_write_row(unsigned char *buf)
4440
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
4441
4380
DRIZZLE_INSERT_ROW_START();
4443
4382
mark_trx_read_write();
4445
4384
if (unlikely(error= write_row(buf)))
4447
if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
4448
return(error); /* purecov: inspected */
4387
if (unlikely(binlog_log_row(table, 0, buf)))
4388
return HA_ERR_RBR_LOGGING_FAILED; /* purecov: inspected */
4449
4390
DRIZZLE_INSERT_ROW_END();
4467
4407
if (unlikely(error= update_row(old_data, new_data)))
4469
if (unlikely(error= binlog_log_row(table, old_data, new_data, log_func)))
4410
if (unlikely(binlog_log_row(table, old_data, new_data)))
4411
return HA_ERR_RBR_LOGGING_FAILED;
4474
4416
int handler::ha_delete_row(const unsigned char *buf)
4477
Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
4479
4420
mark_trx_read_write();
4481
4422
if (unlikely(error= delete_row(buf)))
4483
if (unlikely(error= binlog_log_row(table, buf, 0, log_func)))
4425
if (unlikely(binlog_log_row(table, buf, 0)))
4426
return HA_ERR_RBR_LOGGING_FAILED;