From 3e1a1257320b4885e610db5f5310b1f0c99f3a08 Mon Sep 17 00:00:00 2001 From: Yingwen Date: Mon, 8 Apr 2024 21:42:58 +0800 Subject: [PATCH] feat: add append mode to table options (#3624) * feat: add append mode to table options * test: add append mode test * test: rename test tables * chore: Add delete test for append mode --- src/mito2/src/worker/handle_write.rs | 2 +- src/store-api/src/mito_engine_options.rs | 2 + .../common/insert/append_mode.result | 73 +++++++++++++++++++ .../standalone/common/insert/append_mode.sql | 38 ++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tests/cases/standalone/common/insert/append_mode.result create mode 100644 tests/cases/standalone/common/insert/append_mode.sql diff --git a/src/mito2/src/worker/handle_write.rs b/src/mito2/src/worker/handle_write.rs index 9b7693710b3..ca9a1b31a39 100644 --- a/src/mito2/src/worker/handle_write.rs +++ b/src/mito2/src/worker/handle_write.rs @@ -239,7 +239,7 @@ fn check_op_type(append_mode: bool, request: &WriteRequest) -> Result<()> { request.op_type == OpType::Put, InvalidRequestSnafu { region_id: request.region_id, - reason: "Only put is allowed under append mode", + reason: "DELETE is not allowed under append mode", } ); } diff --git a/src/store-api/src/mito_engine_options.rs b/src/store-api/src/mito_engine_options.rs index cfb26d30892..4ae4bcd0d36 100644 --- a/src/store-api/src/mito_engine_options.rs +++ b/src/store-api/src/mito_engine_options.rs @@ -33,6 +33,7 @@ pub fn is_mito_engine_option_key(key: &str) -> bool { "memtable.partition_tree.index_max_keys_per_shard", "memtable.partition_tree.data_freeze_threshold", "memtable.partition_tree.fork_dictionary_bytes", + "append_mode", ] .contains(&key) } @@ -70,6 +71,7 @@ mod tests { assert!(is_mito_engine_option_key( "memtable.partition_tree.fork_dictionary_bytes" )); + assert!(is_mito_engine_option_key("append_mode")); assert!(!is_mito_engine_option_key("foo")); } } diff --git a/tests/cases/standalone/common/insert/append_mode.result b/tests/cases/standalone/common/insert/append_mode.result new file mode 100644 index 00000000000..4fe1166ae6e --- /dev/null +++ b/tests/cases/standalone/common/insert/append_mode.result @@ -0,0 +1,73 @@ +create table if not exists append_mode_on( + host string, + ts timestamp, + cpu double, + TIME INDEX (ts), + PRIMARY KEY(host) +) +engine=mito +with('append_mode'='true'); + +Affected Rows: 0 + +INSERT INTO append_mode_on VALUES ('host1',0, 0), ('host2', 1, 1,); + +Affected Rows: 2 + +INSERT INTO append_mode_on VALUES ('host1',0, 0), ('host2', 1, 1,); + +Affected Rows: 2 + +SELECT * from append_mode_on ORDER BY host, ts; + ++-------+-------------------------+-----+ +| host | ts | cpu | ++-------+-------------------------+-----+ +| host1 | 1970-01-01T00:00:00 | 0.0 | +| host1 | 1970-01-01T00:00:00 | 0.0 | +| host2 | 1970-01-01T00:00:00.001 | 1.0 | +| host2 | 1970-01-01T00:00:00.001 | 1.0 | ++-------+-------------------------+-----+ + +-- SQLNESS REPLACE (region\s\d+\(\d+\,\s\d+\)) region +DELETE FROM append_mode_on WHERE host = 'host1'; + +Error: 1004(InvalidArguments), Invalid request to region, reason: DELETE is not allowed under append mode + +create table if not exists append_mode_off( + host string, + ts timestamp, + cpu double, + TIME INDEX (ts), + PRIMARY KEY(host) +) +engine=mito +with('append_mode'='false'); + +Affected Rows: 0 + +INSERT INTO append_mode_off VALUES ('host1',0, 0), ('host2', 1, 1,); + +Affected Rows: 2 + +INSERT INTO append_mode_off VALUES ('host1',0, 10), ('host2', 1, 11,); + +Affected Rows: 2 + +SELECT * from append_mode_off ORDER BY host, ts; + ++-------+-------------------------+------+ +| host | ts | cpu | ++-------+-------------------------+------+ +| host1 | 1970-01-01T00:00:00 | 10.0 | +| host2 | 1970-01-01T00:00:00.001 | 11.0 | ++-------+-------------------------+------+ + +DROP TABLE append_mode_on; + +Affected Rows: 0 + +DROP TABLE append_mode_off; + +Affected Rows: 0 + diff --git a/tests/cases/standalone/common/insert/append_mode.sql b/tests/cases/standalone/common/insert/append_mode.sql new file mode 100644 index 00000000000..a27a66f4e01 --- /dev/null +++ b/tests/cases/standalone/common/insert/append_mode.sql @@ -0,0 +1,38 @@ +create table if not exists append_mode_on( + host string, + ts timestamp, + cpu double, + TIME INDEX (ts), + PRIMARY KEY(host) +) +engine=mito +with('append_mode'='true'); + +INSERT INTO append_mode_on VALUES ('host1',0, 0), ('host2', 1, 1,); + +INSERT INTO append_mode_on VALUES ('host1',0, 0), ('host2', 1, 1,); + +SELECT * from append_mode_on ORDER BY host, ts; + +-- SQLNESS REPLACE (region\s\d+\(\d+\,\s\d+\)) region +DELETE FROM append_mode_on WHERE host = 'host1'; + +create table if not exists append_mode_off( + host string, + ts timestamp, + cpu double, + TIME INDEX (ts), + PRIMARY KEY(host) +) +engine=mito +with('append_mode'='false'); + +INSERT INTO append_mode_off VALUES ('host1',0, 0), ('host2', 1, 1,); + +INSERT INTO append_mode_off VALUES ('host1',0, 10), ('host2', 1, 11,); + +SELECT * from append_mode_off ORDER BY host, ts; + +DROP TABLE append_mode_on; + +DROP TABLE append_mode_off;