27
27
#include <drizzled/server_includes.h>
28
28
#include <drizzled/replication/replication.h>
29
29
#include <libdrizzle/libdrizzle.h>
30
#include <drizzled/replicator.h>
30
31
#include <mysys/hash.h>
31
32
#include <drizzled/replication/rli.h>
488
492
Query_log_event qev(session, STRING_WITH_LEN("COMMIT"), true, false);
489
493
qev.error_code= 0; // see comment in DRIZZLE_LOG::write(Session, IO_CACHE)
494
/* TODO: Fix return type */
495
(void)replicator_end_transaction(session, all, true);
490
496
int error= binlog_end_trans(session, trx_data, &qev, all);
546
552
error= binlog_end_trans(session, trx_data, 0, all);
555
/* TODO: Fix return type */
556
(void)replicator_end_transaction(session, all, false);
575
585
static int binlog_savepoint_set(handlerton *, Session *session, void *sv)
587
(void)replicator_savepoint_set(session, sv);
577
588
binlog_trans_log_savepos(session, (my_off_t*) sv);
578
589
/* Write it to the binary log */
586
597
static int binlog_savepoint_rollback(handlerton *, Session *session, void *sv)
589
601
Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
590
602
non-transactional table. Otherwise, truncate the binlog cache starting
597
609
session->binlog_query(Session::STMT_QUERY_TYPE,
598
session->query, session->query_length, true, false);
610
session->query, session->query_length, true, false);
601
613
binlog_trans_log_truncate(session, *(my_off_t*)sv);
616
error= replicator_rollback_to_savepoint(session, sv);
2141
Function to start a statement and optionally a transaction for the
2145
binlog_start_trans_and_stmt()
2149
This function does three things:
2150
- Start a transaction if not in autocommit mode or if a BEGIN
2151
statement has been seen.
2153
- Start a statement transaction to allow us to truncate the binary
2156
- Save the currrent binlog position so that we can roll back the
2157
statement by truncating the transaction log.
2159
We only update the saved position if the old one was undefined,
2160
the reason is that there are some cases (e.g., for CREATE-SELECT)
2161
where the position is saved twice (e.g., both in
2162
select_create::prepare() and Session::binlog_write_table_map()) , but
2163
we should use the first. This means that calls to this function
2164
can be used to start the statement before the first table map
2165
event, to include some extra events.
2169
Session::binlog_start_trans_and_stmt()
2171
binlog_trx_data *trx_data= (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2173
if (trx_data == NULL ||
2174
trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
2176
this->binlog_set_stmt_begin();
2177
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
2178
trans_register_ha(this, true, binlog_hton);
2179
trans_register_ha(this, false, binlog_hton);
2181
Mark statement transaction as read/write. We never start
2182
a binary log transaction and keep it read-only,
2183
therefore it's best to mark the transaction read/write just
2184
at the same time we start it.
2185
Not necessary to mark the normal transaction read/write
2186
since the statement-level flag will be propagated automatically
2187
inside ha_commit_trans.
2189
ha_data[binlog_hton->slot].ha_info[0].set_trx_read_write();
2194
2156
void Session::binlog_set_stmt_begin() {
2195
2157
binlog_trx_data *trx_data=
2196
2158
(binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2212
Write a table map to the binary log.
2215
int Session::binlog_write_table_map(Table *table, bool is_trans)
2219
/* Pre-conditions */
2220
assert(table->s->table_map_id != UINT32_MAX);
2222
Table_map_log_event::flag_set const
2223
flags= Table_map_log_event::TM_NO_FLAGS;
2226
the_event(this, table, table->s->table_map_id, is_trans, flags);
2228
if (is_trans && binlog_table_maps == 0)
2229
binlog_start_trans_and_stmt();
2231
if ((error= drizzle_bin_log.write(&the_event)))
2234
binlog_table_maps++;
2235
table->s->table_map_version= drizzle_bin_log.table_map_version();
2239
2173
Rows_log_event*
2240
2174
Session::binlog_get_pending_rows_event() const
3618
3550
Xid_log_event xle(session, xid);
3619
3551
binlog_trx_data *trx_data=
3620
3552
(binlog_trx_data*) session_get_ha_data(session, binlog_hton);
3553
/* TODO: Fix return type */
3554
(void)replicator_end_transaction(session, true, true);
3622
3556
We always commit the entire transaction when writing an XID. Also
3623
3557
note that the return value is inverted.