From 9d8b08daef5ccf87fe78edc9d40802d827224978 Mon Sep 17 00:00:00 2001 From: discord9 Date: Wed, 4 Dec 2024 16:17:26 +0800 Subject: [PATCH] fix: 10000 years --> forever --- src/common/base/src/ttl.rs | 7 +++++-- src/metric-engine/src/engine/create.rs | 4 ++-- tests/cases/standalone/common/alter/alter_database.result | 3 +++ .../standalone/common/alter/alter_table_options.result | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/common/base/src/ttl.rs b/src/common/base/src/ttl.rs index d78edabc9f7c..8330b26cf852 100644 --- a/src/common/base/src/ttl.rs +++ b/src/common/base/src/ttl.rs @@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize}; /// Time To Live #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] pub enum TimeToLive { - /// immediately throw away on insert + /// Immediately throw away on insert Immediate, /// Duration to keep the data, this duration should be non-zero Duration(Duration), @@ -56,6 +56,7 @@ impl<'de> Deserialize<'de> for TimeToLive { formatter.write_str("a string of time, 'immediate', 'forever' or null") } + /// Correctly deserialize null in json fn visit_unit(self) -> Result { Ok(TimeToLive::Forever) } @@ -84,7 +85,9 @@ impl Display for TimeToLive { } impl TimeToLive { - /// Parse a string into TimeToLive + /// Parse a string that is either `immediate`, `forever`, or a duration to `TimeToLive` + /// + /// note that a empty string is treat as `forever` too pub fn from_humantime_or_str(s: &str) -> Result { match s { "immediate" => Ok(TimeToLive::Immediate), diff --git a/src/metric-engine/src/engine/create.rs b/src/metric-engine/src/engine/create.rs index d897640cc529..5cb8b8e2c7a2 100644 --- a/src/metric-engine/src/engine/create.rs +++ b/src/metric-engine/src/engine/create.rs @@ -540,7 +540,7 @@ pub(crate) fn region_options_for_metadata_region( mut original: HashMap, ) -> HashMap { original.remove(APPEND_MODE_KEY); - original.insert(TTL_KEY.to_string(), "10000 years".to_string()); + original.insert(TTL_KEY.to_string(), "forever".to_string()); original } @@ -731,7 +731,7 @@ mod test { ); assert_eq!( metadata_region_request.options.get("ttl").unwrap(), - "10000 years" + "forever" ); } } diff --git a/tests/cases/standalone/common/alter/alter_database.result b/tests/cases/standalone/common/alter/alter_database.result index a98d48323659..8ff458989e4c 100644 --- a/tests/cases/standalone/common/alter/alter_database.result +++ b/tests/cases/standalone/common/alter/alter_database.result @@ -62,6 +62,9 @@ SHOW CREATE DATABASE alter_database; | Database | Create Database | +----------------+----------------------------------------------+ | alter_database | CREATE DATABASE IF NOT EXISTS alter_database | +| | WITH( | +| | ttl = 'forever' | +| | ) | +----------------+----------------------------------------------+ ALTER DATABASE alter_database SET 'ttl'='😁'; diff --git a/tests/cases/standalone/common/alter/alter_table_options.result b/tests/cases/standalone/common/alter/alter_table_options.result index 8fa08eefea6b..b38a99d8465e 100644 --- a/tests/cases/standalone/common/alter/alter_table_options.result +++ b/tests/cases/standalone/common/alter/alter_table_options.result @@ -103,7 +103,9 @@ SHOW CREATE TABLE ato; | | ) | | | | | | ENGINE=mito | -| | | +| | WITH( | +| | ttl = 'forever' | +| | ) | +-------+------------------------------------+ ALTER TABLE ato SET 'ttl'='1s';