Skip to content

Commit 0907c88

Browse files
Subsegmentroseboy-liu
authored andcommitted
refactor: add config for datablock size
1 parent 0039ea5 commit 0907c88

9 files changed

Lines changed: 26 additions & 3 deletions

File tree

config/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ strict_write = false
6767
## copyinto trigger flush size
6868
#copyinto_trigger_flush_size = "128M" # 134217728
6969

70+
## The maximum size of a datablock in compaction.
71+
max_datablock_size = 102400
72+
7073
[wal]
7174

7275
## If true, write requets on disk before writing to memory.

config/config_8902.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ max_concurrent_compaction = 4
4040
strict_write = false
4141
reserve_space = "0"
4242
copyinto_trigger_flush_size = "128M" # 134217728
43+
max_datablock_size = 102400
4344

4445
[wal]
4546
enabled = true

config/config_8912.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ max_concurrent_compaction = 4
4040
strict_write = false
4141
reserve_space = "0"
4242
copyinto_trigger_flush_size = "128M" # 134217728
43+
max_datablock_size = 102400
4344

4445
[wal]
4546
enabled = true

config/config_8922.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ max_compact_size = "2G" # 2147483648
3939
max_concurrent_compaction = 4
4040
strict_write = false
4141
reserve_space = "0"
42+
max_datablock_size = 102400
4243

4344
[wal]
4445
enabled = true

config/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ strict_write = false
326326
# The size of reserve space of the system.
327327
reserve_space = "10G"
328328
329+
## The maximum size of a datablock in compaction.
330+
max_datablock_size = 102400
331+
329332
[wal]
330333
331334
## If true, write requets on disk before writing to memory.

config/src/storage_config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pub struct StorageConfig {
5959
default = "StorageConfig::default_copyinto_trigger_flush_size"
6060
)]
6161
pub copyinto_trigger_flush_size: u64,
62+
63+
#[serde(default = "StorageConfig::default_max_datablock_size")]
64+
pub max_datablock_size: u64,
6265
}
6366

6467
impl StorageConfig {
@@ -115,6 +118,10 @@ impl StorageConfig {
115118
128 * 1024 * 1024 // 128M
116119
}
117120

121+
fn default_max_datablock_size() -> u64 {
122+
100 * 1024
123+
}
124+
118125
pub fn introspect(&mut self) {
119126
// Unit of storage.compact_trigger_cold_duration is seconds
120127
self.compact_trigger_cold_duration =
@@ -160,6 +167,11 @@ impl OverrideByEnv for StorageConfig {
160167
&mut self.copyinto_trigger_flush_size,
161168
"CNOSDB_COPYINTO_TRIGGER_FLUSH_SIZE",
162169
);
170+
entry_override(&mut self.reserve_space, "CNOSDB_STORAGE_RESERVE_SPACE");
171+
entry_override(
172+
&mut self.max_datablock_size,
173+
"CNOSDB_STORAGE_MAX_DATABLOCK_SIZE",
174+
);
163175
}
164176
}
165177

@@ -179,6 +191,7 @@ impl Default for StorageConfig {
179191
strict_write: Self::default_strict_write(),
180192
reserve_space: Self::default_reserve_space(),
181193
copyinto_trigger_flush_size: Self::default_copyinto_trigger_flush_size(),
194+
max_datablock_size: Self::default_max_datablock_size(),
182195
}
183196
}
184197
}

tskv/src/compaction/compact.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::compaction::CompactReq;
1212
use crate::context::GlobalContext;
1313
use crate::error::TskvResult;
1414
use crate::summary::{CompactMeta, VersionEdit};
15-
use crate::tseries_family::TseriesFamily;
1615
use crate::tsm::chunk::Chunk;
1716
use crate::tsm::column_group::ColumnGroup;
1817
use crate::tsm::data_block::DataBlock;
@@ -770,7 +769,7 @@ pub async fn run_compaction_job(
770769
tsm_readers.push(tsm_reader);
771770
}
772771

773-
let max_block_size = TseriesFamily::MAX_DATA_BLOCK_SIZE as usize;
772+
let max_block_size = request.storage_opt.max_datablock_size as usize;
774773
let mut iter = CompactIterator::new(tsm_readers);
775774
let tsm_dir = request.storage_opt.tsm_dir(&request.database, tsf_id);
776775
let max_file_size = request.storage_opt.level_max_file_size(request.out_level);
@@ -1058,6 +1057,7 @@ pub mod test {
10581057
pub(crate) fn create_options(base_dir: String) -> Arc<Options> {
10591058
let mut config = config::get_config_for_test();
10601059
config.storage.path = base_dir;
1060+
config.storage.max_datablock_size = 1000;
10611061
let opt = Options::from(&config);
10621062
Arc::new(opt)
10631063
}

tskv/src/kv_option.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct StorageOptions {
4949
pub max_concurrent_compaction: u16,
5050
pub strict_write: bool,
5151
pub snapshot_holding_time: i64,
52+
pub max_datablock_size: u64,
5253
}
5354

5455
// database/data/ts_family_id/tsm
@@ -105,6 +106,7 @@ impl From<&Config> for StorageOptions {
105106
max_concurrent_compaction: config.storage.max_concurrent_compaction,
106107
strict_write: config.storage.strict_write,
107108
snapshot_holding_time: config.cluster.snapshot_holding_time.as_secs() as i64,
109+
max_datablock_size: config.storage.max_datablock_size,
108110
}
109111
}
110112
}

tskv/src/tseries_family.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ pub struct TseriesFamily {
873873
}
874874

875875
impl TseriesFamily {
876-
pub const MAX_DATA_BLOCK_SIZE: u32 = 1000;
877876
#[allow(clippy::too_many_arguments)]
878877
#[cfg(test)]
879878
pub fn new(

0 commit comments

Comments
 (0)