jiacai2050 commented on code in PR #1616:
URL: https://github.com/apache/horaedb/pull/1616#discussion_r1895311963


##########
src/metric_engine/src/manifest/encoding.rs:
##########
@@ -303,18 +303,30 @@ impl Snapshot {
 
     // TODO: Ensure no files duplicated
     // https://github.com/apache/horaedb/issues/1608
-    pub fn merge_update(&mut self, update: ManifestUpdate) -> Result<()> {
-        self.records
-            .extend(update.to_adds.into_iter().map(SnapshotRecord::from));
+    pub fn add_records(&mut self, ssts: Vec<SstFile>) {
         self.records
-            .retain(|record| !update.to_deletes.contains(&record.id));
+            .extend(ssts.into_iter().map(SnapshotRecord::from));
+        self.header.length = (self.records.len() * SnapshotRecord::LENGTH) as 
u64;
+    }
 
+    pub fn delete_records(&mut self, to_deletes: Vec<FileId>) {
+        // Since this may hurt performance, we only do this in debug mode.
+        if cfg!(debug_assertions) {
+            for id in &to_deletes {
+                assert!(
+                    self.records.iter().any(|r| r.id == *id),
+                    "File not found in snapshot, id:{id}"
+                );
+            }
+        }
+
+        self.records
+            .retain(|record| !to_deletes.contains(&record.id));
         self.header.length = (self.records.len() * SnapshotRecord::LENGTH) as 
u64;
-        Ok(())
     }
 
     pub fn into_bytes(self) -> Result<Bytes> {
-        let buf = Vec::with_capacity(self.header.length as usize + 
SnapshotHeader::LENGTH);
+        let buf = Vec::with_capacity(self.header.length as usize * 
SnapshotHeader::LENGTH);

Review Comment:
   Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to