forked from eclipse-zenoh/zenoh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-manager): add assertion on Replication Log in Debug
This commit introduces an assertion test every time an Event in inserted in the Replication Log ONLY IN DEBUG. The purpose is to make sure that the invariant of the Replication Log is upheld: it should only contain one Event per key expression. * plugins/zenoh-plugin-storage-manager/src/replication/classification.rs: added the method `assert_only_one_event_per_key_expr` to the `Interval` and `SubInterval` structures. * plugins/zenoh-plugin-storage-manager/src/replication/log.rs: added the method `assert_only_one_event_per_key_expr` to the `LogLatest` structure. Signed-off-by: Julien Loudet <[email protected]>
- Loading branch information
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::collections::{BTreeMap, HashMap}; | ||
use std::collections::{BTreeMap, HashMap, HashSet}; | ||
|
||
use bloomfilter::Bloom; | ||
use serde::{Deserialize, Serialize}; | ||
|
@@ -170,6 +170,24 @@ pub struct LogLatest { | |
} | ||
|
||
impl LogLatest { | ||
/// Returns true if the Replication Log only contains a single Event for each key expression. | ||
/// | ||
/// To perform that check a HashSet is constructed by visiting each Interval and each | ||
/// SubInterval, filling the HashSet with the key expression of all the Events contained. | ||
/// | ||
/// ⚠️ This method will only be called if Zenoh is compiled in Debug mode. | ||
#[cfg(debug_assertions)] | ||
pub(crate) fn assert_only_one_event_per_key_expr(&self) -> bool { | ||
let mut hash_set = HashSet::new(); | ||
for interval in self.intervals.values() { | ||
if !interval.assert_only_one_event_per_key_expr(&mut hash_set) { | ||
return false; | ||
} | ||
} | ||
|
||
true | ||
} | ||
|
||
/// Creates a new [LogLatest] configured with the provided [ReplicaConfig]. | ||
pub fn new( | ||
storage_key_expr: OwnedKeyExpr, | ||
|
@@ -270,6 +288,9 @@ impl LogLatest { | |
.entry(interval_idx) | ||
.or_default() | ||
.insert_unchecked(sub_interval_idx, event); | ||
|
||
#[cfg(debug_assertions)] | ||
assert!(self.assert_only_one_event_per_key_expr()); | ||
} | ||
|
||
/// Removes, if there is one, the previous event from the Replication Log for the provided key | ||
|