fix: support append-only physical table (#4716)

* fix: support append-only physical table

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* Update src/metric-engine/src/engine/create.rs

Co-authored-by: jeremyhi <jiachun_feng@proton.me>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Co-authored-by: Weny Xu <wenymedia@gmail.com>
Co-authored-by: jeremyhi <jiachun_feng@proton.me>
This commit is contained in:
Ruihang Xia
2024-09-10 20:23:23 +08:00
committed by GitHub
parent dcae21208b
commit ff40d512bd
4 changed files with 83 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ use store_api::metric_engine_consts::{
METADATA_SCHEMA_VALUE_COLUMN_INDEX, METADATA_SCHEMA_VALUE_COLUMN_NAME,
PHYSICAL_TABLE_METADATA_KEY,
};
use store_api::mito_engine_options::{APPEND_MODE_KEY, TTL_KEY};
use store_api::region_engine::RegionEngine;
use store_api::region_request::{AffectedRows, RegionCreateRequest, RegionRequest};
use store_api::storage::consts::ReservedColumnId;
@@ -426,9 +427,10 @@ impl MetricEngineInner {
// concat region dir
let metadata_region_dir = join_dir(&request.region_dir, METADATA_REGION_SUBDIR);
// remove TTL option
// remove TTL and APPEND_MODE option
let mut options = request.options.clone();
options.remove("ttl");
options.remove(TTL_KEY);
options.remove(APPEND_MODE_KEY);
RegionCreateRequest {
engine: MITO_ENGINE_NAME.to_string(),

View File

@@ -21,6 +21,8 @@ use common_wal::options::WAL_OPTIONS_KEY;
pub const APPEND_MODE_KEY: &str = "append_mode";
/// Option key for merge mode.
pub const MERGE_MODE_KEY: &str = "merge_mode";
/// Option key for TTL(time-to-live)
pub const TTL_KEY: &str = "ttl";
/// Returns true if the `key` is a valid option key for the mito engine.
pub fn is_mito_engine_option_key(key: &str) -> bool {

View File

@@ -169,3 +169,53 @@ DROP TABLE `auT`;
Affected Rows: 0
-- append-only metric table
CREATE TABLE
phy (ts timestamp time index, val double) engine = metric
with
(
"physical_metric_table" = "",
"append_mode" = "true"
);
Affected Rows: 0
CREATE TABLE t1(ts timestamp time index, val double, host string primary key) engine=metric with ("on_physical_table" = "phy");
Affected Rows: 0
INSERT INTO t1 (ts, val, host) VALUES
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com'),
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com');
Affected Rows: 6
SELECT * FROM t1;
+-------------+---------------------+------+
| host | ts | val |
+-------------+---------------------+------+
| example.com | 2022-01-01T00:00:00 | 1.23 |
| example.com | 2022-01-01T00:00:00 | 1.23 |
| example.com | 2022-01-02T00:00:00 | 4.56 |
| example.com | 2022-01-02T00:00:00 | 4.56 |
| example.com | 2022-01-03T00:00:00 | 7.89 |
| example.com | 2022-01-03T00:00:00 | 7.89 |
+-------------+---------------------+------+
DROP TABLE t1;
Affected Rows: 0
DESC TABLE t1;
Error: 4001(TableNotFound), Table not found: t1
DROP TABLE phy;
Affected Rows: 0

View File

@@ -59,3 +59,30 @@ CREATE TABLE `auT`(
DESC TABLE `auT`;
DROP TABLE `auT`;
-- append-only metric table
CREATE TABLE
phy (ts timestamp time index, val double) engine = metric
with
(
"physical_metric_table" = "",
"append_mode" = "true"
);
CREATE TABLE t1(ts timestamp time index, val double, host string primary key) engine=metric with ("on_physical_table" = "phy");
INSERT INTO t1 (ts, val, host) VALUES
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com'),
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com');
SELECT * FROM t1;
DROP TABLE t1;
DESC TABLE t1;
DROP TABLE phy;