RocksDBStore

Struct RocksDBStore 

Source
pub struct RocksDBStore<'a, DB>(/* private fields */);
Expand description

Type wrapper around RocksDB Transaction struct. Used to extend it with DocOps methods used for convenience when working with Yrs documents.

Implementations§

Source§

impl<'a, DB> RocksDBStore<'a, DB>

Source

pub fn commit(self) -> Result<(), Error>

Methods from Deref<Target = Transaction<'a, DB>>§

Source

pub fn set_name(&self, name: &[u8]) -> Result<(), Error>

Source

pub fn get_name(&self) -> Option<Vec<u8>>

Source

pub fn prepare(&self) -> Result<(), Error>

Source

pub fn snapshot(&self) -> SnapshotWithThreadMode<'_, Transaction<'db, DB>>

Returns snapshot associated with transaction if snapshot was enabled in TransactionOptions. Otherwise, returns a snapshot with nullptr inside which doesn’t effect read operations.

Source

pub fn rollback(&self) -> Result<(), Error>

Discard all batched writes in this transaction.

Source

pub fn set_savepoint(&self)

Record the state of the transaction for future calls to rollback_to_savepoint. May be called multiple times to set multiple save points.

Source

pub fn rollback_to_savepoint(&self) -> Result<(), Error>

Undo all operations in this transaction since the most recent call to set_savepoint and removes the most recent set_savepoint.

Returns error if there is no previous call to set_savepoint.

Source

pub fn get<K>(&self, key: K) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the bytes associated with a key value.

See get_cf_opt for details.

Source

pub fn get_pinned<K>( &self, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the bytes associated with a key value and the given column family.

See get_cf_opt for details.

Source

pub fn get_pinned_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_for_update<K>( &self, key: K, exclusive: bool, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

Source

pub fn get_pinned_for_update<K>( &self, key: K, exclusive: bool, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_for_update_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, exclusive: bool, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the key in the given column family and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

Source

pub fn get_pinned_for_update_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, exclusive: bool, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_opt<K>( &self, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Returns the bytes associated with a key value with read options.

See get_cf_opt for details.

Source

pub fn get_pinned_opt<K>( &self, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the bytes associated with a key value and the given column family with read options.

This function will also read pending changes in this transaction. Currently, this function will return an error of the MergeInProgress kind if the most recent write to the queried key in this batch is a Merge.

Source

pub fn get_pinned_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_for_update_opt<K>( &self, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the key with read options and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

See get_for_update_cf_opt for details.

Source

pub fn get_pinned_for_update_opt<K>( &self, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn get_for_update_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Get the key in the given column family with read options and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).

Currently, this function will return an error of the MergeInProgress if the most recent write to the queried key in this batch is a Merge.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors if this key could not be read.

If this transaction was created by an [OptimisticTransactionDB], get_for_update_opt can cause commit to fail. Otherwise, it could return any error that could be returned by [DB::get].

Source

pub fn get_pinned_for_update_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, exclusive: bool, opts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
where K: AsRef<[u8]>,

Source

pub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Return the values associated with the given keys.

Source

pub fn multi_get_opt<K, I>( &self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
where K: AsRef<[u8]>, I: IntoIterator<Item = K>,

Return the values associated with the given keys using read options.

Source

pub fn multi_get_cf<'a, 'b, K, I, W>( &'a self, keys: I, ) -> Vec<Result<Option<Vec<u8>>, Error>>
where 'b: 'a, K: AsRef<[u8]>, I: IntoIterator<Item = (&'b W, K)>, W: 'b + AsColumnFamilyRef,

Return the values associated with the given keys and column families.

Source

pub fn multi_get_cf_opt<'a, 'b, K, I, W>( &'a self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
where 'b: 'a, K: AsRef<[u8]>, I: IntoIterator<Item = (&'b W, K)>, W: 'b + AsColumnFamilyRef,

Return the values associated with the given keys and column families using read options.

Source

pub fn put<K, V>(&self, key: K, value: V) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Put the key value in default column family and do conflict checking on the key.

See put_cf for details.

Source

pub fn put_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Put the key value in the given column famuly and do conflict checking on the key.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
Source

pub fn merge<K, V>(&self, key: K, value: V) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Merge value with existing value of key, and also do conflict checking on the key.

See merge_cf for details.

Source

pub fn merge_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Merge value with existing value of key in the given column family, and also do conflict checking on the key.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
Source

pub fn delete<K>(&self, key: K) -> Result<(), Error>
where K: AsRef<[u8]>,

Delete the key value if it exists and do conflict checking on the key.

See delete_cf for details.

Source

pub fn delete_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<(), Error>
where K: AsRef<[u8]>,

Delete the key value in the given column family and do conflict checking.

If this transaction was created by a TransactionDB, it can return error of kind:

  • Busy if there is a write conflict.
  • TimedOut if a lock could not be acquired.
  • TryAgain if the memtable history size is not large enough.
  • MergeInProgress if merge operations cannot be resolved.
  • or other errors on unexpected failures.
Source

pub fn iterator<'a, 'b>( &'a self, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Source

pub fn iterator_opt<'a, 'b>( &'a self, mode: IteratorMode<'_>, readopts: ReadOptions, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Source

pub fn iterator_cf_opt<'a, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens an iterator using the provided ReadOptions. This is used when you want to iterate over a specific ColumnFamily with a modified ReadOptions.

Source

pub fn full_iterator<'a, 'b>( &'a self, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens an iterator with set_total_order_seek enabled. This must be used to iterate across prefixes when set_memtable_factory has been called with a Hash-based implementation.

Source

pub fn prefix_iterator<'a, 'b, P>( &'a self, prefix: P, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b, P: AsRef<[u8]>,

Source

pub fn iterator_cf<'a, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Source

pub fn full_iterator_cf<'a, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, mode: IteratorMode<'_>, ) -> DBIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Source

pub fn prefix_iterator_cf<'a, P>( &'a self, cf_handle: &impl AsColumnFamilyRef, prefix: P, ) -> DBIteratorWithThreadMode<'a, Transaction<'db, DB>>
where P: AsRef<[u8]>,

Source

pub fn raw_iterator<'a, 'b>( &'a self, ) -> DBRawIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens a raw iterator over the database, using the default read options

Source

pub fn raw_iterator_cf<'a, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, ) -> DBRawIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens a raw iterator over the given column family, using the default read options

Source

pub fn raw_iterator_opt<'a, 'b>( &'a self, readopts: ReadOptions, ) -> DBRawIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens a raw iterator over the database, using the given read options

Source

pub fn raw_iterator_cf_opt<'a, 'b>( &'a self, cf_handle: &impl AsColumnFamilyRef, readopts: ReadOptions, ) -> DBRawIteratorWithThreadMode<'b, Transaction<'db, DB>>
where 'a: 'b,

Opens a raw iterator over the given column family, using the given read options

Source

pub fn get_writebatch(&self) -> WriteBatchWithTransaction<true>

Source

pub fn rebuild_from_writebatch( &self, writebatch: &WriteBatchWithTransaction<true>, ) -> Result<(), Error>

Trait Implementations§

Source§

impl<'a, DB> Deref for RocksDBStore<'a, DB>

Source§

type Target = Transaction<'a, DB>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, DB> DocOps<'a> for RocksDBStore<'a, DB>

Source§

fn insert_doc<K, T>(&self, name: &K, txn: &T) -> Result<(), Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized, T: ReadTxn,

Inserts or updates a document given it’s read transaction and name. lib0 v1 encoding is used for storing the document. Read more
Source§

fn insert_doc_raw_v1( &self, name: &[u8], doc_state_v1: &[u8], doc_sv_v1: &[u8], ) -> Result<(), Box<dyn Error>>

Inserts or updates a document given it’s binary update and state vector. lib0 v1 encoding is assumed as a format for storing the document. Read more
Source§

fn load_doc<K>( &self, name: &K, txn: &mut TransactionMut<'_>, ) -> Result<bool, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Loads the document state stored in current database under given document name into in-memory Yrs document using provided TransactionMut. This includes potential update entries that may not have been merged with the main document state yet. Read more
Source§

fn flush_doc<K>(&self, name: &K) -> Result<Option<Doc>, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Merges all updates stored via Self::push_update that were detached from the main document state, updates the document and its state vector and finally prunes the updates that have been integrated this way. Returns the Doc with the most recent state produced this way. Read more
Source§

fn flush_doc_with<K>( &self, name: &K, options: Options, ) -> Result<Option<Doc>, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Merges all updates stored via Self::push_update that were detached from the main document state, updates the document and its state vector and finally prunes the updates that have been integrated this way. options are used to drive the details of integration process. Returns the Doc with the most recent state produced this way, initialized using options parameter. Read more
Source§

fn get_state_vector<K>( &self, name: &K, ) -> Result<(Option<StateVector>, bool), Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Returns the StateVector stored directly for the document with a given name. Returns None if the state vector was not stored. Read more
Source§

fn push_update<K>(&self, name: &K, update: &[u8]) -> Result<u32, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Appends new update without integrating it directly into document store (which is faster than persisting full document state on every update). Updates are assumed to be serialized using lib0 v1 encoding. Read more
Source§

fn get_diff<K>( &self, name: &K, sv: &StateVector, ) -> Result<Option<Vec<u8>>, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Returns an update (encoded using lib0 v1 encoding) which contains all new changes that happened since provided state vector for a given document. Read more
Source§

fn clear_doc<K>(&self, name: &K) -> Result<(), Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Removes all data associated with the current document (including its updates and metadata). Read more
Source§

fn get_meta<K1, K2>( &self, name: &K1, meta_key: &K2, ) -> Result<Option<Self::Return>, Box<dyn Error>>
where K1: AsRef<[u8]> + ?Sized, K2: AsRef<[u8]> + ?Sized,

Returns a metadata value stored under its metadata key for a document with given name. Read more
Source§

fn insert_meta<K1, K2>( &self, name: &K1, meta_key: &K2, meta: &[u8], ) -> Result<(), Box<dyn Error>>
where K1: AsRef<[u8]> + ?Sized, K2: AsRef<[u8]> + ?Sized,

Inserts or updates new meta value stored under its metadata key for a document with given name. Read more
Source§

fn remove_meta<K1, K2>( &self, name: &K1, meta_key: &K2, ) -> Result<(), Box<dyn Error>>
where K1: AsRef<[u8]> + ?Sized, K2: AsRef<[u8]> + ?Sized,

Removes an metadata entry stored under given metadata key for a document with provided name. Read more
Source§

fn iter_docs( &self, ) -> Result<DocsNameIter<Self::Cursor, Self::Entry>, Box<dyn Error>>

Returns an iterator over all document names stored in current database.
Source§

fn iter_meta<K>( &self, doc_name: &K, ) -> Result<MetadataIter<Self::Cursor, Self::Entry>, Box<dyn Error>>
where K: AsRef<[u8]> + ?Sized,

Returns an iterator over all metadata entries stored for a given document.
Source§

impl<'a, DB> From<Transaction<'a, DB>> for RocksDBStore<'a, DB>

Source§

fn from(txn: Transaction<'a, DB>) -> Self

Converts to this type from the input type.
Source§

impl<'a, DB> Into<Transaction<'a, DB>> for RocksDBStore<'a, DB>

Source§

fn into(self) -> Transaction<'a, DB>

Converts this type into the (usually inferred) input type.
Source§

impl<'a, DB> KVStore<'a> for RocksDBStore<'a, DB>

Source§

type Error = Error

Error type returned from the implementation.
Source§

type Cursor = RocksDBIter<'a, DB>

Cursor type used to iterate over the ordered range of key-value entries.
Source§

type Entry = RocksDBEntry

Entry type returned by cursor.
Source§

type Return = DBPinnableSlice<'a>

Type returned from the implementation. Different key-value stores have different abstractions over the binary data they use.
Source§

fn get(&self, key: &[u8]) -> Result<Option<Self::Return>, Self::Error>

Return a value stored under given key or None if key was not found.
Source§

fn upsert(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>

Insert a new value under given key or replace an existing value with new one if entry with that key already existed.
Source§

fn remove(&self, key: &[u8]) -> Result<(), Self::Error>

Return a value stored under the given key if it exists.
Source§

fn remove_range(&self, from: &[u8], to: &[u8]) -> Result<(), Self::Error>

Remove all keys between from..=to range of keys.
Source§

fn iter_range( &self, from: &[u8], to: &[u8], ) -> Result<Self::Cursor, Self::Error>

Return an iterator over all entries between from..=to range of keys.
Source§

fn peek_back(&self, key: &[u8]) -> Result<Option<Self::Entry>, Self::Error>

Looks into the last entry value prior to a given key. The provided key parameter may not exist and it’s used only to establish cursor position in ordered key collection. Read more

Auto Trait Implementations§

§

impl<'a, DB> Freeze for RocksDBStore<'a, DB>

§

impl<'a, DB> RefUnwindSafe for RocksDBStore<'a, DB>
where DB: RefUnwindSafe,

§

impl<'a, DB> Send for RocksDBStore<'a, DB>

§

impl<'a, DB> !Sync for RocksDBStore<'a, DB>

§

impl<'a, DB> Unpin for RocksDBStore<'a, DB>

§

impl<'a, DB> UnwindSafe for RocksDBStore<'a, DB>
where DB: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.