| Crates.io | rocksolid |
| lib.rs | rocksolid |
| version | 2.4.2 |
| created_at | 2025-04-27 18:09:46.887017+00 |
| updated_at | 2025-09-09 00:19:57.666935+00 |
| description | An ergonomic persistence layer over RocksDB, offering Column Family support, transactions (CF-aware), batching, merge routing, value expiry, and performance tuning. |
| homepage | |
| repository | https://github.com/excsn/rocksolid |
| max_upload_size | |
| id | 1651343 |
| size | 474,375 |
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, transactional operations, and advanced tuning capabilities.
RocksDbCFStore: The foundational non-transactional store for operations on any named Column Family.RocksDbStore: A convenience wrapper for non-transactional operations targeting the default Column Family.RocksDbCFTxnStore: The core transactional store, enabling pessimistic transactions across multiple Column Families.RocksDbTxnStore: A convenience wrapper for transactional operations on the default Column Family.TuningProfile enum for common workloads like LatestValue, TimeSeries, MemorySaver).rocksdb::Options via callbacks using the Tunable wrapper.TransactionDBOptions.CFOperations and DefaultCFOperations traits.IterConfig) supporting deserialized items, raw byte pairs, or control-only processing, with prefix and range scanning, and custom control functions.serde for values (MessagePack via rmp-serde) and an AsBytes trait for keys (typically raw byte sequences).RocksDbCFTxnStore.TransactionContext for managing operations within a default-CF transaction with a fluent API.BatchWriter for grouping write operations (put, delete, merge) atomically on a single, specified Column Family.BatchWriter::raw_batch_mut() escape hatch.MergeRouterBuilder: Allows routing merge operations based on key patterns to different handler functions within the same CF. The resulting MergeOperatorConfig is then applied to the desired CF.CompactionFilterRouterBuilder: Enables defining custom logic (remove, keep, change value) during RocksDB's compaction process, routed by key patterns. Ideal for implementing TTL, data scrubbing, or schema migrations. The resulting RockSolidCompactionFilterRouterConfig is applied to the desired CF.MergeRouterBuilder and CompactionFilterRouterBuilder) rely on globally shared static matchit::Router instances. This means routes added via any builder instance become part of a single, application-wide routing table for that type of operator.
operator_name in the builder and applying the built config), they will all share the same set of routes.ValueWithExpiry<T>. Actual data removal based on expiry typically requires a custom compaction filter (e.g., using the CompactionFilterRouterBuilder with a handler that checks ValueWithExpiry.expire_time).natlex_sort, nat_sort) configurable per CF.StoreError enum and StoreResult<T> for clear error reporting.generate_dao_get_cf!, generate_dao_put_in_txn!) to reduce boilerplate for common data access patterns.Installation:
Add rocksolid to your Cargo.toml:
[dependencies]
rocksolid = "X.Y.Z" # Replace X.Y.Z with the latest version from crates.io
serde = { version = "1.0", features = ["derive"] }
# tempfile = "3.8" # Often useful for examples and tests
# env_logger = "0.11" # For enabling logging in examples/tests
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).
Usage Guide & Examples:
examples/ directory within the repository.main.rs file (e.g., cargo run --example basic_usage).Full API Reference:
API_REFERENCE.md in the repository.RocksDbStoreRocksDbCFStoreRocksDbTxnStoreRocksDbCFTxnStoreRocksDbCFStoreConfig (or its simpler counterparts RocksDbStoreConfig, RocksDbCFTxnStoreConfig, RocksDbTxnStoreConfig) to define paths, CFs to open, and CF-specific settings like tuning profiles, merge operators, comparators, and compaction filters using BaseCfConfig or CFTxConfig.batch_writer() on your store instance. This returns a BatchWriter scoped to a specific Column Family.RocksDbTxnStore::transaction_context(): Returns a TransactionContext for fluent operations on the default CF.RocksDbCFTxnStore::execute_transaction(|txn| { ... }): For multi-CF transactional logic.MergeRouterBuilder: For custom conflict resolution or data aggregation based on key patterns within a CF.CompactionFilterRouterBuilder: For background data cleanup/transformation (like TTL) based on key patterns within a CF.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 (or the MPL-2.0 text if a separate file is not present) for details.