oxifaster
中文 | English
oxifaster is a Rust port of Microsoft's FASTER project, providing a high-performance concurrent key-value store and log engine.
Features
- High Performance: Efficient read/write operations for large-scale data exceeding memory capacity
- Concurrency Safe: Lock-free concurrent control based on Epoch protection mechanism
- Persistence: Complete Checkpoint and Recovery support with CPR protocol
- Hybrid Log: HybridLog architecture with hot data in memory + cold data on disk
- Async I/O: Async operation support based on Tokio runtime
- Read Cache: Hot data memory cache for accelerated reads, transparently integrated into the read path
- Log Compaction: Log compaction and space reclamation with automatic background compaction support
- Index Growth: Dynamic hash table expansion with rehash callback for correctness
- F2 Architecture: Two-tier storage with hot-cold data separation, including complete Checkpoint/Recovery
- Statistics: Comprehensive statistics collection integrated into all CRUD operations
- Prometheus Metrics: Render statistics snapshots as Prometheus text exposition for external scraping (feature =
prometheus)
Quick Start
Installation
Add the dependency to your Cargo.toml:
[]
= { = "oxifaster" }
Enable the Linux io_uring backend (feature-gated):
[]
= { = "oxifaster", = ["io_uring"] }
Note: the real io_uring backend is only available on Linux. On non-Linux platforms (or when the feature is disabled), IoUringDevice falls back to a portable file-backed implementation.
Enable Prometheus text exposition (for statistics snapshots):
[]
= { = "oxifaster", = ["prometheus"] }
With prometheus enabled, you can also run a minimal HTTP /metrics server (Tokio required):
use SocketAddr;
use Arc;
use NullDisk;
use ;
use ;
async
Basic Usage
use Arc;
use FileSystemDisk;
use ;
Configuration (TOML + Environment)
Use oxifaster::config::OxifasterConfig to load a TOML file and apply environment overrides.
Example oxifaster.toml:
[]
= 1048576
= 536870912
= 22
= 0.9
[]
= 0.5
= 1048576
= 1073741824
= 1
= true
[]
= true
= 268435456
= 0.9
= false
= true
[]
= "single_file"
= "oxifaster.db"
Load from OXIFASTER_CONFIG and apply overrides such as OXIFASTER__store__table_size=2097152:
use OxifasterConfig;
let config = load_from_env?;
let store_config = config.to_faster_kv_config;
let compaction_config = config.to_compaction_config;
let cache_config = config.to_read_cache_config;
let device = config.open_device?;
Development Roadmap
Please refer to DEV.md for the detailed development roadmap, implementation status, and technical debt analysis.
Module Structure
oxifaster/
├── src/
│ ├── lib.rs # Library entry
│ ├── address.rs # Address system (Address, AtomicAddress)
│ ├── record.rs # Record structure (RecordInfo, Record, Key, Value)
│ ├── status.rs # Status codes (Status, OperationStatus)
│ ├── utility.rs # Utility functions
│ │
│ ├── epoch/ # Epoch protection mechanism
│ │ ├── mod.rs
│ │ └── light_epoch.rs
│ │
│ ├── index/ # Hash index
│ │ ├── mod.rs
│ │ ├── hash_bucket.rs
│ │ ├── hash_table.rs
│ │ ├── mem_index.rs
│ │ ├── grow.rs # Index growth
│ │ └── cold_index.rs # Disk cold index
│ │
│ ├── allocator/ # Memory allocator
│ │ ├── mod.rs
│ │ ├── page_allocator.rs
│ │ └── hybrid_log.rs
│ │
│ ├── device/ # Storage devices
│ │ ├── mod.rs
│ │ ├── traits.rs
│ │ ├── file_device.rs
│ │ ├── null_device.rs
│ │ ├── io_uring.rs # io_uring entrypoint (Linux + mock)
│ │ ├── io_uring_common.rs # Shared types
│ │ ├── io_uring_linux.rs # Linux backend (feature = "io_uring")
│ │ └── io_uring_mock.rs # Non-Linux / feature off fallback
│ │
│ ├── store/ # FasterKV store
│ │ ├── mod.rs
│ │ ├── faster_kv.rs
│ │ ├── session.rs
│ │ ├── contexts.rs
│ │ └── state_transitions.rs
│ │
│ ├── checkpoint/ # Checkpoint and recovery
│ │ ├── mod.rs
│ │ ├── state.rs
│ │ ├── locks.rs # CPR checkpoint locks
│ │ ├── recovery.rs
│ │ └── serialization.rs
│ │
│ ├── log/ # FASTER Log
│ │ ├── mod.rs
│ │ └── faster_log.rs
│ │
│ ├── cache/ # Read Cache
│ │ ├── mod.rs
│ │ ├── config.rs
│ │ ├── read_cache.rs
│ │ ├── record_info.rs
│ │ └── stats.rs
│ │
│ ├── compaction/ # Log compaction
│ │ ├── mod.rs
│ │ ├── compact.rs
│ │ ├── concurrent.rs # Concurrent compaction
│ │ ├── auto_compact.rs # Auto compaction background thread
│ │ └── contexts.rs
│ │
│ ├── f2/ # F2 hot-cold architecture
│ │ ├── mod.rs
│ │ ├── config.rs
│ │ ├── store.rs
│ │ └── state.rs
│ │
│ ├── scan/ # Log scanning
│ │ ├── mod.rs
│ │ └── log_iterator.rs
│ │
│ └── stats/ # Statistics collection
│ ├── mod.rs
│ ├── collector.rs
│ ├── metrics.rs
│ └── reporter.rs
│
├── examples/ # Example code
│ ├── async_operations.rs
│ ├── basic_kv.rs
│ ├── cold_index.rs
│ ├── compaction.rs
│ ├── concurrent_access.rs
│ ├── custom_types.rs
│ ├── epoch_protection.rs
│ ├── f2_hot_cold.rs
│ ├── faster_log.rs
│ ├── index_growth.rs
│ ├── log_scan.rs
│ ├── read_cache.rs
│ ├── statistics.rs
│ └── variable_length.rs
│
├── benches/
│ └── ycsb.rs # YCSB benchmark
│
└── tests/
├── async_session.rs # Async session tests
├── basic_ops.rs # Basic operations tests
├── checkpoint_locks.rs # Checkpoint locks tests
├── checkpoint.rs # Checkpoint tests
├── cold_index.rs # Cold index tests
├── compaction.rs # Compaction tests
├── f2.rs # F2 tests
├── incremental_checkpoint.rs # Incremental checkpoint tests
├── index_growth.rs # Index growth tests
├── log_scan.rs # Log scan tests
├── read_cache.rs # Read cache tests
├── recovery.rs # Recovery tests
├── statistics.rs # Statistics tests
└── varlen.rs # Variable length tests
Core Concepts
Address
48-bit logical address used to identify record positions in the hybrid log:
- 25-bit page offset (32 MB per page)
- 23-bit page number (~8 million pages)
Epoch Protection
Lightweight epoch protection mechanism for:
- Safe memory reclamation
- Lock-free concurrent control
- Delayed operation execution
Hybrid Log
Hybrid log allocator managing memory and disk storage:
- Mutable Region: Latest pages supporting in-place updates
- Read-Only Region: Older pages in memory
- Disk Region: Cold data
Hash Index
High-performance in-memory hash index:
- Cache-line aligned hash buckets (64 bytes)
- 14-bit tags for fast comparison
- Overflow bucket support
- Dynamic expansion support
Read Cache
Hot data cache:
- In-memory storage for frequently read records
- LRU-like eviction policy
- Transparently integrated into read path
Log Compaction
Space reclamation mechanism:
- Scan old record regions
- Retain latest version records
- Release expired space
API Reference
FasterKv
Main KV store class:
use Arc;
use FileSystemDisk;
use ;
// Create store
let config = default;
let store_device = single_file?;
let store = new;
// Start session
let mut session = store.start_session.expect;
// Basic operations
session.upsert; // Insert/Update
let value = session.read?; // Read
session.delete; // Delete
session.rmw; // Read-Modify-Write
// Checkpoint and Recovery (Phase 2 complete)
let token = store.checkpoint?; // Create checkpoint
let recovered = recover?;
// Session persistence
let states = store.get_recovered_sessions; // Get recovered session states
let session = store
.continue_session
.expect; // Restore session from saved state
FasterKv with Read Cache
Enable read cache:
use ReadCacheConfig;
let cache_config = default
.with_mem_size // 256 MB
.with_mutable_fraction;
let store = with_read_cache;
FasterKv with Compaction
Enable compaction:
use CompactionConfig;
let compaction_config = default
.with_target_utilization
.with_num_threads;
let store = with_compaction_config;
Automatic Background Compaction
Start a background compaction worker and manage its lifecycle via the returned handle:
use AutoCompactionConfig;
let handle = store.start_auto_compaction;
drop; // Stops and joins the worker thread
FasterLog
Standalone high-performance log:
use ;
use FileSystemDisk;
let config = default;
let device = single_file?;
let log = open?;
// Append data
let addr = log.append?;
// Commit
log.commit?;
// Read
let data = log.read_entry;
// Scan all entries
for in log.scan_all
F2Kv (Hot-Cold Architecture)
Two-tier storage architecture:
use ;
let config = F2Config ;
let f2_store = new;
Statistics
Collect performance statistics:
use ;
let stats = store.stats;
println!;
println!;
println!;
Running Examples
Note: most examples will run twice to compare devices — first with NullDisk (in-memory), then with FileSystemDisk (temp file).
# Async operations
# Basic KV operations
# io_uring (Linux, enable feature for real backend)
# Cold index
# Compaction
# Concurrent access
# Custom types
# Epoch protection
# F2 hot-cold architecture
# FasterLog
# Index growth
# Log scan
# Read cache
# Statistics
# Variable length
Running Tests
Running Benchmarks
Contributing
Contributions are welcome! Please check DEV.md for the development roadmap and technical debt analysis.
Development Workflow
- Fork this repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -am 'Add new feature' - Push branch:
git push origin feature/your-feature - Create Pull Request
Code Standards
- Use
cargo fmtto format code - Use
cargo clippyfor code quality checks - Add unit tests for new features
- Update relevant documentation
References
License
MIT License
Acknowledgments
Thanks to the Microsoft FASTER team for their open-source contributions.