Skip to content

Commit 26ec19d

Browse files
yoshinorimGunnar Kudrjavets
authored andcommitted
Reject binlog_format!=ROW from non-SQL threads in MyRocks (mysql#109)
Summary: MyRocks doesn't support next-key locking so binlog_format!=ROW may cause data inconsistency. On 5.6 slaves, binlog_format!=ROW is fine because no concurrent access to the same table is guaranteed. This diff changes as below. - Rejecting updates (locking reads, including SELECT FOR UPDATE) on master - No behavior changes on slave - No behavior changes if binlog was disabled on the session - Added a new session variable rocksdb_unsafe_for_binlog to optionally allow writing with statement based binary logging Test Plan: mtr, new test case rpl_statement Reviewers: spetrunia, hermanlee4, jkedgar, santoshb Reviewed By: santoshb Subscribers: webscalesql-eng Differential Revision: https://reviews.facebook.net/D51231 Differential Revision: https://reviews.facebook.net/D51489 Differential Revision: https://reviews.facebook.net/D51555 Differential Revision: https://reviews.facebook.net/D51597
1 parent 1d38131 commit 26ec19d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

storage/rocksdb/ha_rocksdb.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ static MYSQL_THDVAR_BOOL(skip_fill_cache,
667667
"Skip filling block cache on read requests",
668668
NULL, NULL, FALSE);
669669

670+
static MYSQL_THDVAR_BOOL(unsafe_for_binlog,
671+
PLUGIN_VAR_RQCMDARG,
672+
"Allowing statement based binary logging which may break consistency",
673+
nullptr, nullptr, FALSE);
674+
670675
static MYSQL_THDVAR_UINT(records_in_range,
671676
PLUGIN_VAR_RQCMDARG,
672677
"Used to override the result of records_in_range(). Set to a positive number to override",
@@ -861,6 +866,7 @@ static struct st_mysql_sys_var* rocksdb_system_variables[]= {
861866
MYSQL_SYSVAR(write_ignore_missing_column_families),
862867

863868
MYSQL_SYSVAR(skip_fill_cache),
869+
MYSQL_SYSVAR(unsafe_for_binlog),
864870

865871
MYSQL_SYSVAR(records_in_range),
866872
MYSQL_SYSVAR(debug_optimizer_n_rows),
@@ -5622,6 +5628,21 @@ int ha_rocksdb::external_lock(THD *thd, int lock_type)
56225628
{
56235629
int res= 0;
56245630
DBUG_ENTER("ha_rocksdb::external_lock");
5631+
5632+
int binlog_format= thd_binlog_format(thd);
5633+
bool unsafe_for_binlog= THDVAR(ha_thd(), unsafe_for_binlog);
5634+
if (lock_type == F_WRLCK && !thd->rli_slave &&
5635+
!unsafe_for_binlog &&
5636+
binlog_format != BINLOG_FORMAT_ROW &&
5637+
binlog_format != BINLOG_FORMAT_UNSPEC &&
5638+
thd_binlog_filter_ok(thd))
5639+
{
5640+
my_printf_error(ER_UNKNOWN_ERROR,
5641+
"Can't execute updates on master with binlog_format != ROW.",
5642+
MYF(0));
5643+
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
5644+
}
5645+
56255646
io_perf_start();
56265647

56275648
if (lock_type == F_UNLCK)

storage/rocksdb/ha_rocksdb.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,32 @@ inline bool looks_like_per_index_cf_typo(const char *name)
6767
extern PSI_stage_info stage_waiting_on_row_lock;
6868

6969
extern "C"
70+
{
7071
void thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond, mysql_mutex_t *mutex,
7172
const PSI_stage_info *stage, PSI_stage_info *old_stage);
72-
extern "C"
7373
void thd_exit_cond(MYSQL_THD thd, const PSI_stage_info *stage);
7474

7575
/**
7676
Mark transaction to rollback and mark error as fatal to a sub-statement.
7777
@param thd Thread handle
7878
@param all TRUE <=> rollback main transaction.
7979
*/
80-
extern "C"
8180
void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all);
8281

82+
/**
83+
* Get the user thread's binary logging format
84+
* @param thd user thread
85+
* @return Value to be used as index into the binlog_format_names array
86+
*/
87+
int thd_binlog_format(const MYSQL_THD thd);
88+
89+
/**
90+
* Check if binary logging is filtered for thread's current db.
91+
* @param thd Thread handle
92+
* @retval 1 the query is not filtered, 0 otherwise.
93+
*/
94+
bool thd_binlog_filter_ok(const MYSQL_THD thd);
95+
}
8396

8497
//#endif
8598

0 commit comments

Comments
 (0)