Skip to content

Commit 2901722

Browse files
goffrieConvex, Inc.
authored andcommitted
Skip joining against prev_ts in document retention (#42235)
We don't actually need the body of the previous revision in order to garbage collect it. A behaviour change is that if the row's already been deleted, we'll try to delete it again anyway, which is fine. GitOrigin-RevId: 39291c9e848681ece57724798ac96348ea435aa8
1 parent e0b2a25 commit 2901722

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

crates/database/src/retention.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use common::{
6363
},
6464
persistence::{
6565
new_static_repeatable_recent,
66+
DocumentLogEntry,
6667
NoopRetentionValidator,
6768
Persistence,
6869
PersistenceGlobalKey,
@@ -769,8 +770,7 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
769770
"expired_documents: reading expired documents from {cursor:?} to {:?}",
770771
min_document_snapshot_ts,
771772
);
772-
let mut revs = persistence.load_revision_pairs(
773-
None, /* tablet_id */
773+
let mut revs = persistence.load_documents(
774774
TimestampRange::new(*cursor..*min_document_snapshot_ts),
775775
Order::Asc,
776776
*DEFAULT_DOCUMENTS_PAGE_SIZE,
@@ -786,26 +786,17 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
786786
// the document was deleted.
787787
// A NoopRetentionValidator is used here because we are fetching revisions
788788
// outside of the document retention window.
789-
let RevisionPair {
789+
let DocumentLogEntry {
790790
id,
791-
rev:
792-
DocumentRevision {
793-
ts,
794-
document: maybe_doc,
795-
},
796-
prev_rev,
791+
ts,
792+
value: maybe_doc,
793+
prev_ts,
797794
} = rev;
798795
{
799796
// If there is no prev rev, there's nothing to delete.
800797
// If this happens for a tombstone, it means the document was created and
801798
// deleted in the same transaction.
802-
let Some(DocumentRevision {
803-
ts: prev_rev_ts,
804-
// If `prev_rev.document` is None, that means we already
805-
// garbage collected that revision.
806-
document: Some(_),
807-
}) = prev_rev
808-
else {
799+
let Some(prev_rev_ts) = prev_ts else {
809800
log_document_retention_scanned_document(maybe_doc.is_none(), false);
810801
if maybe_doc.is_none() {
811802
anyhow::ensure!(

0 commit comments

Comments
 (0)