2025-01-19 19:24:12 -05:00
|
|
|
// 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.
|
|
|
|
|
|
2024-01-20 11:11:09 +08:00
|
|
|
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,
|
2024-01-20 11:14:19 +08:00
|
|
|
_snapshot: &LsmStorageState,
|
|
|
|
|
_sst_ids: &[usize],
|
|
|
|
|
_in_level: usize,
|
2024-01-20 11:11:09 +08:00
|
|
|
) -> Vec<usize> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_compaction_task(
|
|
|
|
|
&self,
|
2024-01-20 11:14:19 +08:00
|
|
|
_snapshot: &LsmStorageState,
|
2024-01-20 11:11:09 +08:00
|
|
|
) -> Option<LeveledCompactionTask> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn apply_compaction_result(
|
|
|
|
|
&self,
|
2024-01-20 11:14:19 +08:00
|
|
|
_snapshot: &LsmStorageState,
|
|
|
|
|
_task: &LeveledCompactionTask,
|
|
|
|
|
_output: &[usize],
|
2024-07-02 20:25:43 -04:00
|
|
|
_in_recovery: bool,
|
2024-01-20 11:11:09 +08:00
|
|
|
) -> (LsmStorageState, Vec<usize>) {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|