Files
mini_lsm/mini-lsm-starter/src/compact/leveled.rs

72 lines
2.0 KiB
Rust
Raw Normal View History

// Copyright (c) 2022-2025 Alex Chi Z
//
// 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};
use crate::lsm_storage::LsmStorageState;
#[derive(Debug, Serialize, Deserialize)]
pub struct LeveledCompactionTask {
// if upper_level is `None`, then it is L0 compaction
pub upper_level: Option<usize>,
pub upper_level_sst_ids: Vec<usize>,
pub lower_level: usize,
pub lower_level_sst_ids: Vec<usize>,
pub is_lower_level_bottom_level: bool,
}
#[derive(Debug, Clone)]
pub struct LeveledCompactionOptions {
pub level_size_multiplier: usize,
pub level0_file_num_compaction_trigger: usize,
pub max_levels: usize,
pub base_level_size_mb: usize,
}
pub struct LeveledCompactionController {
options: LeveledCompactionOptions,
}
impl LeveledCompactionController {
pub fn new(options: LeveledCompactionOptions) -> Self {
Self { options }
}
fn find_overlapping_ssts(
&self,
_snapshot: &LsmStorageState,
_sst_ids: &[usize],
_in_level: usize,
) -> Vec<usize> {
unimplemented!()
}
pub fn generate_compaction_task(
&self,
_snapshot: &LsmStorageState,
) -> Option<LeveledCompactionTask> {
unimplemented!()
}
pub fn apply_compaction_result(
&self,
_snapshot: &LsmStorageState,
_task: &LeveledCompactionTask,
_output: &[usize],
_in_recovery: bool,
) -> (LsmStorageState, Vec<usize>) {
unimplemented!()
}
}