mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-26 12:44:10 +00:00
fix: reject primary key encoding options on logical metric tables (#10624)
Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
+13
-3
@@ -127,6 +127,16 @@ pub enum Error {
|
||||
#[snafu(display("Unsupported operation: {}", operation))]
|
||||
Unsupported { operation: String },
|
||||
|
||||
#[snafu(display(
|
||||
"Cannot set {} on a logical table; configure it on the physical table",
|
||||
key
|
||||
))]
|
||||
PhysicalTableOption {
|
||||
key: String,
|
||||
#[snafu(implicit)]
|
||||
location: Location,
|
||||
},
|
||||
|
||||
#[snafu(display("Failed to parse table option, key: {}, value: {}", key, value))]
|
||||
ParseTableOption {
|
||||
key: String,
|
||||
@@ -239,9 +249,9 @@ impl ErrorExt for Error {
|
||||
Error::InvalidColumnOption { .. } => StatusCode::InvalidArguments,
|
||||
Error::ColumnNotExists { .. } => StatusCode::TableColumnNotFound,
|
||||
Error::Unsupported { .. } => StatusCode::Unsupported,
|
||||
Error::ParseTableOption { .. } | Error::ConflictingTableOptions { .. } => {
|
||||
StatusCode::InvalidArguments
|
||||
}
|
||||
Error::PhysicalTableOption { .. }
|
||||
| Error::ParseTableOption { .. }
|
||||
| Error::ConflictingTableOptions { .. } => StatusCode::InvalidArguments,
|
||||
Error::MissingTimeIndexColumn { .. } => StatusCode::IllegalState,
|
||||
Error::SetSkippingOptions { .. }
|
||||
| Error::UnsetSkippingOptions { .. }
|
||||
|
||||
@@ -34,7 +34,8 @@ use greptime_proto::v1::region::{build_index_request, compact_request};
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use store_api::metric_engine_consts::{
|
||||
LOGICAL_TABLE_METADATA_KEY, PHYSICAL_TABLE_METADATA_KEY, is_metric_engine_option_key,
|
||||
LOGICAL_TABLE_METADATA_KEY, MEMTABLE_PARTITION_TREE_PRIMARY_KEY_ENCODING,
|
||||
PHYSICAL_TABLE_METADATA_KEY, PRIMARY_KEY_ENCODING, is_metric_engine_option_key,
|
||||
};
|
||||
use store_api::mito_engine_options::{
|
||||
APPEND_MODE_KEY, COMPACTION_TYPE, EXPERIMENTAL_SST_FLOAT_FIELD_ENCODING, FloatFieldEncoding,
|
||||
@@ -47,7 +48,9 @@ use store_api::mito_engine_options::{
|
||||
};
|
||||
use store_api::region_request::{SetRegionOption, UnsetRegionOption};
|
||||
|
||||
use crate::error::{ConflictingTableOptionsSnafu, ParseTableOptionSnafu, Result};
|
||||
use crate::error::{
|
||||
ConflictingTableOptionsSnafu, ParseTableOptionSnafu, PhysicalTableOptionSnafu, Result,
|
||||
};
|
||||
use crate::metadata::{TableId, TableVersion};
|
||||
|
||||
mod semantic;
|
||||
@@ -314,6 +317,17 @@ impl TableOptions {
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
|
||||
if kvs.contains_key(LOGICAL_TABLE_METADATA_KEY) {
|
||||
for key in [
|
||||
PRIMARY_KEY_ENCODING,
|
||||
MEMTABLE_PARTITION_TREE_PRIMARY_KEY_ENCODING,
|
||||
] {
|
||||
if kvs.contains_key(key) {
|
||||
return PhysicalTableOptionSnafu { key }.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
normalize_twcs_trigger_options(&mut kvs).map_err(|conflict| {
|
||||
ConflictingTableOptionsSnafu {
|
||||
first_key: TWCS_TRIGGER_FILE_NUM,
|
||||
@@ -1156,6 +1170,24 @@ mod tests {
|
||||
assert!(!validate_database_option("foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_primary_key_encoding_on_metric_tables() {
|
||||
for key in [
|
||||
PRIMARY_KEY_ENCODING,
|
||||
MEMTABLE_PARTITION_TREE_PRIMARY_KEY_ENCODING,
|
||||
] {
|
||||
let error = TableOptions::try_from_iter([
|
||||
(LOGICAL_TABLE_METADATA_KEY, "metrics"),
|
||||
(key, "sparse"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert_eq!(StatusCode::InvalidArguments, error.status_code());
|
||||
assert!(error.to_string().contains(key));
|
||||
TableOptions::try_from_iter([(PHYSICAL_TABLE_METADATA_KEY, ""), (key, "sparse")])
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_float_field_encoding_option() {
|
||||
let options = TableOptions::try_from_iter([(
|
||||
|
||||
Reference in New Issue
Block a user