Persist a snapshot.
(&self, snapshot: &TileSnapshot)
| 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> { |