|
14 | 14 |
|
15 | 15 | use std::cmp;
|
16 | 16 | use std::collections::HashSet;
|
17 |
| -use std::ops::Bound::{Excluded, Included}; |
18 | 17 | use std::ops::DerefMut;
|
19 | 18 | use std::sync::atomic::{AtomicBool, Ordering};
|
20 | 19 | use std::time::{Duration, SystemTime};
|
@@ -223,30 +222,8 @@ impl HummockManager {
|
223 | 222 | ) -> Result<Vec<HummockSstableObjectId>> {
|
224 | 223 | // This lock ensures `commit_epoch` and `report_compat_task` can see the latest GC history during sanity check.
|
225 | 224 | let versioning = self.versioning.read().await;
|
226 |
| - let tracked_object_ids: HashSet<HummockSstableObjectId> = { |
227 |
| - let context_info = self.context_info.read().await; |
228 |
| - // object ids in checkpoint version |
229 |
| - let mut tracked_object_ids = versioning.checkpoint.version.get_object_ids(); |
230 |
| - // add object ids added between checkpoint version and current version |
231 |
| - for (_, delta) in versioning.hummock_version_deltas.range(( |
232 |
| - Excluded(versioning.checkpoint.version.id), |
233 |
| - Included(versioning.current_version.id), |
234 |
| - )) { |
235 |
| - tracked_object_ids.extend(delta.newly_added_object_ids()); |
236 |
| - } |
237 |
| - // add stale object ids before the checkpoint version |
238 |
| - let min_pinned_version_id = context_info.min_pinned_version_id(); |
239 |
| - tracked_object_ids.extend( |
240 |
| - versioning |
241 |
| - .checkpoint |
242 |
| - .stale_objects |
243 |
| - .iter() |
244 |
| - .filter(|(version_id, _)| **version_id >= min_pinned_version_id) |
245 |
| - .flat_map(|(_, objects)| objects.id.iter()) |
246 |
| - .cloned(), |
247 |
| - ); |
248 |
| - tracked_object_ids |
249 |
| - }; |
| 225 | + let tracked_object_ids: HashSet<HummockSstableObjectId> = versioning |
| 226 | + .get_tracked_object_ids(self.context_info.read().await.min_pinned_version_id()); |
250 | 227 | let to_delete = object_ids.filter(|object_id| !tracked_object_ids.contains(object_id));
|
251 | 228 | self.write_gc_history(to_delete.clone()).await?;
|
252 | 229 | Ok(to_delete.collect())
|
@@ -561,9 +538,15 @@ impl HummockManager {
|
561 | 538 | };
|
562 | 539 | // Objects pinned by either meta backup or time travel should be filtered out.
|
563 | 540 | let backup_pinned: HashSet<_> = backup_manager.list_pinned_ssts();
|
| 541 | + // The version_pinned is obtained after the candidate object_ids for deletion, which is new enough for filtering purpose. |
| 542 | + let version_pinned = { |
| 543 | + let versioning = self.versioning.read().await; |
| 544 | + versioning |
| 545 | + .get_tracked_object_ids(self.context_info.read().await.min_pinned_version_id()) |
| 546 | + }; |
564 | 547 | let object_ids = object_ids
|
565 | 548 | .into_iter()
|
566 |
| - .filter(|s| !backup_pinned.contains(s)); |
| 549 | + .filter(|s| !version_pinned.contains(s) && !backup_pinned.contains(s)); |
567 | 550 | let object_ids = self.filter_out_objects_by_time_travel(object_ids).await?;
|
568 | 551 | // Retry is not necessary. Full GC will handle these objects eventually.
|
569 | 552 | self.delete_objects(object_ids.into_iter().collect())
|
|
0 commit comments