massa_db_exports/db_batch.rs
1use std::collections::BTreeMap;
2
3pub type Key = Vec<u8>;
4pub type Value = Vec<u8>;
5
6/// We use batching to reduce the number of writes to the database
7///
8/// Here, a DBBatch is a map from Key to Some(Value) for a new or updated value, or None for a deletion
9pub type DBBatch = BTreeMap<Key, Option<Value>>;
10
11/// A Batch of elements from the database, used by a bootstrap server.
12#[derive(Debug, Clone)]
13pub struct StreamBatch<ChangeID: PartialOrd + Ord + PartialEq + Eq + Clone + std::fmt::Debug> {
14 /// New elements to be streamed to the client.
15 pub new_elements: BTreeMap<Key, Value>,
16 /// The changes made to previously streamed keys. Note that a None value can delete a given key.
17 pub updates_on_previous_elements: BTreeMap<Key, Option<Value>>,
18 /// The ChangeID associated with this batch, useful for syncing the changes not streamed yet to the client.
19 pub change_id: ChangeID,
20}
21
22impl<ChangeID: PartialOrd + Ord + PartialEq + Eq + Clone + std::fmt::Debug> StreamBatch<ChangeID> {
23 /// Helper function used to know if the main bootstrap state step is finished.
24 ///
25 /// Note: even after having an empty StreamBatch, we still need to send the updates on previous elements while bootstrap has not finished.
26 pub fn is_empty(&self) -> bool {
27 self.updates_on_previous_elements.is_empty() && self.new_elements.is_empty()
28 }
29}