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

Method put

nodedb/src/control/array_sync/snapshot_store.rs:117–151  ·  view source on GitHub ↗

Persist a snapshot.

(&self, snapshot: &TileSnapshot)

Source from the content-addressed store, hash-verified

115
116 /// Persist a snapshot.
117 pub fn put(&self, snapshot: &TileSnapshot) -> crate::Result<()> {
118 let key = snapshot_key(&snapshot.array, snapshot.snapshot_hlc).ok_or_else(|| {
119 crate::Error::Storage {
120 engine: "array_sync".into(),
121 detail: format!("snapshot_store: array name too long: '{}'", snapshot.array),
122 }
123 })?;
124 let encoded = encode_snapshot(snapshot).map_err(|e| crate::Error::Storage {
125 engine: "array_sync".into(),
126 detail: format!("snapshot_store encode: {e}"),
127 })?;
128
129 let txn = self.db.begin_write().map_err(|e| crate::Error::Storage {
130 engine: "array_sync".into(),
131 detail: format!("snapshot_store put begin_write: {e}"),
132 })?;
133 {
134 let mut table = txn
135 .open_table(SNAPSHOT_TABLE)
136 .map_err(|e| crate::Error::Storage {
137 engine: "array_sync".into(),
138 detail: format!("snapshot_store put open_table: {e}"),
139 })?;
140 table
141 .insert(key.as_slice(), encoded.as_slice())
142 .map_err(|e| crate::Error::Storage {
143 engine: "array_sync".into(),
144 detail: format!("snapshot_store put insert: {e}"),
145 })?;
146 }
147 txn.commit().map_err(|e| crate::Error::Storage {
148 engine: "array_sync".into(),
149 detail: format!("snapshot_store put commit: {e}"),
150 })
151 }
152
153 /// Retrieve a snapshot by exact `(array, hlc)`.
154 pub fn get(&self, array: &str, hlc: Hlc) -> Option<TileSnapshot> {

Callers 4

write_snapshotMethod · 0.45
put_and_get_roundtripFunction · 0.45

Calls 6

snapshot_keyFunction · 0.85
encode_snapshotFunction · 0.85
begin_writeMethod · 0.80
insertMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by 3

put_and_get_roundtripFunction · 0.36