massa_db_exports/
controller.rs1use crate::{DBBatch, Key, MassaDBError, StreamBatch, Value};
2use massa_hash::{HashXof, HASH_XOF_SIZE_BYTES};
3use massa_models::{error::ModelsError, slot::Slot, streaming_step::StreamingStep};
4use parking_lot::RwLock;
5use std::path::PathBuf;
6use std::{fmt::Debug, sync::Arc};
7
8#[cfg(feature = "test-exports")]
9use std::collections::BTreeMap;
10
11pub type ShareableMassaDBController = Arc<RwLock<Box<dyn MassaDBController>>>;
12
13pub trait MassaDBController: Send + Sync + Debug {
16 fn backup_db(&self, slot: Slot) -> PathBuf;
18
19 fn get_change_id(&self) -> Result<Slot, ModelsError>;
21
22 fn set_initial_change_id(&self, change_id: Slot);
24
25 fn write_batch(&mut self, batch: DBBatch, versioning_batch: DBBatch, change_id: Option<Slot>);
27
28 fn put_or_update_entry_value(&self, batch: &mut DBBatch, key: Vec<u8>, value: &[u8]);
30
31 fn delete_key(&self, batch: &mut DBBatch, key: Vec<u8>);
33
34 fn delete_prefix(&mut self, prefix: &str, handle_str: &str, change_id: Option<Slot>);
36
37 fn reset_slot_and_history(&mut self, slot: Slot);
40
41 fn get_cf(&self, handle_cf: &str, key: Key) -> Result<Option<Value>, MassaDBError>;
43
44 fn multi_get_cf(&self, query: Vec<(&str, Key)>) -> Vec<Result<Option<Value>, MassaDBError>>;
46
47 fn iterator_cf_for_full_db_traversal(
49 &self,
50 handle_cf: &str,
51 mode: MassaIteratorMode,
52 ) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
53
54 fn iterator_cf(
56 &self,
57 handle_cf: &str,
58 mode: MassaIteratorMode,
59 ) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
60
61 fn prefix_iterator_cf(
63 &self,
64 handle_cf: &str,
65 prefix: &[u8],
66 ) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
67
68 fn get_xof_db_hash(&self) -> HashXof<HASH_XOF_SIZE_BYTES>;
70
71 fn flush(&self) -> Result<(), MassaDBError>;
73
74 fn write_batch_bootstrap_client(
76 &mut self,
77 stream_changes: StreamBatch<Slot>,
78 stream_changes_versioning: StreamBatch<Slot>,
79 ) -> Result<(StreamingStep<Key>, StreamingStep<Key>), MassaDBError>;
80
81 fn get_batch_to_stream(
85 &self,
86 last_state_step: &StreamingStep<Vec<u8>>,
87 last_change_id: Option<Slot>,
88 ) -> Result<StreamBatch<Slot>, MassaDBError>;
89
90 fn get_versioning_batch_to_stream(
94 &self,
95 last_versioning_step: &StreamingStep<Vec<u8>>,
96 last_change_id: Option<Slot>,
97 ) -> Result<StreamBatch<Slot>, MassaDBError>;
98
99 fn get_change_history_sizes(&self) -> (usize, usize);
101
102 #[cfg(feature = "test-exports")]
104 fn get_entire_database(&self) -> Vec<BTreeMap<Vec<u8>, Vec<u8>>>;
105}
106
107pub enum MassaIteratorMode<'a> {
109 Start,
110 End,
111 From(&'a [u8], MassaDirection),
112}
113
114pub enum MassaDirection {
116 Forward,
117 Reverse,
118}