Skip to main content
RotorTreeConfig controls all aspects of how a RotorTree persists data, including WAL flushing, checkpointing, and memory/disk tiering.

Definition

Defined in src/storage/mod.rs:56
pub struct RotorTreeConfig {
    pub path: PathBuf,
    pub flush_policy: FlushPolicy,
    pub checkpoint_policy: CheckpointPolicy,
    pub tiering: TieringConfig,
    pub verify_checkpoint: bool,
}

Fields

path
PathBuf
required
Directory path where the WAL and data files are stored. The directory will be created if it doesn’t exist.The structure will contain:
  • wal file for write-ahead log
  • data/ directory for checkpoint files after the first checkpoint
flush_policy
FlushPolicy
required
Controls when WAL entries are fsynced to disk.Options:
  • FlushPolicy::Interval(Duration) - Periodic fsync (default: 10ms)
  • FlushPolicy::Manual - Application controls via flush()
See FlushPolicy for details.
checkpoint_policy
CheckpointPolicy
required
Controls when checkpoints are triggered to materialize tree state to data files.Options:
  • Manual (default)
  • EveryNEntries(u64)
  • MemoryThreshold(usize)
  • OnClose
See CheckpointPolicy for details.
tiering
TieringConfig
required
Controls which tree levels are kept in memory vs mmap’d from disk after checkpoint.See TieringConfig for details.
verify_checkpoint
bool
required
When true, recomputes the Merkle root on recovery to detect corruption beyond CRC checks.Default: Typically set to true for maximum safety.Tradeoff: Setting to false speeds up recovery but only relies on CRC validation.

Usage Example

use rotortree::{
    Blake3Hasher, RotorTree, RotorTreeConfig,
    FlushPolicy, CheckpointPolicy, TieringConfig,
};
use std::path::PathBuf;
use std::time::Duration;

// Configuration with automatic checkpointing
let config = RotorTreeConfig {
    path: PathBuf::from("/tmp/my-tree"),
    flush_policy: FlushPolicy::Interval(Duration::from_millis(10)),
    checkpoint_policy: CheckpointPolicy::EveryNEntries(10_000),
    tiering: TieringConfig::default(), // all mmap'd
    verify_checkpoint: true,
};

let tree = RotorTree::<Blake3Hasher, 4, 20>::open(Blake3Hasher, config)?;

Common Configurations

High Throughput

RotorTreeConfig {
    path: PathBuf::from("/data/tree"),
    flush_policy: FlushPolicy::Interval(
        Duration::from_millis(100)
    ), // less frequent fsync
    checkpoint_policy: CheckpointPolicy::MemoryThreshold(
        1_073_741_824 // 1 GiB
    ),
    tiering: TieringConfig { pin_above_level: 2 },
    verify_checkpoint: false,
}

Maximum Safety

RotorTreeConfig {
    path: PathBuf::from("/data/tree"),
    flush_policy: FlushPolicy::Manual, // app controls
    checkpoint_policy: CheckpointPolicy::OnClose,
    tiering: TieringConfig { pin_above_level: 0 }, // all memory
    verify_checkpoint: true,
}

Blockchain Sync

RotorTreeConfig {
    path: PathBuf::from("/data/tree"),
    flush_policy: FlushPolicy::Manual,
    checkpoint_policy: CheckpointPolicy::Manual,
    tiering: TieringConfig::default(),
    verify_checkpoint: true,
}
Call flush() after each block, checkpoint() after each epoch.

Development

RotorTreeConfig {
    path: PathBuf::from("/tmp/dev-tree"),
    flush_policy: FlushPolicy::default(),
    checkpoint_policy: CheckpointPolicy::default(),
    tiering: TieringConfig::default(),
    verify_checkpoint: true,
}

Build docs developers (and LLMs) love