|
13 | 13 | //
|
14 | 14 |
|
15 | 15 | use std::{
|
16 |
| - collections::HashMap, |
| 16 | + collections::{HashMap, HashSet}, |
17 | 17 | ops::{Deref, Sub},
|
18 | 18 | };
|
19 | 19 |
|
@@ -91,6 +91,26 @@ impl<const N: usize> From<[(SubIntervalIdx, SubInterval); N]> for Interval {
|
91 | 91 | }
|
92 | 92 |
|
93 | 93 | impl Interval {
|
| 94 | + /// Returns true if the Replication Log only contains a single Event for each key expression. |
| 95 | + /// |
| 96 | + /// To perform that check a HashSet is constructed by visiting each Interval and each |
| 97 | + /// SubInterval, filling the HashSet with the key expression of all the Events contained. |
| 98 | + /// |
| 99 | + /// ⚠️ This method will only be called if Zenoh is compiled in Debug mode. |
| 100 | + #[cfg(debug_assertions)] |
| 101 | + pub(crate) fn assert_only_one_event_per_key_expr( |
| 102 | + &self, |
| 103 | + events: &mut HashSet<Option<OwnedKeyExpr>>, |
| 104 | + ) -> bool { |
| 105 | + for sub_interval in self.sub_intervals.values() { |
| 106 | + if !sub_interval.assert_only_one_event_per_key_expr(events) { |
| 107 | + return false; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + true |
| 112 | + } |
| 113 | + |
94 | 114 | /// Returns the [Fingerprint] of this [Interval].
|
95 | 115 | ///
|
96 | 116 | /// The [Fingerprint] of an [Interval] is equal to the XOR (exclusive or) of the fingerprints
|
@@ -229,6 +249,30 @@ impl<const N: usize> From<[Event; N]> for SubInterval {
|
229 | 249 | }
|
230 | 250 |
|
231 | 251 | impl SubInterval {
|
| 252 | + /// Returns true if the Replication Log only contains a single Event for each key expression. |
| 253 | + /// |
| 254 | + /// To perform that check a HashSet is constructed by visiting each Interval and each |
| 255 | + /// SubInterval, filling the HashSet with the key expression of all the Events contained. |
| 256 | + /// |
| 257 | + /// ⚠️ This method will only be called if Zenoh is compiled in Debug mode. |
| 258 | + #[cfg(debug_assertions)] |
| 259 | + fn assert_only_one_event_per_key_expr( |
| 260 | + &self, |
| 261 | + events: &mut HashSet<Option<OwnedKeyExpr>>, |
| 262 | + ) -> bool { |
| 263 | + for event_ke in self.events.keys() { |
| 264 | + if !events.insert(event_ke.clone()) { |
| 265 | + tracing::error!( |
| 266 | + "FATAL ERROR, REPLICATION LOG INVARIANT VIOLATED, KEY APPEARS MULTIPLE TIMES: \ |
| 267 | + < {event_ke:?} >" |
| 268 | + ); |
| 269 | + return false; |
| 270 | + } |
| 271 | + } |
| 272 | + |
| 273 | + true |
| 274 | + } |
| 275 | + |
232 | 276 | /// Inserts the [Event], regardless of its [Timestamp].
|
233 | 277 | ///
|
234 | 278 | /// This method also updates the fingerprint of the [SubInterval].
|
|
0 commit comments