Expand description
Rust wrapper for RocksDB.
§Examples
use rocksdb::{DB, Options};
// NB: db is automatically closed at end of lifetime
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage");
let path = tempdir.path();
{
let db = DB::open_default(path).unwrap();
db.put(b"my key", b"my value").unwrap();
match db.get(b"my key") {
Ok(Some(value)) => println!("retrieved value {}", String::from_utf8(value).unwrap()),
Ok(None) => println!("value not found"),
Err(e) => println!("operational problem encountered: {}", e),
}
db.delete(b"my key").unwrap();
}
let _ = DB::destroy(&Options::default(), path);
Opening a database and a single column family with custom options:
use rocksdb::{DB, ColumnFamilyDescriptor, Options};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage_with_cfs")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage_with_cfs.");
let path = tempdir.path();
let mut cf_opts = Options::default();
cf_opts.set_max_write_buffer_number(16);
let cf = ColumnFamilyDescriptor::new("cf1", cf_opts);
let mut db_opts = Options::default();
db_opts.create_missing_column_families(true);
db_opts.create_if_missing(true);
{
let db = DB::open_cf_descriptors(&db_opts, path, vec![cf]).unwrap();
}
let _ = DB::destroy(&db_opts, path);
Re-exports§
pub use crate::compaction_filter::Decision as CompactionDecision;
pub use crate::merge_operator::MergeOperands;
pub use crate::perf::PerfContext;
pub use crate::perf::PerfMetric;
pub use crate::perf::PerfStatsLevel;
Modules§
- backup
- checkpoint
- Implementation of bindings to RocksDB Checkpoint1 API
- compaction_
filter - compaction_
filter_ factory - merge_
operator - rustic merge operator
- perf
- properties
- Properties
- statistics
Structs§
- Block
Based Options - For configuring block-based file storage.
- Bound
Column Family - A specialized opaque type used to represent a column family by the
MultiThreaded
mode. Clone (and Copy) is derived to behave like&ColumnFamily
(this is used for single-threaded mode).Clone
/Copy
is safe because this lifetime is bound to DB like iterators/snapshots. On top of it, this is as cheap and small as&ColumnFamily
because this only has a single pointer-wide field. - Cache
- Column
Family - An opaque type used to represent a column family. Returned from some functions, and used in others
- Column
Family Descriptor - A descriptor for a RocksDB column family.
- Compact
Options - Cuckoo
Table Options - Configuration of cuckoo-based storage.
- DBCommon
- A helper type to implement some common methods for
DBWithThreadMode
andOptimisticTransactionDB
. - DBIterator
With Thread Mode - An iterator over a database or column family, with specifiable ranges and direction.
- DBPath
- Represents a path where sst files can be put into
- DBPinnable
Slice - Wrapper around RocksDB PinnableSlice struct.
- DBRaw
Iterator With Thread Mode - An iterator over a database or column family, with specifiable ranges and direction.
- DBWAL
Iterator - Iterates the batches of writes since a given sequence number.
- Env
- An Env is an interface used by the rocksdb implementation to access operating system functionality like the filesystem etc. Callers may wish to provide a custom Env object when opening a database to get fine gain control; e.g., to rate limit file system operations.
- Error
- A simple wrapper round a string, used for errors reported from ffi calls.
- Fifo
Compact Options - Flush
Options - Optionally wait for the memtable flush to be performed.
- Ingest
External File Options - For configuring external files ingestion.
- Live
File - The metadata that describes a SST file
- LruCache
Options - Multi
Threaded - Actual marker type for the marker trait
ThreadMode
, which holds a collection of column families wrapped in a RwLock to be mutated concurrently. The other mode isSingleThreaded
. - Optimistic
Transaction Options - Options
- Database-wide options around performance and behavior.
- Plain
Table Factory Options - Used with DBOptions::set_plain_table_factory. See official wiki for more information.
- Prefix
Range - Representation of a range of keys starting with given prefix.
- Read
Options - Single
Threaded - Actual marker type for the marker trait
ThreadMode
, which holds a collection of column families without synchronization primitive, providing no overhead for the single-threaded column family alternations. The other mode isMultiThreaded
. - Slice
Transform - A
SliceTransform
is a generic pluggable way of transforming one string to another. Its primary use-case is in configuring rocksdb to store prefix blooms by setting prefix_extractor in ColumnFamilyOptions. - Snapshot
With Thread Mode - A consistent view of the database at the point of creation.
- SstFile
Writer - SstFileWriter is used to create sst files that can be added to database later All keys in files generated by SstFileWriter will have sequence number = 0.
- Transaction
- RocksDB Transaction.
- TransactionDB
- RocksDB TransactionDB.
- TransactionDB
Options - Transaction
Options - Universal
Compact Options - Wait
ForCompact Options - Write
Batch With Transaction - An atomic batch of write operations.
- Write
Buffer Manager - Write
Options - Optionally disable WAL or sync for this write.
Enums§
- Block
Based Index Type - Used by BlockBasedOptions::set_index_type.
- Bottommost
Level Compaction - Checksum
Type - Used by BlockBasedOptions::set_checksum_type.
- Column
Family Ttl - Specifies the TTL behavior for a column family. https://github.com/facebook/rocksdb/blob/18cecb9c46b4c2a8b148659dac2fcab5a843d32b/include/rocksdb/utilities/db_ttl.h#L16-L46
- Compaction
Pri - DBCompaction
Style - DBCompression
Type - DBRecovery
Mode - Data
Block Index Type - Used by BlockBasedOptions::set_data_block_index_type.
- Direction
- Error
Kind - RocksDB error kind.
- Iterator
Mode - KeyEncoding
Type - Used in
PlainTableFactoryOptions
. - LogLevel
- Memtable
Factory - Defines the underlying memtable implementation. See official wiki for more information.
- Read
Tier - Universal
Compaction Stop Style
Constants§
- DEFAULT_
COLUMN_ FAMILY_ NAME - The name of the default column family.
Traits§
- AsColumn
Family Ref - Utility trait to accept both supported references to
ColumnFamily
(&ColumnFamily
andBoundColumnFamily
) - CStr
Like - Value which can be converted into a C string.
- DBAccess
- Minimal set of DB-related methods, intended to be generic over
DBWithThreadMode<T>
. Mainly used internally - Iterate
Bounds - A range which can be set as iterate bounds on
crate::ReadOptions
. - Thread
Mode - Marker trait to specify single or multi threaded column family alternations for
DBWithThreadMode<T>
- Write
Batch Iterator - Receives the puts and deletes of a write batch.
Type Aliases§
- Column
Family Ref - Handy type alias to hide actual type difference to reference
ColumnFamily
depending on themulti-threaded-cf
crate feature. - DB
- A type alias to DB instance type with the single-threaded column family creations/deletions
- DBIterator
- A type alias to keep compatibility. See
DBIteratorWithThreadMode
for details - DBRaw
Iterator - A type alias to keep compatibility. See
DBRawIteratorWithThreadMode
for details - DBWith
Thread Mode - A type alias to RocksDB database.
- Optimistic
TransactionDB - A type alias to RocksDB Optimistic Transaction DB.
- Snapshot
- A type alias to keep compatibility. See
SnapshotWithThreadMode
for details - Write
Batch - A type alias to keep compatibility. See
WriteBatchWithTransaction
for details