Skip to main content

Crate rust_rocksdb

Crate rust_rocksdb 

Source
Expand description

Rust wrapper for RocksDB.

§Examples

use rust_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 rust_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::BlobFileAdditionInfo;
pub use crate::compaction::BlobFileGarbageInfo;
pub use crate::compaction::CompactionCancellationToken;
pub use crate::compaction::CompactionFileInfo;
pub use crate::compaction::CompactionJobStats;
pub use crate::compaction::CompactionOptions;
pub use crate::compaction_filter::Decision as CompactionDecision;
pub use crate::compaction_service::CompactionService;
pub use crate::compaction_service::CompactionServiceJobInfo;
pub use crate::compaction_service::CompactionServiceJobStatus;
pub use crate::compaction_service::CompactionServiceOptionsOverride;
pub use crate::compaction_service::EnvPriority;
pub use crate::compaction_service::OpenAndCompactCancellationToken;
pub use crate::compaction_service::OpenAndCompactOptions;
pub use crate::compaction_service::ScheduleResponse;
pub use crate::event_listener::OwnedCompactionJobInfo;
pub use crate::file_checksum::FileChecksumGenFactory;
pub use crate::merge_operator::MergeOperands;
pub use crate::metadata::ColumnFamilyMetaDataOptions;
pub use crate::metadata::FileType;
pub use crate::metadata::LevelMetaData;
pub use crate::metadata::LiveFileStorageInfoEntry;
pub use crate::metadata::LiveFilesStorageInfo;
pub use crate::metadata::LiveFilesStorageInfoOptions;
pub use crate::metadata::SstFileMetaData;
pub use crate::metadata::Temperature;
pub use crate::perf::PerfContext;
pub use crate::perf::PerfMetric;
pub use crate::perf::PerfStatsLevel;
pub use crate::perf::with_thread_local;
pub use crate::sst_file_manager::SstFileManager;
pub use crate::sst_partitioner::SstPartitionerFactory;
pub use crate::table_properties::TableProperties;
pub use crate::trace::BlockCacheTraceOptions;
pub use crate::trace::BlockCacheTraceWriterOptions;
pub use crate::trace::ReplayOptions;
pub use crate::trace::Replayer;
pub use crate::trace::TraceFilter;
pub use crate::trace::TraceOptions;
pub use crate::trace::TraceReader;
pub use crate::wal::OwnedWalFile;
pub use crate::wal::WalFile;
pub use crate::wal::WalFileType;
pub use crate::wal::WalFiles;
pub use crate::wal::WalReadOptions;
pub use crate::wal_filter::WalFilter;
pub use crate::wal_filter::WalRecordAction;
pub use rust_librocksdb_sys as ffi_raw;raw-ptr

Modules§

backup
checkpoint
Implementation of bindings to RocksDB Checkpoint1 API
compaction
Inputs to a manual compaction and read only views of what one did.
compaction_filter
compaction_filter_factory
compaction_service
Running compactions on another process or another machine.
event_listener
file_checksum
Whole file checksums recorded in the manifest.
merge_operator
rustic merge operator
metadata
Per-level and per-file LSM metadata, plus the live files storage info API.
perf
properties
Properties
sst_file_manager
sst_partitioner
Boundaries that compaction must cut SST files on.
statistics
table_properties
Read only properties of a single SST file.
trace
Query tracing and trace replay.
wal
Write ahead log inspection.
wal_filter
Inspecting and rewriting WAL records during recovery.

Structs§

BlockBasedOptions
For configuring block-based file storage.
BoundColumnFamily
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.
CSlice
Owned malloc-allocated memory slice. Do not derive Clone for this because it will cause double-free.
Cache
ColumnFamily
An opaque type used to represent a column family. Returned from some functions, and used in others
ColumnFamilyDescriptor
A descriptor for a RocksDB column family.
ColumnFamilyMetaData
The metadata that describes a column family.
CompactFilesResult
What a DBCommon::compact_files call produced.
CompactOptions
Comparator
A key ordering, owned by Rust and shareable with anything that needs one.
CuckooTableOptions
Configuration of cuckoo-based storage.
DBCommon
A helper type to implement some common methods for DBWithThreadMode and OptimisticTransactionDB.
DBIteratorWithThreadMode
A standard Rust Iterator over a database or column family.
DBPath
Represents a path where sst files can be put into
DBPinnableBatch
Owns all values returned by one native pinned MultiGet operation.
DBPinnableBatchIter
Iterator over a DBPinnableBatch.
DBPinnableSlice
Wrapper around RocksDB PinnableSlice struct.
DBRawIteratorWithThreadMode
A low-level iterator over a database or column family, created by DB::raw_iterator and other raw_iterator_* methods.
DBWALIterator
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.
EnvOptions
Per-file I/O settings handed to an Env when it opens a file.
Error
A simple wrapper round a string, used for errors reported from ffi calls.
ExportImportFilesMetaData
Metadata returned as output from Checkpoint::export_column_family and used as input to DB::create_column_family_with_import.
FifoCompactOptions
FlushOptions
Optionally wait for the memtable flush to be performed.
FlushWalOptions
Options for DB::flush_wal_with_options.
HyperClockCacheOptions
Configuration for a HyperClockCache, RocksDB’s block cache of choice.
ImportColumnFamilyOptions
Options for importing column families. See DB::create_column_family_with_import.
InfoLogger
IngestExternalFileOptions
For configuring external files ingestion.
LiveFile
The metadata that describes a SST file
LruCacheOptions
MemoryAllocator
An allocator RocksDB uses for cache block memory instead of the system one.
MultiThreaded
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 is SingleThreaded.
OccLockBuckets
A pool of mutex locks used to validate optimistic transactions.
OptimisticTransactionDBOptions
Options for opening an OptimisticTransactionDB.
OptimisticTransactionOptions
Options
Database-wide options around performance and behavior.
OwnedPrefixProber
A PrefixProber that keeps the database open instead of borrowing it.
PlainTableFactoryOptions
Used with DBOptions::set_plain_table_factory. See official wiki for more information.
PrefixProber
A reusable prefix probe that avoids per-call iterator creation/destruction.
PrefixRange
Representation of a range of keys starting with given prefix.
Range
A range of keys, start_key is included, but not end_key.
ReadOptions
SingleThreaded
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 is MultiThreaded.
SizeApproximationFlags
Which kinds of data DB::get_approximate_sizes_cf_with_flags counts.
SizeApproximationOptions
Options for the _with_options variants of DB::get_approximate_sizes.
SliceTransform
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.
SnapshotReadOptions
Reusable read state bound to a SnapshotWithThreadMode.
SnapshotWithThreadMode
A consistent view of the database at the point of creation.
SstFileWriter
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.
TimestampedValue
A value read from a DB with user-defined timestamps, and the timestamp it carries.
Transaction
RocksDB Transaction.
TransactionDB
RocksDB TransactionDB.
TransactionDBOptions
TransactionOptions
UniversalCompactOptions
WaitForCompactOptions
WriteBatchWithIndex
A write batch that can also be read from, and that can be layered on top of a database iterator.
WriteBatchWithTransaction
An atomic batch of write operations.
WriteBufferManager
WriteOptions
Optionally disable WAL or sync for this write.

Enums§

BlockBasedIndexType
Used by BlockBasedOptions::set_index_type.
BlockBasedPinningTier
BottommostLevelCompaction
ChecksumType
Used by BlockBasedOptions::set_checksum_type.
ColumnFamilyTtl
Specifies the TTL behavior for a column family. https://github.com/facebook/rocksdb/blob/18cecb9c46b4c2a8b148659dac2fcab5a843d32b/include/rocksdb/utilities/db_ttl.h#L16-L46
DBCompactionPri
DBCompactionStyle
DBCompressionType
DBRecoveryMode
DataBlockIndexType
Used by BlockBasedOptions::set_data_block_index_type.
Direction
ErrorKind
RocksDB error kind.
GetIntoBufferResult
Result of a get_into_buffer operation.
IndexBlockSearchType
Index-block search algorithm selected by BlockBasedOptions::set_index_block_search_type.
IoPriority
Priority at which an IO operation is charged to the rate limiter set with Options::set_ratelimiter.
IteratorMode
KeyEncodingType
Used in PlainTableFactoryOptions.
LogLevel
MemtableFactory
Defines the underlying memtable implementation. See official wiki for more information.
OccValidationPolicy
How an OptimisticTransactionDB checks a transaction for write conflicts at commit.
PrepopulateBlobCache
Whether blobs written by a flush are inserted into the blob cache right away.
RateLimiterMode
ReadTier
TxnDBWritePolicy
When a TransactionDB writes transaction data into the DB.
UniversalCompactionStopStyle

Constants§

DEFAULT_COLUMN_FAMILY_NAME
The name of the default column family.

Traits§

AsColumnFamilyRef
Utility trait to accept both supported references to ColumnFamily (&ColumnFamily and BoundColumnFamily)
AsRawPtrraw-ptr
Trait for accessing raw pointers to underlying RocksDB objects.
CStrLike
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
IterateBounds
A range which can be set as iterate bounds on crate::ReadOptions.
ThreadMode
Marker trait to specify single or multi threaded column family alternations for DBWithThreadMode<T>
WriteBatchIterator
Receives the puts and deletes of a write batch.
WriteBatchIteratorCf
Receives the puts, deletes, and merges of a write batch with column family information.

Functions§

built_with_coroutines
Returns true if this crate was built with the coroutines feature, in which case librocksdb was compiled with USE_COROUTINES and linked against folly.

Type Aliases§

ColumnFamilyRefmulti-threaded-cf
DBmulti-threaded-cf
DBIterator
A type alias to keep compatibility. See DBIteratorWithThreadMode for details
DBRawIterator
A type alias to keep compatibility. See DBRawIteratorWithThreadMode for details
DBWithThreadMode
A type alias to RocksDB database.
OptimisticTransactionDBmulti-threaded-cf
Snapshot
A type alias to keep compatibility. See SnapshotWithThreadMode for details
WriteBatch
A type alias to keep compatibility. See WriteBatchWithTransaction for details