MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / load

Method load

nodedb/src/event/watermark.rs:65–97  ·  view source on GitHub ↗

Load the last-processed LSN for a given core. Returns `Lsn::ZERO` if no watermark has been persisted yet (first startup).

(&self, core_id: usize)

Source from the content-addressed store, hash-verified

63 /// Load the last-processed LSN for a given core. Returns `Lsn::ZERO` if
64 /// no watermark has been persisted yet (first startup).
65 pub fn load(&self, core_id: usize) -> crate::Result<Lsn> {
66 let key = core_key(core_id);
67 let txn = self.db.begin_read().map_err(|e| crate::Error::Storage {
68 engine: "event_plane".into(),
69 detail: format!("begin_read: {e}"),
70 })?;
71 let table = txn
72 .open_table(WATERMARKS)
73 .map_err(|e| crate::Error::Storage {
74 engine: "event_plane".into(),
75 detail: format!("open_table: {e}"),
76 })?;
77
78 match table.get(key.as_str()) {
79 Ok(Some(guard)) => {
80 let bytes = guard.value();
81 if bytes.len() == 8 {
82 let arr: [u8; 8] = [
83 bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
84 bytes[7],
85 ];
86 Ok(Lsn::new(u64::from_le_bytes(arr)))
87 } else {
88 Ok(Lsn::ZERO)
89 }
90 }
91 Ok(None) => Ok(Lsn::ZERO),
92 Err(e) => Err(crate::Error::Storage {
93 engine: "event_plane".into(),
94 detail: format!("get watermark core {core_id}: {e}"),
95 }),
96 }
97 }
98
99 /// Persist the last-processed LSN for a given core.
100 pub fn save(&self, core_id: usize, lsn: Lsn) -> crate::Result<()> {

Callers 15

fmtMethod · 0.45
try_reserveMethod · 0.45
availableMethod · 0.45
atomic_saturating_subFunction · 0.45
try_reserveMethod · 0.45
releaseMethod · 0.45
allocatedMethod · 0.45
limitMethod · 0.45
over_release_countMethod · 0.45

Calls 4

core_keyFunction · 0.85
getMethod · 0.45
as_strMethod · 0.45
lenMethod · 0.45