| Crates.io | rocksolid |
| lib.rs | rocksolid |
| version | 2.5.6 |
| created_at | 2025-04-27 18:09:46.887017+00 |
| updated_at | 2025-11-20 04:33:01.525519+00 |
| description | An ergonomic, high-level RocksDB wrapper for Rust. Features CF-aware optimistic & pessimistic transactions, advanced routing for merge operators and compaction filters, performance tuning profiles, batching, TTL values, and DAO macros. |
| homepage | |
| repository | https://github.com/excsn/rocksolid |
| max_upload_size | |
| id | 1651343 |
| size | 603,328 |
RockSolid Store is a Rust library providing a robust, ergonomic, and opinionated persistence layer on top of the powerful RocksDB embedded key-value store. It aims to simplify common database interactions while offering flexibility for advanced use cases through comprehensive Column Family (CF) support, powerful transactional models, and advanced tuning capabilities.
Ergonomic, Layered Architecture:
RocksDbCFStore provides a complete API for operations on any named Column Family.RocksDbStore and its transactional counterparts provide simplified APIs for common use cases targeting only the default Column Family.CFOperations and DefaultCFOperations traits, ensuring a predictable experience across store types.Powerful Transaction Models:
RocksDbCFTxnStore enables standard, locking transactions across multiple Column Families. The TransactionContext provides a safe, RAII-based API that guarantees automatic rollback on drop.RocksDbCFOptimisticTxnStore provides a high-performance transactional model.
optimistic_transaction() builder encapsulates complex conflict detection and retry logic.RetryPolicy trait for custom backoff strategies.Advanced Data Handling & Logic:
MergeRouterBuilder allows routing of merge operations to different handler functions based on key patterns, enabling complex data aggregation within a single Column Family.CompactionFilterRouterBuilder enables custom logic (remove, keep, or change value) during compaction, routed by key patterns. Ideal for implementing TTLs, data scrubbing, or schema migrations.ValueWithExpiry<T> type simplifies storing data with a TTL. When combined with a compaction filter, this provides an efficient mechanism for automatic data expiration.natlex_sort, nat_sort), configurable per-CF.Performance & Flexibility:
BatchWriter provides an ergonomic API for grouping write operations (put, delete, merge) atomically on a specific Column Family.TuningProfile enum offers pre-configured settings for common workloads (LatestValue, TimeSeries, MemorySaver, RealTime).rocksdb::Options via callbacks.Developer Experience:
serde for values (MessagePack via rmp-serde) and an AsBytes trait for keys.generate_dao_get_cf!, generate_dao_put_in_txn!) to reduce boilerplate for data access patterns.StoreError enum and StoreResult<T> for robust error management.Add rocksolid to your Cargo.toml:
[dependencies]
rocksolid = "X.Y.Z" # Replace with the latest version
serde = { version = "1.0", features = ["derive"] }
# tempfile = "3" # Useful for examples and tests
# env_logger = "0.11" # For enabling logging
For custom comparators (natural sort), enable the corresponding features:
rocksolid = { version = "X.Y.Z", features = ["natlex_sort", "nat_sort"] }
Ensure RocksDB system dependencies are installed. Refer to the rust-rocksdb documentation for system-specific instructions (e.g., librocksdb-dev, clang, llvm).
The examples/ directory in the repository contains runnable code demonstrating all major features:
basic_usage.rs: Simple non-transactional CRUD.cf_store_operations.rs: Using multiple Column Families.transactional.rs: Pessimistic transactions on the default CF.cf_txn_store_operations.rs: Pessimistic transactions across multiple CFs.optimistic_transaction.rs: A complete example of an optimistic transaction with a multi-threaded conflict and automatic retry.batching.rs: Atomic batch writes.compaction_filter_routing.rs: Implementing TTLs and data migration.merge_routing.rs: Custom data aggregation logic.tuning_showcase.rs: Applying performance tuning profiles.Run an example with: cargo run --example basic_usage.
For an exhaustive list of all public types, traits, functions, and their detailed signatures, please refer to the generated rustdoc documentation on docs.rs. A summary can also be found in API_REFERENCE.md in the repository.
Choose your Store:
RocksDbStore (default CF) or RocksDbCFStore (multi-CF).RocksDbTxnStore (default CF) or RocksDbCFTxnStore (multi-CF).RocksDbOptimisticTxnStore (default CF) or RocksDbCFOptimisticTxnStore (multi-CF).Configuration is Key: Use the appropriate config struct (e.g., RocksDbCFStoreConfig) to define paths, CFs, and apply BaseCfConfig settings like tuning profiles, merge operators, or compaction filters.
Batching for Atomicity: Use store.batch_writer("cf_name") to get a BatchWriter for atomic writes to a single CF.
Transactions for Complex Atomicity:
store.execute_transaction(|txn| { ... }) for guaranteed locking.store.optimistic_transaction().execute_with_snapshot(|txn| { ... }) for high-throughput operations with automatic conflict detection and retries.Contributions are welcome! Please feel free to open an issue to discuss bugs, feature requests, or potential improvements. Pull requests are also encouraged.
Licensed under the Mozilla Public License Version 2.0. See LICENSE for details.