2385
2385
pthread_mutex_unlock(&LOCK_xid_cache);
2389
Implementation of interface to write rows to the binary log through the
2390
thread. The thread is responsible for writing the rows it has
2391
inserted/updated/deleted.
2396
Template member function for ensuring that there is an rows log
2397
event of the apropriate type before proceeding.
2400
- Events of type 'RowEventT' have the type code 'type_code'.
2403
If a non-NULL pointer is returned, the pending event for thread 'session' will
2404
be an event of type 'RowEventT' (which have the type code 'type_code')
2405
will either empty or have enough space to hold 'needed' bytes. In
2406
addition, the columns bitmap will be correct for the row, meaning that
2407
the pending event will be flushed if the columns in the event differ from
2408
the columns suppled to the function.
2411
If no error, a non-NULL pending event (either one which already existed or
2412
the newly created one).
2416
template <class RowsEventT> Rows_log_event*
2417
Session::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
2419
bool is_transactional,
2420
RowsEventT *hint __attribute__((unused)))
2422
/* Pre-conditions */
2423
assert(table->s->table_map_id != UINT32_MAX);
2425
/* Fetch the type code for the RowsEventT template parameter */
2426
int const type_code= RowsEventT::TYPE_CODE;
2429
There is no good place to set up the transactional data, so we
2432
if (binlog_setup_trx_data())
2435
Rows_log_event* pending= binlog_get_pending_rows_event();
2437
if (unlikely(pending && !pending->is_valid()))
2441
Check if the current event is non-NULL and a write-rows
2442
event. Also check if the table provided is mapped: if it is not,
2443
then we have switched to writing to a new table.
2444
If there is no pending event, we need to create one. If there is a pending
2445
event, but it's not about the same table id, or not of the same type
2446
(between Write, Update and Delete), or not the same affected columns, or
2447
going to be too big, flush this event to disk and create a new pending
2450
The last test is necessary for the Cluster injector to work
2451
correctly. The reason is that the Cluster can inject two write
2452
rows with different column bitmaps if there is an insert followed
2453
by an update in the same transaction, and these are grouped into a
2454
single epoch/transaction when fed to the injector.
2456
TODO: Fix the code so that the last test can be removed.
2459
pending->server_id != serv_id ||
2460
pending->get_table_id() != table->s->table_map_id ||
2461
pending->get_type_code() != type_code ||
2462
pending->get_data_size() + needed > opt_binlog_rows_event_max_size ||
2463
!bitmap_cmp(pending->get_cols(), table->write_set))
2465
/* Create a new RowsEventT... */
2466
Rows_log_event* const
2467
ev= new RowsEventT(this, table, table->s->table_map_id,
2471
ev->server_id= serv_id; // I don't like this, it's too easy to forget.
2473
flush the pending event and replace it with the newly created
2476
if (unlikely(drizzle_bin_log.flush_and_set_pending_rows_event(this, ev)))
2482
return(ev); /* This is the new pending event */
2484
return(pending); /* This is the current pending event */
2487
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
2489
Instantiate the versions we need, we have -fno-implicit-template as
2492
template Rows_log_event*
2493
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2494
Write_rows_log_event*);
2496
template Rows_log_event*
2497
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2498
Delete_rows_log_event *);
2500
template Rows_log_event*
2501
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2502
Update_rows_log_event *);
2507
2390
Class to handle temporary allocation of memory for row data.
2619
int Session::binlog_flush_pending_rows_event(bool stmt_end)
2622
We shall flush the pending event even if we are not in row-based
2623
mode: it might be the case that we left row-based mode before
2624
flushing anything (e.g., if we have explicitly locked tables).
2626
if (!drizzle_bin_log.is_open())
2630
Mark the event as the last event of a statement if the stmt_end
2634
if (Rows_log_event *pending= binlog_get_pending_rows_event())
2638
pending->set_flags(Rows_log_event::STMT_END_F);
2639
pending->flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F;
2640
binlog_table_maps= 0;
2643
error= drizzle_bin_log.flush_and_set_pending_rows_event(this, 0);
2649
2501
bool Discrete_intervals_list::append(uint64_t start, uint64_t val,