Skip to main content

MergeOperator

Trait MergeOperator 

Source
pub trait MergeOperator: Send + Sync {
    // Required methods
    fn combine_operands(&self, key: &[u8], left: &[u8], right: &[u8]) -> Vec<u8> ⓘ;
    fn apply(
        &self,
        key: &[u8],
        base: Option<&[u8]>,
        operand: &[u8],
    ) -> Option<Vec<u8>>;
}
Expand description

user-provided merge operator for a bucket

The operator turns a base value plus a chain of merge operands into the logical value:

apply(base, combine_operands(a, b)) == apply(apply(base, a), b)

base = None stands for “key absent or deleted” and belongs to the domain of apply. Implementations must be deterministic and must satisfy associativity, commutativity of combine_operands, and the base action law above. They must not read time, randomness, external I/O, or mutable process state, and must not produce observable side effects: compaction and split may retry or redo fold attempts.

Reads combine operands from newest to oldest; compaction combines them from oldest to newest. Commutativity and associativity make the two orders equivalent. The methods are total and must return non-empty results; an empty or oversized result is an engine-detected violation. None from apply is the only logical deletion. The engine does not invoke the operator during merge admission or catch panics.

The engine stores only this runtime handle and never persists operator identity. Callers own semantic compatibility across process restarts.

Required Methods§

Source

fn combine_operands(&self, key: &[u8], left: &[u8], right: &[u8]) -> Vec<u8> ⓘ

Combines two operands into one equivalent operand. Must return a non-empty equivalent operand for every pair the operator accepted.

Source

fn apply( &self, key: &[u8], base: Option<&[u8]>, operand: &[u8], ) -> Option<Vec<u8>>

Applies one operand to a base value. None deletes or leaves the key absent; Some(value) must be non-empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§