Skip to content

Commit

Permalink
refactor: change max_active_window_files to max_active_window_runs
Browse files Browse the repository at this point in the history
  • Loading branch information
v0y4g3r committed Apr 16, 2024
1 parent 6dc0ad2 commit d1762b9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/mito2/src/compaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CompactionRequest {
pub fn compaction_options_to_picker(strategy: &CompactionOptions) -> CompactionPickerRef {
match strategy {
CompactionOptions::Twcs(twcs_opts) => Arc::new(TwcsPicker::new(
twcs_opts.max_active_window_files,
twcs_opts.max_active_window_runs,
twcs_opts.max_inactive_window_files,
twcs_opts.time_window_seconds(),
)) as Arc<_>,
Expand Down
13 changes: 7 additions & 6 deletions src/mito2/src/compaction/twcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tokio::sync::mpsc;
use crate::access_layer::{AccessLayerRef, SstWriteRequest};
use crate::cache::CacheManagerRef;
use crate::compaction::picker::{CompactionTask, Picker};
use crate::compaction::run::find_sorted_runs;
use crate::compaction::CompactionRequest;
use crate::config::MitoConfig;
use crate::error::{self, CompactRegionSnafu};
Expand All @@ -55,35 +56,35 @@ const LEVEL_COMPACTED: Level = 1;
/// `TwcsPicker` picks files of which the max timestamp are in the same time window as compaction
/// candidates.
pub struct TwcsPicker {
max_active_window_files: usize,
max_active_window_runs: usize,
max_inactive_window_files: usize,
time_window_seconds: Option<i64>,
}

impl Debug for TwcsPicker {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TwcsPicker")
.field("max_active_window_files", &self.max_active_window_files)
.field("max_active_window_runs", &self.max_active_window_runs)
.field("max_inactive_window_files", &self.max_inactive_window_files)
.finish()
}
}

impl TwcsPicker {
pub fn new(
max_active_window_files: usize,
max_active_window_runs: usize,
max_inactive_window_files: usize,
time_window_seconds: Option<i64>,
) -> Self {
Self {
max_inactive_window_files,
max_active_window_files,
max_active_window_runs,
time_window_seconds,
}
}

/// Builds compaction output from files.
/// For active writing window, we allow for at most `max_active_window_files` files to alleviate
/// For active writing window, we allow for at most `max_active_window_runs` files to alleviate
/// fragmentation. For other windows, we allow at most 1 file at each window.
fn build_output(
&self,
Expand All @@ -96,7 +97,7 @@ impl TwcsPicker {
&& *window == active_window
{
// inside active window
if files.len() > self.max_active_window_files {
if files.len() > self.max_active_window_runs {
output.push(CompactionOutput {
output_file_id: FileId::random(),
output_level: LEVEL_COMPACTED,
Expand Down
2 changes: 1 addition & 1 deletion src/mito2/src/engine/append_mode_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn test_append_mode_compaction() {

let request = CreateRequestBuilder::new()
.insert_option("compaction.type", "twcs")
.insert_option("compaction.twcs.max_active_window_files", "2")
.insert_option("compaction.twcs.max_active_window_runs", "2")
.insert_option("compaction.twcs.max_inactive_window_files", "2")
.insert_option("append_mode", "true")
.build();
Expand Down
16 changes: 8 additions & 8 deletions src/mito2/src/region/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ impl Default for CompactionOptions {
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default)]
pub struct TwcsOptions {
/// Max num of files that can be kept in active writing time window.
/// Max num of sorted runs that can be kept in active writing time window.
#[serde_as(as = "DisplayFromStr")]
pub max_active_window_files: usize,
pub max_active_window_runs: usize,
/// Max num of files that can be kept in inactive time window.
#[serde_as(as = "DisplayFromStr")]
pub max_inactive_window_files: usize,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl TwcsOptions {
impl Default for TwcsOptions {
fn default() -> Self {
Self {
max_active_window_files: 4,
max_active_window_runs: 4,
max_inactive_window_files: 1,
time_window: None,
}
Expand Down Expand Up @@ -381,7 +381,7 @@ mod tests {
#[test]
fn test_without_compaction_type() {
let map = make_map(&[
("compaction.twcs.max_active_window_files", "8"),
("compaction.twcs.max_active_window_runs", "8"),
("compaction.twcs.time_window", "2h"),
]);
let err = RegionOptions::try_from(&map).unwrap_err();
Expand All @@ -391,14 +391,14 @@ mod tests {
#[test]
fn test_with_compaction_type() {
let map = make_map(&[
("compaction.twcs.max_active_window_files", "8"),
("compaction.twcs.max_active_window_runs", "8"),
("compaction.twcs.time_window", "2h"),
("compaction.type", "twcs"),
]);
let options = RegionOptions::try_from(&map).unwrap();
let expect = RegionOptions {
compaction: CompactionOptions::Twcs(TwcsOptions {
max_active_window_files: 8,
max_active_window_runs: 8,
time_window: Some(Duration::from_secs(3600 * 2)),
..Default::default()
}),
Expand Down Expand Up @@ -484,7 +484,7 @@ mod tests {
});
let map = make_map(&[
("ttl", "7d"),
("compaction.twcs.max_active_window_files", "8"),
("compaction.twcs.max_active_window_runs", "8"),
("compaction.twcs.max_inactive_window_files", "2"),
("compaction.twcs.time_window", "2h"),
("compaction.type", "twcs"),
Expand All @@ -505,7 +505,7 @@ mod tests {
let expect = RegionOptions {
ttl: Some(Duration::from_secs(3600 * 24 * 7)),
compaction: CompactionOptions::Twcs(TwcsOptions {
max_active_window_files: 8,
max_active_window_runs: 8,
max_inactive_window_files: 2,
time_window: Some(Duration::from_secs(3600 * 2)),
}),
Expand Down
4 changes: 2 additions & 2 deletions src/store-api/src/mito_engine_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn is_mito_engine_option_key(key: &str) -> bool {
[
"ttl",
"compaction.type",
"compaction.twcs.max_active_window_files",
"compaction.twcs.max_active_window_runs",
"compaction.twcs.max_inactive_window_files",
"compaction.twcs.time_window",
"storage",
Expand All @@ -47,7 +47,7 @@ mod tests {
assert!(is_mito_engine_option_key("ttl"));
assert!(is_mito_engine_option_key("compaction.type"));
assert!(is_mito_engine_option_key(
"compaction.twcs.max_active_window_files"
"compaction.twcs.max_active_window_runs"
));
assert!(is_mito_engine_option_key(
"compaction.twcs.max_inactive_window_files"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ with(
'regions'=1,
'ttl'='7d',
'compaction.type'='twcs',
'compaction.twcs.max_active_window_files'='8',
'compaction.twcs.max_active_window_runs'='2',
'compaction.twcs.max_inactive_window_files'='2',
'compaction.twcs.time_window'='1d',
'index.inverted_index.ignore_column_ids'='1,2,3',
Expand All @@ -91,7 +91,7 @@ create table if not exists invalid_compaction(
PRIMARY KEY(host)
)
engine=mito
with('compaction.type'='twcs', 'compaction.twcs.max_active_window_files'='8d');
with('compaction.type'='twcs', 'compaction.twcs.max_active_window_runs'='8d');

Error: 1004(InvalidArguments), Invalid options: invalid digit found in string

4 changes: 2 additions & 2 deletions tests/cases/standalone/common/create/create_with_options.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ with(
'regions'=1,
'ttl'='7d',
'compaction.type'='twcs',
'compaction.twcs.max_active_window_files'='8',
'compaction.twcs.max_active_window_runs'='8',
'compaction.twcs.max_inactive_window_files'='2',
'compaction.twcs.time_window'='1d',
'index.inverted_index.ignore_column_ids'='1,2,3',
Expand All @@ -77,4 +77,4 @@ create table if not exists invalid_compaction(
PRIMARY KEY(host)
)
engine=mito
with('compaction.type'='twcs', 'compaction.twcs.max_active_window_files'='8d');
with('compaction.type'='twcs', 'compaction.twcs.max_active_window_runs'='8d');

0 comments on commit d1762b9

Please sign in to comment.