Skip to main content

KWayMerger

Struct KWayMerger 

Source
pub struct KWayMerger { /* private fields */ }
Expand description

K-way merger for combining multiple SSTables

Uses a min-heap to efficiently merge k sorted SSTable runs into a single output. Each run maintains a small peek buffer for efficient lookahead.

§Usage

// Create merger from input SSTable paths
let merger = KWayMerger::new(input_paths, &schema)?;

// Option 1: Full merge to output writer
let stats = merger.merge(&mut output_writer)?;

// Option 2: Incremental merge (step-by-step)
loop {
    match merger.step()? {
        MergeStep::Partition { key, rows } => {
            // Process partition
        }
        MergeStep::Complete => break,
    }
}

Implementations§

Source§

impl KWayMerger

Source

pub fn new(input_paths: Vec<PathBuf>, schema: &TableSchema) -> Result<Self>

Create a new k-way merger from input SSTable paths

§Arguments
  • input_paths - Paths to input SSTable Data.db files (ordered newest to oldest)
  • schema - Table schema for schema-aware merging
§Returns

A new KWayMerger ready to merge the input SSTables.

§Errors

Returns an error if any input SSTable cannot be opened.

§Example
let input_paths = vec![
    PathBuf::from("data/nb-1-big-Data.db"),
    PathBuf::from("data/nb-2-big-Data.db"),
];
let merger = KWayMerger::new(input_paths, &schema)?;
Source

pub fn merge(self, output_writer: &mut SSTableWriter) -> Result<MergeStats>

Perform a full merge to the output writer

This is a convenience method that repeatedly calls step() until the merge is complete, writing each partition to the output writer.

§Arguments
  • output_writer - SSTableWriter to write merged output
§Returns

Statistics about the merge operation.

§Errors

Returns an error if reading or writing fails.

Source

pub fn step(&mut self) -> Result<MergeStep>

Perform one merge step (one partition)

Returns the next merged partition, or Complete if the merge is done. This allows incremental merging for better memory control.

§Returns
  • MergeStep::Partition - Next merged partition with all its rows
  • MergeStep::Complete - Merge is complete
§Errors

Returns an error if reading fails.

Trait Implementations§

Source§

impl Debug for KWayMerger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.