4285
4286
- table is not mysql.event
4288
static bool check_table_binlog_row_based(Session *session, Table *table)
4290
if (table->s->cached_row_logging_check == -1)
4292
int const check(table->s->tmp_table == NO_TMP_TABLE);
4293
table->s->cached_row_logging_check= check;
4296
assert(table->s->cached_row_logging_check == 0 ||
4297
table->s->cached_row_logging_check == 1);
4299
return (table->s->cached_row_logging_check &&
4300
(session->options & OPTION_BIN_LOG) &&
4301
drizzle_bin_log.is_open());
4306
Write table maps for all (manually or automatically) locked tables
4309
This function will generate and write table maps for all tables
4310
that are locked by the thread 'session'. Either manually locked
4311
(stored in Session::locked_tables) and automatically locked (stored
4312
in Session::lock) are considered.
4314
@param session Pointer to Session structure
4317
@retval 1 Failed to write all table maps
4321
Session::locked_tables
4324
static int write_locked_table_maps(Session *session)
4326
if (session->get_binlog_table_maps() == 0)
4328
DRIZZLE_LOCK *locks[3];
4329
locks[0]= session->extra_lock;
4330
locks[1]= session->lock;
4331
locks[2]= session->locked_tables;
4332
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4334
DRIZZLE_LOCK const *const lock= locks[i];
4338
Table **const end_ptr= lock->table + lock->table_count;
4339
for (Table **table_ptr= lock->table ;
4340
table_ptr != end_ptr ;
4343
Table *const table= *table_ptr;
4344
if (table->current_lock == F_WRLCK &&
4345
check_table_binlog_row_based(session, table))
4347
int const has_trans= table->file->has_transactions();
4348
int const error= session->binlog_write_table_map(table, has_trans);
4350
If an error occurs, it is the responsibility of the caller to
4351
roll back the transaction.
4353
if (unlikely(error))
4363
4289
typedef bool Log_func(Session*, Table*, bool, const unsigned char*, const unsigned char*);
4365
4291
static int binlog_log_row(Table* table,
4366
4292
const unsigned char *before_record,
4367
const unsigned char *after_record,
4293
const unsigned char *after_record)
4370
if (table->no_replicate)
4374
4296
Session *const session= table->in_use;
4376
if (check_table_binlog_row_based(session, table))
4379
If there are no table maps written to the binary log, this is
4380
the first row handled in this statement. In that case, we need
4381
to write table maps for all locked tables to the binary log.
4383
if (likely(!(error= write_locked_table_maps(session))))
4385
bool const has_trans= table->file->has_transactions();
4386
error= (*log_func)(session, table, has_trans, before_record, after_record);
4298
if (table->no_replicate)
4301
if (session->getReplicationData() == NULL)
4303
error= replicator_session_init(session);
4306
switch (session->lex->sql_command)
4308
case SQLCOM_REPLACE:
4310
case SQLCOM_REPLACE_SELECT:
4311
case SQLCOM_INSERT_SELECT:
4312
error= replicator_write_row(session, table);
4316
case SQLCOM_UPDATE_MULTI:
4317
error= replicator_update_row(session, table, before_record, after_record);
4321
case SQLCOM_DELETE_MULTI:
4322
error= replicator_delete_row(session, table);
4390
4329
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
4436
4375
int handler::ha_write_row(unsigned char *buf)
4439
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
4440
4378
DRIZZLE_INSERT_ROW_START();
4442
4380
mark_trx_read_write();
4444
4382
if (unlikely(error= write_row(buf)))
4446
if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
4384
if (unlikely(error= binlog_log_row(table, 0, buf)))
4447
4385
return(error); /* purecov: inspected */
4448
4386
DRIZZLE_INSERT_ROW_END();