Skip to content

Commit

Permalink
feat: introduce experimental_sparse_primary_key_encoding to `Metric…
Browse files Browse the repository at this point in the history
…EngineConfig`
  • Loading branch information
WenyXu committed Jan 15, 2025
1 parent 121ec79 commit 3c3a98f
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
| `region_engine.mito.memtable.data_freeze_threshold` | Integer | `32768` | The max rows of data inside the actively writing buffer in one shard.<br/>Only available for `partition_tree` memtable. |
| `region_engine.mito.memtable.fork_dictionary_bytes` | String | `1GiB` | Max dictionary bytes.<br/>Only available for `partition_tree` memtable. |
| `region_engine.file` | -- | -- | Enable the file engine. |
| `region_engine.metric` | -- | -- | Metric engine options. |
| `region_engine.metric.experimental_sparse_primary_key_encoding` | Bool | `false` | Whether to enable the experimental sparse primary key encoding. |
| `logging` | -- | -- | The logging options. |
| `logging.dir` | String | `/tmp/greptimedb/logs` | The directory to store the log files. If set to empty, logs will not be written to files. |
| `logging.level` | String | Unset | The log level. Can be `info`/`debug`/`warn`/`error`. |
Expand Down Expand Up @@ -506,6 +508,8 @@
| `region_engine.mito.memtable.data_freeze_threshold` | Integer | `32768` | The max rows of data inside the actively writing buffer in one shard.<br/>Only available for `partition_tree` memtable. |
| `region_engine.mito.memtable.fork_dictionary_bytes` | String | `1GiB` | Max dictionary bytes.<br/>Only available for `partition_tree` memtable. |
| `region_engine.file` | -- | -- | Enable the file engine. |
| `region_engine.metric` | -- | -- | Metric engine options. |
| `region_engine.metric.experimental_sparse_primary_key_encoding` | Bool | `false` | Whether to enable the experimental sparse primary key encoding. |
| `logging` | -- | -- | The logging options. |
| `logging.dir` | String | `/tmp/greptimedb/logs` | The directory to store the log files. If set to empty, logs will not be written to files. |
| `logging.level` | String | Unset | The log level. Can be `info`/`debug`/`warn`/`error`. |
Expand Down
6 changes: 6 additions & 0 deletions config/datanode.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ fork_dictionary_bytes = "1GiB"
## Enable the file engine.
[region_engine.file]

[[region_engine]]
## Metric engine options.
[region_engine.metric]
## Whether to enable the experimental sparse primary key encoding.
experimental_sparse_primary_key_encoding = false

## The logging options.
[logging]
## The directory to store the log files. If set to empty, logs will not be written to files.
Expand Down
6 changes: 6 additions & 0 deletions config/standalone.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ fork_dictionary_bytes = "1GiB"
## Enable the file engine.
[region_engine.file]

[[region_engine]]
## Metric engine options.
[region_engine.metric]
## Whether to enable the experimental sparse primary key encoding.
experimental_sparse_primary_key_encoding = false

## The logging options.
[logging]
## The directory to store the log files. If set to empty, logs will not be written to files.
Expand Down
3 changes: 3 additions & 0 deletions src/datanode/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use common_telemetry::logging::{LoggingOptions, TracingOptions};
use common_wal::config::DatanodeWalConfig;
use file_engine::config::EngineConfig as FileEngineConfig;
use meta_client::MetaClientOptions;
use metric_engine::config::EngineConfig as MetricEngineConfig;
use mito2::config::MitoConfig;
use serde::{Deserialize, Serialize};
use servers::export_metrics::ExportMetricsOption;
Expand Down Expand Up @@ -432,6 +433,8 @@ pub enum RegionEngineConfig {
Mito(MitoConfig),
#[serde(rename = "file")]
File(FileEngineConfig),
#[serde(rename = "metric")]
Metric(MetricEngineConfig),
}

#[cfg(test)]
Expand Down
13 changes: 12 additions & 1 deletion src/datanode/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ impl DatanodeBuilder {
plugins: Plugins,
) -> Result<Vec<RegionEngineRef>> {
let mut engines = vec![];
let mut metric_engine_config = opts.region_engine.iter().find_map(|c| match c {
RegionEngineConfig::Metric(config) => Some(config.clone()),
_ => None,
});

for engine in &opts.region_engine {
match engine {
RegionEngineConfig::Mito(config) => {
Expand All @@ -407,7 +412,10 @@ impl DatanodeBuilder {
)
.await?;

let metric_engine = MetricEngine::new(mito_engine.clone());
let metric_engine = MetricEngine::new(
mito_engine.clone(),
metric_engine_config.take().unwrap_or_default(),
);
engines.push(Arc::new(mito_engine) as _);
engines.push(Arc::new(metric_engine) as _);
}
Expand All @@ -418,6 +426,9 @@ impl DatanodeBuilder {
);
engines.push(Arc::new(engine) as _);
}
RegionEngineConfig::Metric(_) => {
// Already handled in `build_mito_engine`.
}
}
}
Ok(engines)
Expand Down
1 change: 1 addition & 0 deletions src/metric-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mito2.workspace = true
mur3 = "0.1"
object-store.workspace = true
prometheus.workspace = true
serde.workspace = true
serde_json.workspace = true
snafu.workspace = true
store-api.workspace = true
Expand Down
20 changes: 20 additions & 0 deletions src/metric-engine/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct EngineConfig {
pub experimental_sparse_primary_key_encoding: bool,
}
7 changes: 6 additions & 1 deletion src/metric-engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use store_api::region_request::RegionRequest;
use store_api::storage::{RegionId, ScanRequest};

use self::state::MetricEngineState;
use crate::config::EngineConfig;
use crate::data_region::DataRegion;
use crate::error::{self, Result, UnsupportedRegionRequestSnafu};
use crate::metadata_region::MetadataRegion;
Expand Down Expand Up @@ -255,7 +256,7 @@ impl RegionEngine for MetricEngine {
}

impl MetricEngine {
pub fn new(mito: MitoEngine) -> Self {
pub fn new(mito: MitoEngine, config: EngineConfig) -> Self {
let metadata_region = MetadataRegion::new(mito.clone());
let data_region = DataRegion::new(mito.clone());
Self {
Expand All @@ -264,6 +265,7 @@ impl MetricEngine {
metadata_region,
data_region,
state: RwLock::default(),
config,
}),
}
}
Expand Down Expand Up @@ -304,6 +306,9 @@ struct MetricEngineInner {
metadata_region: MetadataRegion,
data_region: DataRegion,
state: RwLock<MetricEngineState>,
/// TODO(weny): remove it after the config is used.
#[allow(unused)]
config: EngineConfig,
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion src/metric-engine/src/engine/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ mod test {
use store_api::metric_engine_consts::{METRIC_ENGINE_NAME, PHYSICAL_TABLE_METADATA_KEY};

use super::*;
use crate::config::EngineConfig;
use crate::engine::MetricEngine;
use crate::test_util::TestEnv;

Expand Down Expand Up @@ -707,7 +708,7 @@ mod test {

// set up
let env = TestEnv::new().await;
let engine = MetricEngine::new(env.mito());
let engine = MetricEngine::new(env.mito(), EngineConfig::default());
let engine_inner = engine.inner;

// check create data region request
Expand Down
1 change: 1 addition & 0 deletions src/metric-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#![feature(let_chains)]

pub mod config;
mod data_region;
pub mod engine;
pub mod error;
Expand Down
3 changes: 2 additions & 1 deletion src/metric-engine/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use store_api::region_request::{
};
use store_api::storage::{ColumnId, RegionId};

use crate::config::EngineConfig;
use crate::data_region::DataRegion;
use crate::engine::MetricEngine;
use crate::metadata_region::MetadataRegion;
Expand All @@ -54,7 +55,7 @@ impl TestEnv {
pub async fn with_prefix(prefix: &str) -> Self {
let mut mito_env = MitoTestEnv::with_prefix(prefix);
let mito = mito_env.create_engine(MitoConfig::default()).await;
let metric = MetricEngine::new(mito.clone());
let metric = MetricEngine::new(mito.clone(), EngineConfig::default());
Self {
mito_env,
mito,
Expand Down

0 comments on commit 3c3a98f

Please sign in to comment.