From b9046f122611a0918ba110a6aa1ad442928a8849 Mon Sep 17 00:00:00 2001 From: lyang24 Date: Sun, 24 Nov 2024 18:26:38 -0800 Subject: [PATCH] allow physical region alter region options --- src/metric-engine/src/engine.rs | 3 +- src/metric-engine/src/engine/alter.rs | 14 +++-- .../common/alter/alter_table_options.result | 51 +++++++++++++++++++ .../common/alter/alter_table_options.sql | 12 +++++ 4 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/metric-engine/src/engine.rs b/src/metric-engine/src/engine.rs index a136ed3c76c6..86b64ddfae2a 100644 --- a/src/metric-engine/src/engine.rs +++ b/src/metric-engine/src/engine.rs @@ -96,9 +96,10 @@ use crate::utils; /// | Read | ✅ | ✅ | /// | Close | ✅ | ✅ | /// | Open | ✅ | ✅ | -/// | Alter | ✅ | ❌ | +/// | Alter | ✅ | ❓* | /// /// *: Physical region can be dropped only when all related logical regions are dropped. +/// *: Alter: Physical regions only support altering region options. /// /// ## Internal Columns /// diff --git a/src/metric-engine/src/engine/alter.rs b/src/metric-engine/src/engine/alter.rs index f4a4811f7210..0da446ecea35 100644 --- a/src/metric-engine/src/engine/alter.rs +++ b/src/metric-engine/src/engine/alter.rs @@ -150,10 +150,16 @@ impl MetricEngineInner { region_id: RegionId, request: RegionAlterRequest, ) -> Result<()> { - info!("Metric region received alter request {request:?} on physical region {region_id:?}"); - FORBIDDEN_OPERATION_COUNT.inc(); - - ForbiddenPhysicalAlterSnafu.fail() + match request.kind { + AlterKind::SetRegionOptions { options: _ } + | AlterKind::UnsetRegionOptions { keys: _ } => Ok(()), + _ => { + info!("Metric region received alter request {request:?} on physical region {region_id:?}"); + FORBIDDEN_OPERATION_COUNT.inc(); + + ForbiddenPhysicalAlterSnafu.fail() + } + } } } diff --git a/tests/cases/standalone/common/alter/alter_table_options.result b/tests/cases/standalone/common/alter/alter_table_options.result index a375b7ac78c3..8fa08eefea6b 100644 --- a/tests/cases/standalone/common/alter/alter_table_options.result +++ b/tests/cases/standalone/common/alter/alter_table_options.result @@ -281,3 +281,54 @@ DROP TABLE ato; Affected Rows: 0 +CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("physical_metric_table" = ""); + +Affected Rows: 0 + +ALTER TABLE phy set ttl='2years'; + +Affected Rows: 0 + +SHOW CREATE TABLE phy; + ++-------+------------------------------------+ +| Table | Create Table | ++-------+------------------------------------+ +| phy | CREATE TABLE IF NOT EXISTS "phy" ( | +| | "ts" TIMESTAMP(3) NOT NULL, | +| | "val" DOUBLE NULL, | +| | TIME INDEX ("ts") | +| | ) | +| | | +| | ENGINE=metric | +| | WITH( | +| | physical_metric_table = '', | +| | ttl = '2years' | +| | ) | ++-------+------------------------------------+ + +ALTER TABLE phy UNSET 'ttl'; + +Affected Rows: 0 + +SHOW CREATE TABLE phy; + ++-------+------------------------------------+ +| Table | Create Table | ++-------+------------------------------------+ +| phy | CREATE TABLE IF NOT EXISTS "phy" ( | +| | "ts" TIMESTAMP(3) NOT NULL, | +| | "val" DOUBLE NULL, | +| | TIME INDEX ("ts") | +| | ) | +| | | +| | ENGINE=metric | +| | WITH( | +| | physical_metric_table = '' | +| | ) | ++-------+------------------------------------+ + +DROP TABLE phy; + +Affected Rows: 0 + diff --git a/tests/cases/standalone/common/alter/alter_table_options.sql b/tests/cases/standalone/common/alter/alter_table_options.sql index 2fcc8a9707ab..63d794c661a6 100644 --- a/tests/cases/standalone/common/alter/alter_table_options.sql +++ b/tests/cases/standalone/common/alter/alter_table_options.sql @@ -60,3 +60,15 @@ SHOW CREATE TABLE ato; SHOW CREATE TABLE ato; DROP TABLE ato; + +CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("physical_metric_table" = ""); + +ALTER TABLE phy set ttl='2years'; + +SHOW CREATE TABLE phy; + +ALTER TABLE phy UNSET 'ttl'; + +SHOW CREATE TABLE phy; + +DROP TABLE phy;