Skip to content

Commit

Permalink
Enable atomic bulk loading
Browse files Browse the repository at this point in the history
Upstream commit ID : fb-mysql-5.6.35/269d05b0beb761d9f9ba057f12b62b0077a3c4a2
PS-6864 : Merge fb-prod201902

Summary:
Enable atomic bulk loading - bulk loading using SST APIs are now atomic.
You should not observe any in between state if there is any failures in
ingestion (there are some caveats, as usual, that needs to be
investigated/documented).

This change essentially delays all SST ingestion until finish_bulk_load,
and ingest them all in one batch. Care is taken to:
1. Make sure the state management of multiple `Rdb_sst_info` are done
transactionally as well to match the ingestion,
2. Works well with closing connections and ALTER TABLE statement race
conditions (however under race conditions the ingestion are forcefully
interrupted and therefore no longer truly atomic - this needs to be
investigated to see if there are other approaches).
3. Files are properly cleaned up in the failure case

NOTE: I specifically avoided doing refactoring in order to make code
review easier. Finish_bulk_load is becoming too big and that will get
addressed later.

This changes takes advantage of latest
[PR][(facebook/rocksdb#4895) from Yanqin Jin
which supports ingesting SST from multiple column families.

NOTE: This change updates rocksdb to latest commit in the PR and will
update to the proper rocksdb version once the PR is merged and we've
decided on a proper RocksDB version to consume.

update-submodule: rocksdb

fbshipit-source-id: 767c36232b6
  • Loading branch information
yizhang82 authored and oleksandr-kachan committed May 13, 2024
1 parent b5cb7a5 commit 64d3544
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 78 deletions.
11 changes: 11 additions & 0 deletions mysql-test/suite/rocksdb/include/bulk_load.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,26 @@ start transaction with consistent snapshot;
select VALUE > 0 as 'Has opened snapshots' from information_schema.rocksdb_dbstats where stat_type='DB_NUM_SNAPSHOTS';

connection default;

# Update CF to smaller value to create multiple SST in ingestion
eval SET @@GLOBAL.ROCKSDB_UPDATE_CF_OPTIONS=
'$pk_cf_name={write_buffer_size=8m;target_file_size_base=1m};';

set rocksdb_bulk_load=1;
set rocksdb_bulk_load_size=100000;
--disable_query_log
--echo LOAD DATA INFILE <input_file> INTO TABLE t1;
eval LOAD DATA INFILE '$file' INTO TABLE t1;
# There should be no SST being ingested
select * from t1;
--echo LOAD DATA INFILE <input_file> INTO TABLE t2;
eval LOAD DATA INFILE '$file' INTO TABLE t2;
# There should be no SST being ingested
select * from t2;
--echo LOAD DATA INFILE <input_file> INTO TABLE t3;
eval LOAD DATA INFILE '$file' INTO TABLE t3;
# There should be no SST being ingested
select * from t3;
--enable_query_log
set rocksdb_bulk_load=0;

Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/rocksdb/r/bulk_load.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ start transaction with consistent snapshot;
select VALUE > 0 as 'Has opened snapshots' from information_schema.rocksdb_dbstats where stat_type='DB_NUM_SNAPSHOTS';
Has opened snapshots
1
SET @@GLOBAL.ROCKSDB_UPDATE_CF_OPTIONS=
'cf1={write_buffer_size=8m;target_file_size_base=1m};';
set rocksdb_bulk_load=1;
set rocksdb_bulk_load_size=100000;
LOAD DATA INFILE <input_file> INTO TABLE t1;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t2;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t3;
pk a b
set rocksdb_bulk_load=0;
SHOW TABLE STATUS WHERE name LIKE 't%';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/rocksdb/r/bulk_load_rev_cf.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ start transaction with consistent snapshot;
select VALUE > 0 as 'Has opened snapshots' from information_schema.rocksdb_dbstats where stat_type='DB_NUM_SNAPSHOTS';
Has opened snapshots
1
SET @@GLOBAL.ROCKSDB_UPDATE_CF_OPTIONS=
'rev:cf1={write_buffer_size=8m;target_file_size_base=1m};';
set rocksdb_bulk_load=1;
set rocksdb_bulk_load_size=100000;
LOAD DATA INFILE <input_file> INTO TABLE t1;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t2;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t3;
pk a b
set rocksdb_bulk_load=0;
SHOW TABLE STATUS WHERE name LIKE 't%';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/rocksdb/r/bulk_load_rev_cf_and_data.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ start transaction with consistent snapshot;
select VALUE > 0 as 'Has opened snapshots' from information_schema.rocksdb_dbstats where stat_type='DB_NUM_SNAPSHOTS';
Has opened snapshots
1
SET @@GLOBAL.ROCKSDB_UPDATE_CF_OPTIONS=
'rev:cf1={write_buffer_size=8m;target_file_size_base=1m};';
set rocksdb_bulk_load=1;
set rocksdb_bulk_load_size=100000;
LOAD DATA INFILE <input_file> INTO TABLE t1;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t2;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t3;
pk a b
set rocksdb_bulk_load=0;
SHOW TABLE STATUS WHERE name LIKE 't%';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/rocksdb/r/bulk_load_rev_data.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ start transaction with consistent snapshot;
select VALUE > 0 as 'Has opened snapshots' from information_schema.rocksdb_dbstats where stat_type='DB_NUM_SNAPSHOTS';
Has opened snapshots
1
SET @@GLOBAL.ROCKSDB_UPDATE_CF_OPTIONS=
'cf1={write_buffer_size=8m;target_file_size_base=1m};';
set rocksdb_bulk_load=1;
set rocksdb_bulk_load_size=100000;
LOAD DATA INFILE <input_file> INTO TABLE t1;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t2;
pk a b
LOAD DATA INFILE <input_file> INTO TABLE t3;
pk a b
set rocksdb_bulk_load=0;
SHOW TABLE STATUS WHERE name LIKE 't%';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/rocksdb/t/bulk_load.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--source include/big_test.inc

--let pk_cf=cf1
--let pk_cf_name=cf1
--let data_order_desc=0

--source suite/rocksdb/include/bulk_load.inc
1 change: 1 addition & 0 deletions mysql-test/suite/rocksdb/t/bulk_load_rev_cf.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--source include/big_test.inc

--let pk_cf=rev:cf1
--let pk_cf_name=cf1
--let data_order_desc=0

--source suite/rocksdb/include/bulk_load.inc
1 change: 1 addition & 0 deletions mysql-test/suite/rocksdb/t/bulk_load_rev_cf_and_data.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--source include/big_test.inc

--let pk_cf=rev:cf1
--let pk_cf_name=cf1
--let data_order_desc=1

--source suite/rocksdb/include/bulk_load.inc
1 change: 1 addition & 0 deletions mysql-test/suite/rocksdb/t/bulk_load_rev_data.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--source include/big_test.inc

--let pk_cf=cf1
--let pk_cf_name=cf1
--let data_order_desc=1

--source suite/rocksdb/include/bulk_load.inc

0 comments on commit 64d3544

Please sign in to comment.