Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major compaction write amplification #151

Open
crwen opened this issue Sep 12, 2024 · 0 comments
Open

Major compaction write amplification #151

crwen opened this issue Sep 12, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@crwen
Copy link
Contributor

crwen commented Sep 12, 2024

Bug Report

image
What did you do?

As illustrated in the picture, when flush, mem-table will be flushed to level0 and trigger major compaction.

  • first loop, [0-3], [5-8] in level 0 and [7-100] in level 1 are selected, and produce [0-100] in level 1
  • second loop [7-100] was selected again, and compacting with [100-150]

[7-100] involved twice, which will cause write and space amplification

My idea is to use a compact_status to record sstables that involved into compaction, and remove them in the next compaction

        let mut compact_status = HashSet::new();

        while level < MAX_LEVEL - 2 {
            if !option.is_threshold_exceeded_major(version, level) {
                break;
            }
            let (mut meet_scopes_l, start_l, end_l) =
                Self::this_level_scopes(version, min, max, level);
            let (mut meet_scopes_ll, start_ll, end_ll) =
                Self::next_level_scopes(version, &mut min, &mut max, level, &meet_scopes_l)?;

            // remain sstables that not involved in the compaction
            meet_scopes_l.retain(|scope| compact_status.insert(scope.gen));
            meet_scopes_ll.retain(|scope| compact_status.insert(scope.gen));

            // do compaction ......

            level += 1;
        }
@KKould KKould added the enhancement New feature or request label Sep 12, 2024
@ethe ethe added this to Tonbo Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants