Trait massa_db_exports::MassaDBController
source · pub trait MassaDBController: Send + Sync + Debug {
Show 17 methods
// Required methods
fn backup_db(&self, slot: Slot) -> PathBuf;
fn get_change_id(&self) -> Result<Slot, ModelsError>;
fn set_initial_change_id(&self, change_id: Slot);
fn write_batch(
&mut self,
batch: DBBatch,
versioning_batch: DBBatch,
change_id: Option<Slot>,
);
fn put_or_update_entry_value(
&self,
batch: &mut DBBatch,
key: Vec<u8>,
value: &[u8],
);
fn delete_key(&self, batch: &mut DBBatch, key: Vec<u8>);
fn delete_prefix(
&mut self,
prefix: &str,
handle_str: &str,
change_id: Option<Slot>,
);
fn reset(&mut self, slot: Slot);
fn get_cf(
&self,
handle_cf: &str,
key: Key,
) -> Result<Option<Value>, MassaDBError>;
fn multi_get_cf(
&self,
query: Vec<(&str, Key)>,
) -> Vec<Result<Option<Value>, MassaDBError>>;
fn iterator_cf(
&self,
handle_cf: &str,
mode: MassaIteratorMode<'_>,
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
fn prefix_iterator_cf(
&self,
handle_cf: &str,
prefix: &[u8],
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
fn get_xof_db_hash(&self) -> HashXof<HASH_XOF_SIZE_BYTES>;
fn flush(&self) -> Result<(), MassaDBError>;
fn write_batch_bootstrap_client(
&mut self,
stream_changes: StreamBatch<Slot>,
stream_changes_versioning: StreamBatch<Slot>,
) -> Result<(StreamingStep<Key>, StreamingStep<Key>), MassaDBError>;
fn get_batch_to_stream(
&self,
last_state_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>;
fn get_versioning_batch_to_stream(
&self,
last_versioning_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>;
}
Expand description
Controller trait for the MassaDB TODO: MOCK IT WITH MOCKALL. HAVING LIFETIMES ERRORS WITH AUTO MOCK
Required Methods§
sourcefn backup_db(&self, slot: Slot) -> PathBuf
fn backup_db(&self, slot: Slot) -> PathBuf
Creates a new hard copy of the DB, for the given slot
sourcefn get_change_id(&self) -> Result<Slot, ModelsError>
fn get_change_id(&self) -> Result<Slot, ModelsError>
Get the current change_id attached to the database.
sourcefn set_initial_change_id(&self, change_id: Slot)
fn set_initial_change_id(&self, change_id: Slot)
Set the initial change_id. This function should only be called at startup/reset, as it does not batch this set with other changes.
sourcefn write_batch(
&mut self,
batch: DBBatch,
versioning_batch: DBBatch,
change_id: Option<Slot>,
)
fn write_batch( &mut self, batch: DBBatch, versioning_batch: DBBatch, change_id: Option<Slot>, )
Writes the batch to the DB
sourcefn put_or_update_entry_value(
&self,
batch: &mut DBBatch,
key: Vec<u8>,
value: &[u8],
)
fn put_or_update_entry_value( &self, batch: &mut DBBatch, key: Vec<u8>, value: &[u8], )
Utility function to put / update a key & value in the batch
sourcefn delete_key(&self, batch: &mut DBBatch, key: Vec<u8>)
fn delete_key(&self, batch: &mut DBBatch, key: Vec<u8>)
Utility function to delete a key & value in the batch
sourcefn delete_prefix(
&mut self,
prefix: &str,
handle_str: &str,
change_id: Option<Slot>,
)
fn delete_prefix( &mut self, prefix: &str, handle_str: &str, change_id: Option<Slot>, )
Utility function to delete all keys in a prefix
sourcefn get_cf(
&self,
handle_cf: &str,
key: Key,
) -> Result<Option<Value>, MassaDBError>
fn get_cf( &self, handle_cf: &str, key: Key, ) -> Result<Option<Value>, MassaDBError>
Exposes RocksDB’s “get_cf” function
sourcefn multi_get_cf(
&self,
query: Vec<(&str, Key)>,
) -> Vec<Result<Option<Value>, MassaDBError>>
fn multi_get_cf( &self, query: Vec<(&str, Key)>, ) -> Vec<Result<Option<Value>, MassaDBError>>
Exposes RocksDB’s “multi_get_cf” function
sourcefn iterator_cf(
&self,
handle_cf: &str,
mode: MassaIteratorMode<'_>,
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>
fn iterator_cf( &self, handle_cf: &str, mode: MassaIteratorMode<'_>, ) -> Box<dyn Iterator<Item = (Key, Value)> + '_>
Exposes RocksDB’s “iterator_cf” function
sourcefn prefix_iterator_cf(
&self,
handle_cf: &str,
prefix: &[u8],
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>
fn prefix_iterator_cf( &self, handle_cf: &str, prefix: &[u8], ) -> Box<dyn Iterator<Item = (Key, Value)> + '_>
Exposes RocksDB’s “prefix_iterator_cf” function
sourcefn get_xof_db_hash(&self) -> HashXof<HASH_XOF_SIZE_BYTES>
fn get_xof_db_hash(&self) -> HashXof<HASH_XOF_SIZE_BYTES>
Get the current extended state hash of the database
sourcefn flush(&self) -> Result<(), MassaDBError>
fn flush(&self) -> Result<(), MassaDBError>
Flushes the underlying db.
sourcefn write_batch_bootstrap_client(
&mut self,
stream_changes: StreamBatch<Slot>,
stream_changes_versioning: StreamBatch<Slot>,
) -> Result<(StreamingStep<Key>, StreamingStep<Key>), MassaDBError>
fn write_batch_bootstrap_client( &mut self, stream_changes: StreamBatch<Slot>, stream_changes_versioning: StreamBatch<Slot>, ) -> Result<(StreamingStep<Key>, StreamingStep<Key>), MassaDBError>
Write a stream_batch of database entries received from a bootstrap server
sourcefn get_batch_to_stream(
&self,
last_state_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>
fn get_batch_to_stream( &self, last_state_step: &StreamingStep<Vec<u8>>, last_change_id: Option<Slot>, ) -> Result<StreamBatch<Slot>, MassaDBError>
Used for bootstrap servers (get a new batch of data from STATE_CF to stream to the client)
Returns a StreamBatch
sourcefn get_versioning_batch_to_stream(
&self,
last_versioning_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>
fn get_versioning_batch_to_stream( &self, last_versioning_step: &StreamingStep<Vec<u8>>, last_change_id: Option<Slot>, ) -> Result<StreamBatch<Slot>, MassaDBError>
Used for bootstrap servers (get a new batch of data from VERSIONING_CF to stream to the client)
Returns a StreamBatch