libsql_wal/storage/compaction/strategy/
log_strategy.rs

1use std::ops::Deref as _;
2
3use crate::storage::compaction::SegmentSet;
4
5use super::PartitionStrategy;
6
7/// partition the SegmentSet in logarithmically reducing sets
8pub struct LogReductionStrategy;
9
10impl PartitionStrategy for LogReductionStrategy {
11    fn partition(&self, segments: &SegmentSet) -> Vec<SegmentSet> {
12        let mut segs = segments.deref();
13        let mut out = Vec::new();
14        while !segs.is_empty() {
15            let (lhs, rhs) = segs.split_at(segs.len() / 2);
16            out.push(SegmentSet {
17                segments: lhs.to_vec(),
18                namespace: segments.namespace.clone(),
19            });
20            segs = rhs;
21            if segs.len() == 1 {
22                out.push(SegmentSet {
23                    segments: rhs.to_vec(),
24                    namespace: segments.namespace.clone(),
25                });
26                break;
27            }
28        }
29
30        out
31    }
32}