Skip to content

Commit

Permalink
Skipping transaction API cause delete row fail to find key
Browse files Browse the repository at this point in the history
Upstream commit ID: facebook/mysql-5.6@6bd68a8
PS-8951: Merge percona-202305 (https://jira.percona.com/browse/PS-8951)

Summary:
When replica use skip transaction API(rpl_skip_tx_api=1) and try to delete a row with unique key, It will fail with key not found error and cause replication break.

From code, ha_rocksdb::delete_row() call ha_rocksdb::get_for_update() to check uniqueness. the key slice passed in ha_rocksdb::get_for_update() doesn't include extended fields and myrocks unique key stored in rocksdb always contain extended fields, rocksdb couldn't find the key without extended fields.

The delete row will pass if using transaction API, since in transaction API, if value parameter in get_for_update() is nullptr, skip get its value(see https://github.com/facebook/rocksdb/blob/main/utilities/transactions/transaction_base.cc#L309).

The change is to following transaction API behavior, skip call get its value if value parameter in get_for_update() is nullptr.

Differential Revision: D47338818

fbshipit-source-id: 8f953f4a899213a0367bb7afbc22b2744e127c4f
  • Loading branch information
Luqun Lou authored and inikep committed Jan 17, 2024
1 parent 72b8f0b commit a619e9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions mysql-test/suite/rocksdb/r/trx_info_rpl.result
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the connection metadata repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START REPLICA; see the 'START REPLICA Syntax' in the MySQL Manual for more information.
[connection master]
[connection master]
create table t1 (a int, b int, primary key (a), unique key (b)) engine=rocksdb;
[connection slave]
show variables like 'rocksdb_rpl_skip_tx_api';
Variable_name Value
rocksdb_rpl_skip_tx_api ON
include/start_slave.inc
found
[connection master]
delete from t1 where a = 1;
include/sync_slave_sql_with_master.inc
[connection master]
DROP TABLE t1;
include/rpl_end.inc
14 changes: 11 additions & 3 deletions mysql-test/suite/rocksdb/t/trx_info_rpl.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
--let rpl_skip_start_slave=1

--source include/master-slave.inc
--source include/count_sessions.inc

connection master;
--source include/rpl_connection_master.inc
create table t1 (a int, b int, primary key (a), unique key (b)) engine=rocksdb;
--disable_query_log
--let $aa= 0
Expand All @@ -15,7 +16,7 @@ while ($aa < 1000) {
}
--enable_query_log

connection slave;
--source include/rpl_connection_slave.inc
show variables like 'rocksdb_rpl_skip_tx_api';
--source include/start_slave.inc

Expand All @@ -36,6 +37,13 @@ let $count= query_get_value(select count(*) as Value from information_schema.roc
--inc $it
}

connection master;
--source include/rpl_connection_master.inc
delete from t1 where a = 1;
--source include/sync_slave_sql_with_master.inc


--source include/rpl_connection_master.inc
DROP TABLE t1;

--source include/rpl_end.inc
--source include/wait_until_count_sessions.inc
8 changes: 4 additions & 4 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4985,10 +4985,10 @@ class Rdb_writebatch_impl : public Rdb_transaction {

rocksdb::ColumnFamilyHandle *const column_family = key_descr.get_cf();
if (value == nullptr) {
rocksdb::PinnableSlice pin_val;
rocksdb::Status s = get(column_family, key, &pin_val);
pin_val.Reset();
return s;
// minic tranaction API get_for_update() behavior:
// if value isn't nullptr, get_for_update() will lock and fetch value
// if value is nullptr, get_for_update will only lock
return rocksdb::Status::OK();
}

return get(column_family, key, value);
Expand Down

0 comments on commit a619e9e

Please sign in to comment.