Skip to content

Commit 429f635

Browse files
FooBarriorvuvova
authored andcommitted
MDEV-16329 [2/5] refactor binlog and cache_mngr
pump up binlog and cache manager to level of binlog_log_row_internal
1 parent 0dfbb05 commit 429f635

File tree

8 files changed

+162
-136
lines changed

8 files changed

+162
-136
lines changed

sql/handler.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7249,16 +7249,28 @@ int handler::binlog_log_row(TABLE *table,
72497249
const uchar *after_record,
72507250
Log_func *log_func)
72517251
{
7252-
bool error;
72537252
THD *thd= table->in_use;
72547253
DBUG_ENTER("binlog_log_row");
72557254

72567255
if (!thd->binlog_table_maps &&
72577256
thd->binlog_write_table_maps())
72587257
DBUG_RETURN(HA_ERR_RBR_LOGGING_FAILED);
72597258

7260-
error= (*log_func)(thd, table, row_logging_has_trans,
7261-
before_record, after_record);
7259+
DBUG_ASSERT(thd->is_current_stmt_binlog_format_row());
7260+
DBUG_ASSERT((WSREP_NNULL(thd) && wsrep_emulate_bin_log)
7261+
|| mysql_bin_log.is_open());
7262+
7263+
auto *cache_mngr= thd->binlog_setup_trx_data();
7264+
if (cache_mngr == NULL)
7265+
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
7266+
7267+
bool is_trans= row_logging_has_trans;
7268+
/* Ensure that all events in a GTID group are in the same cache */
7269+
if (thd->variables.option_bits & OPTION_GTID_BEGIN)
7270+
is_trans= 1;
7271+
7272+
bool error= (*log_func)(thd, table, &mysql_bin_log, cache_mngr,
7273+
is_trans, before_record, after_record);
72627274
DBUG_RETURN(error ? HA_ERR_RBR_LOGGING_FAILED : 0);
72637275
}
72647276

sql/handler.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,11 @@ given at all. */
654654
#define HA_CREATE_PRINT_ALL_OPTIONS (1UL << 26)
655655

656656
typedef ulonglong alter_table_operations;
657-
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
657+
658+
class MYSQL_BIN_LOG;
659+
class binlog_cache_mngr;
660+
typedef bool Log_func(THD*, TABLE*, MYSQL_BIN_LOG *, binlog_cache_mngr *, bool,
661+
const uchar*, const uchar*);
658662

659663
/*
660664
These flags are set by the parser and describes the type of
@@ -5623,11 +5627,6 @@ inline const LEX_CSTRING *table_case_name(HA_CREATE_INFO *info, const LEX_CSTRIN
56235627
return ((lower_case_table_names == 2 && info->alias.str) ? &info->alias : name);
56245628
}
56255629

5626-
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
5627-
int binlog_log_row(TABLE* table,
5628-
const uchar *before_record,
5629-
const uchar *after_record,
5630-
Log_func *log_func);
56315630

56325631
/**
56335632
@def MYSQL_TABLE_IO_WAIT

sql/log.cc

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ binlog_truncate_trx_cache(THD *thd, binlog_cache_mngr *cache_mngr, bool all)
20882088
else
20892089
cache_mngr->trx_cache.restore_prev_position();
20902090

2091-
DBUG_ASSERT(thd->binlog_get_pending_rows_event(is_transactional) == NULL);
2091+
DBUG_ASSERT(cache_mngr->trx_cache.pending() == NULL);
20922092
DBUG_RETURN(error);
20932093
}
20942094

@@ -6309,30 +6309,51 @@ binlog_cache_mngr *THD::binlog_get_cache_mngr() const
63096309
is @c true, the pending event is returned from the transactional cache.
63106310
Otherwise from the non-transactional cache.
63116311
6312-
@param is_transactional @c true indicates a transactional cache,
6312+
@param cache_mngr cache manager to return pending row from
6313+
@param use_trans_cache @c true indicates a transactional cache,
63136314
otherwise @c false a non-transactional.
63146315
@return
63156316
The row event if any.
63166317
*/
6317-
Rows_log_event*
6318-
THD::binlog_get_pending_rows_event(bool is_transactional) const
6318+
Rows_log_event* binlog_get_pending_rows_event(binlog_cache_mngr *cache_mngr,
6319+
bool use_trans_cache)
63196320
{
63206321
Rows_log_event* rows= NULL;
6321-
binlog_cache_mngr *const cache_mngr= binlog_get_cache_mngr();
63226322

63236323
/*
63246324
This is less than ideal, but here's the story: If there is no cache_mngr,
63256325
prepare_pending_rows_event() has never been called (since the cache_mngr
63266326
is set up there). In that case, we just return NULL.
63276327
*/
63286328
if (cache_mngr)
6329+
rows= cache_mngr->get_binlog_cache_data(use_trans_cache)->pending();
6330+
return rows;
6331+
}
6332+
6333+
int binlog_flush_pending_rows_event(THD *thd, bool stmt_end,
6334+
bool is_transactional,
6335+
MYSQL_BIN_LOG *bin_log,
6336+
binlog_cache_mngr *cache_mngr,
6337+
bool use_trans_cache)
6338+
{
6339+
/*
6340+
Mark the event as the last event of a statement if the stmt_end
6341+
flag is set.
6342+
*/
6343+
int error= 0;
6344+
auto *pending= cache_mngr->get_binlog_cache_data(use_trans_cache)->pending();
6345+
if (pending)
63296346
{
6330-
binlog_cache_data *cache_data=
6331-
cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional));
6347+
if (stmt_end)
6348+
{
6349+
pending->set_flags(Rows_log_event::STMT_END_F);
6350+
thd->reset_binlog_for_next_statement();
6351+
}
63326352

6333-
rows= cache_data->pending();
6353+
error= bin_log->flush_and_set_pending_rows_event(thd, 0, cache_mngr,
6354+
is_transactional);
63346355
}
6335-
return (rows);
6356+
return error;
63366357
}
63376358

63386359
/**
@@ -6342,18 +6363,18 @@ THD::binlog_get_pending_rows_event(bool is_transactional) const
63426363
into the non-transactional cache.
63436364
63446365
@param evt a pointer to the row event.
6345-
@param is_transactional @c true indicates a transactional cache,
6366+
@param use_trans_cache @c true indicates a transactional cache,
63466367
otherwise @c false a non-transactional.
63476368
*/
63486369
void
6349-
THD::binlog_set_pending_rows_event(Rows_log_event* ev, bool is_transactional)
6370+
THD::binlog_set_pending_rows_event(Rows_log_event* ev, bool use_trans_cache)
63506371
{
63516372
binlog_cache_mngr *const cache_mngr= binlog_setup_trx_data();
63526373

63536374
DBUG_ASSERT(cache_mngr);
63546375

63556376
binlog_cache_data *cache_data=
6356-
cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional));
6377+
cache_mngr->get_binlog_cache_data(use_trans_cache);
63576378

63586379
cache_data->set_pending(ev);
63596380
}
@@ -6402,18 +6423,18 @@ MYSQL_BIN_LOG::remove_pending_rows_event(THD *thd, bool is_transactional)
64026423
int
64036424
MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
64046425
Rows_log_event* event,
6426+
binlog_cache_mngr *cache_mngr,
64056427
bool is_transactional)
64066428
{
64076429
DBUG_ENTER("MYSQL_BIN_LOG::flush_and_set_pending_rows_event(event)");
64086430
DBUG_ASSERT(WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open());
64096431
DBUG_PRINT("enter", ("event: %p", event));
64106432

6411-
binlog_cache_mngr *const cache_mngr= thd->binlog_get_cache_mngr();
6412-
64136433
DBUG_ASSERT(cache_mngr);
64146434

6435+
bool should_use_trans_cache= use_trans_cache(thd, is_transactional);
64156436
binlog_cache_data *cache_data=
6416-
cache_mngr->get_binlog_cache_data(use_trans_cache(thd, is_transactional));
6437+
cache_mngr->get_binlog_cache_data(should_use_trans_cache);
64176438

64186439
DBUG_PRINT("info", ("cache_mngr->pending(): %p", cache_data->pending()));
64196440

@@ -6442,7 +6463,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
64426463
delete pending;
64436464
}
64446465

6445-
thd->binlog_set_pending_rows_event(event, is_transactional);
6466+
thd->binlog_set_pending_rows_event(event, should_use_trans_cache);
64466467

64476468
DBUG_RETURN(0);
64486469
}

sql/log.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
725725
#if !defined(MYSQL_CLIENT)
726726

727727
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event,
728+
binlog_cache_mngr *cache_mngr,
728729
bool is_transactional);
729730
int remove_pending_rows_event(THD *thd, bool is_transactional);
730731

@@ -1175,6 +1176,13 @@ File open_binlog(IO_CACHE *log, const char *log_file_name,
11751176
void make_default_log_name(char **out, const char* log_ext, bool once);
11761177
void binlog_reset_cache(THD *thd);
11771178
bool write_annotated_row(THD *thd);
1179+
int binlog_flush_pending_rows_event(THD *thd, bool stmt_end,
1180+
bool is_transactional,
1181+
MYSQL_BIN_LOG *bin_log,
1182+
binlog_cache_mngr *cache_mngr,
1183+
bool use_trans_cache);
1184+
Rows_log_event* binlog_get_pending_rows_event(binlog_cache_mngr *cache_mngr,
1185+
bool use_trans_cache);
11781186

11791187
extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
11801188
extern handlerton *binlog_hton;

sql/log_event.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,13 +4926,16 @@ class Write_rows_log_event : public Rows_log_event
49264926
#endif
49274927
#if defined(MYSQL_SERVER)
49284928
static bool binlog_row_logging_function(THD *thd, TABLE *table,
4929+
MYSQL_BIN_LOG *bin_log,
4930+
binlog_cache_mngr *cache_mngr,
49294931
bool is_transactional,
49304932
const uchar *before_record
49314933
__attribute__((unused)),
49324934
const uchar *after_record)
49334935
{
49344936
DBUG_ASSERT(!table->versioned(VERS_TRX_ID));
4935-
return thd->binlog_write_row(table, is_transactional, after_record);
4937+
return thd->binlog_write_row(table, bin_log, cache_mngr, is_transactional,
4938+
after_record);
49364939
}
49374940
#endif
49384941

@@ -5009,12 +5012,14 @@ class Update_rows_log_event : public Rows_log_event
50095012

50105013
#ifdef MYSQL_SERVER
50115014
static bool binlog_row_logging_function(THD *thd, TABLE *table,
5015+
MYSQL_BIN_LOG *bin_log,
5016+
binlog_cache_mngr *cache_mngr,
50125017
bool is_transactional,
50135018
const uchar *before_record,
50145019
const uchar *after_record)
50155020
{
50165021
DBUG_ASSERT(!table->versioned(VERS_TRX_ID));
5017-
return thd->binlog_update_row(table, is_transactional,
5022+
return thd->binlog_update_row(table, bin_log, cache_mngr, is_transactional,
50185023
before_record, after_record);
50195024
}
50205025
#endif
@@ -5098,13 +5103,15 @@ class Delete_rows_log_event : public Rows_log_event
50985103
#endif
50995104
#ifdef MYSQL_SERVER
51005105
static bool binlog_row_logging_function(THD *thd, TABLE *table,
5106+
MYSQL_BIN_LOG *bin_log,
5107+
binlog_cache_mngr *cache_mngr,
51015108
bool is_transactional,
51025109
const uchar *before_record,
51035110
const uchar *after_record
51045111
__attribute__((unused)))
51055112
{
51065113
DBUG_ASSERT(!table->versioned(VERS_TRX_ID));
5107-
return thd->binlog_delete_row(table, is_transactional,
5114+
return thd->binlog_delete_row(table, bin_log, cache_mngr, is_transactional,
51085115
before_record);
51095116
}
51105117
#endif

0 commit comments

Comments
 (0)