Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make START TRANSACTION WITH CONSISTENT ROCKSDB SNAPSHOT read only and…
… use DB::GetSnapshot Summary: RocksDB's diff D50475 had a side effect that SingleDelete entries weren't removed if there was a long running transactions opened via RocksDB Transaction API. To prevent this issue, creating a snapshot without using Transaction API is needed, but the transaction has to be read only. Practical use case of the long running transaction is logical backup, which uses START TRANSACTION WITH CONSISTENT ROCKSDB SNAPSHOT. This diff makes the transaction read only, and raising an error if doing any update within the transaction. This restriction has to be documented. @update-submodule: rocksdb Test Plan: mtr, new test case rocksdb.read_only_tx Reviewers: spetrunia, jkedgar, hermanlee4 Reviewed By: hermanlee4 Subscribers: anthony, webscalesql-eng Differential Revision: https://reviews.facebook.net/D51945
- Loading branch information
1 parent
5315d1f
commit c8b0c7a
Showing
8 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
DROP TABLE IF EXISTS t1; | ||
CREATE TABLE t1 (id INT, value int, PRIMARY KEY (id), INDEX (value)) ENGINE=RocksDB; | ||
INSERT INTO t1 VALUES (1,1); | ||
select variable_value into @p from information_schema.global_status where variable_name='rocksdb_number_sst_entry_put'; | ||
select variable_value into @s from information_schema.global_status where variable_name='rocksdb_number_sst_entry_singledelete'; | ||
START TRANSACTION WITH CONSISTENT ROCKSDB SNAPSHOT; | ||
File Position Gtid_executed | ||
master-bin.000001 734 uuid:1-3 | ||
select case when variable_value-@p < 1000 then 'true' else variable_value-@p end from information_schema.global_status where variable_name='rocksdb_number_sst_entry_put'; | ||
case when variable_value-@p < 1000 then 'true' else variable_value-@p end | ||
true | ||
select case when variable_value-@s < 100 then 'true' else variable_value-@s end from information_schema.global_status where variable_name='rocksdb_number_sst_entry_singledelete'; | ||
case when variable_value-@s < 100 then 'true' else variable_value-@s end | ||
true | ||
SELECT * FROM t1; | ||
id value | ||
1 1 | ||
INSERT INTO t1 values (2, 2); | ||
ERROR HY000: Can't execute updates when you started a transaction with START TRANSACTION WITH CONSISTENT [ROCKSDB] SNAPSHOT. | ||
ROLLBACK; | ||
SELECT * FROM t1; | ||
id value | ||
1 10001 | ||
INSERT INTO t1 values (2, 2); | ||
SELECT * FROM t1 ORDER BY id; | ||
id value | ||
1 10001 | ||
2 2 | ||
BEGIN; | ||
SELECT COUNT(*) FROM t1; | ||
COUNT(*) | ||
9998 | ||
COMMIT; | ||
OPTIMIZE TABLE t1; | ||
Table Op Msg_type Msg_text | ||
test.t1 optimize status OK | ||
DROP TABLE t1; | ||
reset master; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--rocksdb_default_cf_options=write_buffer_size=16k --log-bin --binlog_format=row --gtid_mode=ON --enforce_gtid_consistency --log-slave-updates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--source include/have_log_bin.inc | ||
--source include/have_rocksdb.inc | ||
--source include/count_sessions.inc | ||
--disable_warnings | ||
--source include/have_gtid.inc | ||
--enable_warnings | ||
-- let $uuid = `select @@server_uuid;` | ||
|
||
--disable_warnings | ||
DROP TABLE IF EXISTS t1; | ||
--enable_warnings | ||
|
||
connect (con1,localhost,root,,); | ||
connect (con2,localhost,root,,); | ||
|
||
connection con1; | ||
CREATE TABLE t1 (id INT, value int, PRIMARY KEY (id), INDEX (value)) ENGINE=RocksDB; | ||
INSERT INTO t1 VALUES (1,1); | ||
|
||
# Read-only, long-running transaction. SingleDelete/Put shouldn't increase much. | ||
select variable_value into @p from information_schema.global_status where variable_name='rocksdb_number_sst_entry_put'; | ||
select variable_value into @s from information_schema.global_status where variable_name='rocksdb_number_sst_entry_singledelete'; | ||
-- replace_result $uuid uuid | ||
START TRANSACTION WITH CONSISTENT ROCKSDB SNAPSHOT; | ||
|
||
connection con2; | ||
--disable_query_log | ||
let $i = 1; | ||
while ($i <= 10000) { | ||
let $update = UPDATE t1 SET value=value+1 WHERE id=1; | ||
inc $i; | ||
eval $update; | ||
} | ||
--enable_query_log | ||
|
||
connection con1; | ||
select case when variable_value-@p < 1000 then 'true' else variable_value-@p end from information_schema.global_status where variable_name='rocksdb_number_sst_entry_put'; | ||
select case when variable_value-@s < 100 then 'true' else variable_value-@s end from information_schema.global_status where variable_name='rocksdb_number_sst_entry_singledelete'; | ||
SELECT * FROM t1; | ||
--error ER_UNKNOWN_ERROR | ||
INSERT INTO t1 values (2, 2); | ||
ROLLBACK; | ||
SELECT * FROM t1; | ||
INSERT INTO t1 values (2, 2); | ||
SELECT * FROM t1 ORDER BY id; | ||
|
||
# Regular long-running transaction. | ||
# No "Transaction could not check for conflicts for opearation" error should happen. | ||
BEGIN; | ||
|
||
connection con2; | ||
--disable_query_log | ||
let $i = 5; | ||
while ($i <= 10000) { | ||
let $insert = INSERT INTO t1 VALUES ($i, $i); | ||
inc $i; | ||
eval $insert; | ||
} | ||
--enable_query_log | ||
|
||
connection con1; | ||
SELECT COUNT(*) FROM t1; | ||
COMMIT; | ||
|
||
connection default; | ||
disconnect con1; | ||
disconnect con2; | ||
OPTIMIZE TABLE t1; | ||
DROP TABLE t1; | ||
reset master; |
Submodule rocksdb
updated
26 files
+1 −1 | build_tools/rocksdb-lego-determinator | |
+2 −1 | db/builder.cc | |
+1 −0 | db/builder.h | |
+10 −0 | db/compaction_iterator.cc | |
+52 −11 | db/db_impl.cc | |
+24 −7 | db/db_impl.h | |
+4 −2 | db/flush_job.cc | |
+2 −0 | db/flush_job.h | |
+6 −6 | db/flush_job_test.cc | |
+2 −1 | db/repair.cc | |
+1 −1 | db/snapshot_impl.h | |
+3 −1 | db/table_cache.cc | |
+13 −7 | db/version_set.cc | |
+15 −2 | db/version_set.h | |
+6 −0 | include/rocksdb/compaction_filter.h | |
+8 −0 | include/rocksdb/options.h | |
+6 −0 | include/rocksdb/utilities/transaction.h | |
+7 −2 | table/cuckoo_table_reader.cc | |
+21 −5 | table/get_context.cc | |
+20 −2 | table/get_context.h | |
+7 −3 | utilities/transactions/optimistic_transaction_impl.cc | |
+7 −1 | utilities/transactions/transaction_base.h | |
+2 −1 | utilities/transactions/transaction_impl.cc | |
+199 −44 | utilities/transactions/transaction_test.cc | |
+46 −31 | utilities/transactions/transaction_util.cc | |
+8 −3 | utilities/transactions/transaction_util.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters