FlushPolicy determines the durability guarantees for insertions by controlling when buffered write-ahead log entries are fsynced to disk.
Definition
Defined insrc/storage/mod.rs:70
Variants
Interval(Duration)
A background thread periodically fsyncs the WAL buffer at the specified interval.
Default: Duration::from_millis(10)
Time interval between fsync operations.Common values:
10ms- Default, good balance of throughput and durability1ms- Lower latency, higher overhead100ms- Higher throughput, longer recovery window
- Shorter intervals = lower durability latency, higher CPU overhead
- Longer intervals = higher throughput, larger recovery window
- You want automatic durability without managing flushes
- Acceptable to lose up to
intervalworth of writes on crash - Trading off some durability for better throughput
Manual
The application controls when to fsync by calling tree.flush() explicitly.
No automatic flushing occurs. Insertions are buffered in memory until:
- Application calls
flush() - Tree checkpoint occurs (flushes before checkpointing)
- Tree is closed (flushes on graceful shutdown)
- You have natural flush points (e.g., after each blockchain block)
- You want maximum control over durability vs performance tradeoff
- Your application has its own batching logic
- You’re okay with manual durability management
Usage Examples
Automatic Periodic Flushing
Manual Flushing
Blockchain Integration Pattern
Durability Guarantees
| Policy | Durability | Max Data Loss on Crash | Performance |
|---|---|---|---|
Interval(1ms) | High | ≤1ms of writes | Medium-High |
Interval(10ms) | Medium | ≤10ms of writes | High |
Interval(100ms) | Low | ≤100ms of writes | Very High |
Manual | Application-controlled | Depends on flush frequency | Maximum |
Performance Considerations
fsync operations are relatively expensive. The flush policy significantly impacts throughput:
Interval(10ms): ~100 fsyncs/secondInterval(100ms): ~10 fsyncs/secondManualwith batching: Can achieve >1M inserts/sec between flushes
Measuring Flush Impact
- SSD: 0.1-1ms
- HDD: 5-10ms
- NVMe: 0.05-0.3ms
Default Value
Related
- DurabilityToken - Waiting for specific inserts to become durable
- RotorTree::flush() - Manual flush method
- RotorTree::insert_durable() - Insert + flush in one call
- RotorTreeConfig - Full configuration structure
