Skip to content

Commit 28aa33b

Browse files
authored
refactor: init to support external storage for history tables (#18185)
* refactor(storage-config): split StorageParams out from databend-common-meta-app * chore: add new config for external storage * refactor: split meta related operations out from `GlobalHistoryLog` * change default level from WARN to INFO
1 parent 3f823fc commit 28aa33b

File tree

14 files changed

+391
-135
lines changed

14 files changed

+391
-135
lines changed

Cargo.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ members = [
112112
"src/tests/sqlsmith",
113113
"src/bendsave",
114114
"src/bendpy",
115+
"src/meta/app-storage",
115116
]
116117

117118
# Workspace dependencies
@@ -142,6 +143,7 @@ databend-common-license = { path = "src/common/license" }
142143
databend-common-management = { path = "src/query/management" }
143144
databend-common-meta-api = { path = "src/meta/api" }
144145
databend-common-meta-app = { path = "src/meta/app" }
146+
databend-common-meta-app-storage = { path = "src/meta/app-storage" }
145147
databend-common-meta-app-types = { path = "src/meta/app-types" }
146148
databend-common-meta-cache = { path = "src/meta/cache" }
147149
databend-common-meta-client = { path = "src/meta/client" }

src/common/tracing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ chrono = { workspace = true }
1616
concurrent-queue = { workspace = true }
1717
databend-common-base = { workspace = true }
1818
databend-common-exception = { workspace = true }
19+
databend-common-meta-app-storage = { workspace = true }
1920
defer = { workspace = true }
2021
fastrace = { workspace = true }
2122
fastrace-opentelemetry = { workspace = true }

src/common/tracing/src/config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::collections::BTreeMap;
1616
use std::fmt::Display;
1717
use std::fmt::Formatter;
1818

19+
use databend_common_meta_app_storage::StorageParams;
1920
use itertools::Itertools;
2021

2122
// use the uncommon usage of Pascal Case level name
@@ -346,6 +347,7 @@ pub struct HistoryConfig {
346347
pub level: String,
347348
pub retention_interval: usize,
348349
pub tables: Vec<HistoryTableConfig>,
350+
pub storage_params: Option<StorageParams>,
349351
}
350352

351353
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
@@ -358,7 +360,7 @@ impl Display for HistoryConfig {
358360
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
359361
write!(
360362
f,
361-
"enabled={}, log_only={}, interval={}, stage_name={}, level={}, retention_interval={}, tables=[{}]",
363+
"enabled={}, log_only={}, interval={}, stage_name={}, level={}, retention_interval={}, tables=[{}], storage_params={}",
362364
self.on,
363365
self.log_only,
364366
self.interval,
@@ -368,7 +370,9 @@ impl Display for HistoryConfig {
368370
self.tables
369371
.iter()
370372
.map(|f| format!("{}({} hours)", f.table_name.clone(), f.retention))
371-
.join(", ")
373+
.join(", "),
374+
self.storage_params.as_ref()
375+
.map_or("None".to_string(), |p| p.to_string())
372376
)
373377
}
374378
}
@@ -381,10 +385,11 @@ impl Default for HistoryConfig {
381385
log_only: false,
382386
// The default value of stage name uses an uuid to avoid conflicts with existing stages
383387
stage_name: "log_1f93b76af0bd4b1d8e018667865fbc65".to_string(),
384-
level: "WARN".to_string(),
388+
level: "INFO".to_string(),
385389
// Trigger the retention task every 24 hours
386390
retention_interval: 24,
387391
tables: vec![],
392+
storage_params: None,
388393
}
389394
}
390395
}

src/meta/app-storage/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "databend-common-meta-app-storage"
3+
version.workspace = true
4+
authors.workspace = true
5+
license.workspace = true
6+
publish.workspace = true
7+
edition.workspace = true
8+
9+
[dependencies]
10+
databend-common-base = { workspace = true }
11+
databend-common-exception = { workspace = true }
12+
opendal = { workspace = true }
13+
serde = { workspace = true }
14+
15+
[lints]
16+
workspace = true

src/meta/app-storage/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 Datafuse Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#![feature(no_sanitize)]
16+
mod storage_params;
17+
18+
pub use storage_params::*;

src/meta/app/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ storage-hdfs = []
1313
anyerror = { workspace = true }
1414
chrono = { workspace = true }
1515
databend-common-ast = { workspace = true }
16-
databend-common-base = { workspace = true }
1716
databend-common-exception = { workspace = true }
1817
databend-common-expression = { workspace = true }
1918
databend-common-io = { workspace = true }
19+
databend-common-meta-app-storage = { workspace = true }
2020
databend-common-meta-app-types = { workspace = true }
2121
databend-common-meta-kvapi = { workspace = true }
2222
databend-common-meta-types = { workspace = true }
@@ -28,7 +28,6 @@ itertools = { workspace = true }
2828
maplit = { workspace = true }
2929
num-derive = { workspace = true }
3030
num-traits = { workspace = true }
31-
opendal = { workspace = true }
3231
paste = { workspace = true }
3332
prost = { workspace = true }
3433
serde = { workspace = true }

src/meta/app/src/storage/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
mod storage_params;
16-
17-
pub use storage_params::*;
15+
use databend_common_meta_app_storage;
16+
pub use databend_common_meta_app_storage::*;

src/query/config/src/config.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ pub struct HistoryLogConfig {
27692769
#[clap(
27702770
long = "log-history-level",
27712771
value_name = "VALUE",
2772-
default_value = "WARN"
2772+
default_value = "INFO"
27732773
)]
27742774
#[serde(rename = "level")]
27752775
pub log_history_level: String,
@@ -2788,6 +2788,13 @@ pub struct HistoryLogConfig {
27882788
#[clap(skip)]
27892789
#[serde(rename = "tables")]
27902790
pub log_history_tables: Vec<HistoryLogTableConfig>,
2791+
2792+
/// Specifies the storage parameters for the history log
2793+
/// This is used to configure how the history log data is stored.
2794+
/// If not specified, the default storage parameters from `[storage]` will be used.
2795+
#[clap(skip)]
2796+
#[serde(rename = "storage")]
2797+
pub log_history_storage_params: Option<StorageConfig>,
27912798
}
27922799

27932800
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -2837,6 +2844,12 @@ impl TryInto<InnerHistoryConfig> for HistoryLogConfig {
28372844
type Error = ErrorCode;
28382845

28392846
fn try_into(self) -> Result<InnerHistoryConfig> {
2847+
let storage_params: Option<InnerStorageConfig> =
2848+
if self.log_history_storage_params.is_some() {
2849+
Some(self.log_history_storage_params.unwrap().try_into()?)
2850+
} else {
2851+
None
2852+
};
28402853
Ok(InnerHistoryConfig {
28412854
on: self.log_history_on,
28422855
log_only: self.log_history_log_only,
@@ -2849,12 +2862,18 @@ impl TryInto<InnerHistoryConfig> for HistoryLogConfig {
28492862
.into_iter()
28502863
.map(|cfg| cfg.try_into())
28512864
.collect::<Result<Vec<_>>>()?,
2865+
storage_params: storage_params.map(|cfg| cfg.params),
28522866
})
28532867
}
28542868
}
28552869

28562870
impl From<InnerHistoryConfig> for HistoryLogConfig {
28572871
fn from(inner: InnerHistoryConfig) -> Self {
2872+
let inner_storage_config: Option<InnerStorageConfig> =
2873+
inner.storage_params.map(|params| InnerStorageConfig {
2874+
params,
2875+
..Default::default()
2876+
});
28582877
Self {
28592878
log_history_on: inner.on,
28602879
log_history_log_only: inner.log_only,
@@ -2863,6 +2882,7 @@ impl From<InnerHistoryConfig> for HistoryLogConfig {
28632882
log_history_level: inner.level,
28642883
log_history_retention_interval: inner.retention_interval,
28652884
log_history_tables: inner.tables.into_iter().map(Into::into).collect(),
2885+
log_history_storage_params: inner_storage_config.map(Into::into),
28662886
}
28672887
}
28682888
}

0 commit comments

Comments
 (0)