jiacai2050 commented on code in PR #1566:
URL: https://github.com/apache/horaedb/pull/1566#discussion_r1749680761
##########
src/wal/src/local_storage_impl/segment.rs:
##########
@@ -454,6 +515,76 @@ impl SegmentManager {
}
Ok(())
}
+
+ pub fn mark_delete_entries_up_to(
+ &self,
+ location: WalLocation,
+ sequence_num: SequenceNumber,
+ ) -> Result<()> {
+ let current_segment_id =
self.current_segment.lock().unwrap().lock().unwrap().id;
+ let mut segments_to_remove: Vec<u64> = Vec::new();
+ let mut all_segments = self.all_segments.lock().unwrap();
+
+ for (_, segment) in all_segments.iter() {
+ let mut segment = segment.lock().unwrap();
+
+ segment.mark_deleted(location.table_id, sequence_num);
+
+ // Delete this segment if it is empty
+ if segment.is_empty() && segment.id != current_segment_id {
+ let mut cache = self.cache.lock().unwrap();
+
+ // Check if segment is already in cache
+ if let Some(index) = cache.iter().position(|id| *id ==
segment.id) {
+ cache.remove(index);
+ }
+
+ segments_to_remove.push(segment.id);
+ segment.delete()?;
Review Comment:
This is a heavy task, I think we can do this outside all_segment's lock.
--
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]