Skip to content

Commit 7de2464

Browse files
ldanilekConvex, Inc.
authored andcommitted
fix retention checkpoint age metric on startup (#24706)
accidentally regressed by #24504 GitOrigin-RevId: 929258e7ff48d42cbbfb2ed46a9951fe4d6cc70b
1 parent c65a490 commit 7de2464

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

crates/database/src/metrics.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ pub fn log_document_retention_cursor_age(age_secs: f64) {
410410
log_gauge(&DOCUMENT_RETENTION_CURSOR_AGE_SECONDS, age_secs)
411411
}
412412

413+
register_convex_gauge!(
414+
RETENTION_MISSING_CURSOR_INFO,
415+
"Index retention has no cursor"
416+
);
417+
pub fn log_retention_no_cursor() {
418+
log_gauge(&RETENTION_MISSING_CURSOR_INFO, 1.0)
419+
}
420+
421+
register_convex_gauge!(
422+
DOCUMENT_RETENTION_MISSING_CURSOR_INFO,
423+
"Document retention has no cursor"
424+
);
425+
pub fn log_document_retention_no_cursor() {
426+
log_gauge(&DOCUMENT_RETENTION_MISSING_CURSOR_INFO, 1.0)
427+
}
428+
413429
register_convex_counter!(
414430
RETENTION_SCANNED_DOCUMENT_TOTAL,
415431
"Count of documents scanned by retention",

crates/database/src/retention.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ use crate::{
116116
latest_min_document_snapshot_timer,
117117
latest_min_snapshot_timer,
118118
log_document_retention_cursor_age,
119+
log_document_retention_no_cursor,
119120
log_document_retention_scanned_document,
120121
log_retention_cursor_age,
121122
log_retention_documents_deleted,
122123
log_retention_expired_index_entry,
123124
log_retention_index_entries_deleted,
125+
log_retention_no_cursor,
124126
log_retention_scanned_document,
125127
log_snapshot_verification_age,
126128
retention_advance_timestamp_timer,
@@ -1249,13 +1251,22 @@ impl<RT: Runtime> LeaderRetentionManager<RT> {
12491251
retention_type: RetentionType,
12501252
) -> anyhow::Result<Timestamp> {
12511253
let checkpoint = Self::get_checkpoint_no_logging(persistence, retention_type).await?;
1252-
match retention_type {
1253-
RetentionType::Document => log_document_retention_cursor_age(
1254-
(*snapshot_reader.lock().latest_ts()).secs_since_f64(checkpoint),
1255-
),
1256-
RetentionType::Index => log_retention_cursor_age(
1257-
(*snapshot_reader.lock().latest_ts()).secs_since_f64(checkpoint),
1258-
),
1254+
if checkpoint > Timestamp::MIN {
1255+
// Only log if the checkpoint has been written once, to avoid logging time since
1256+
// epoch when the instance is first starting up.
1257+
match retention_type {
1258+
RetentionType::Document => log_document_retention_cursor_age(
1259+
(*snapshot_reader.lock().latest_ts()).secs_since_f64(checkpoint),
1260+
),
1261+
RetentionType::Index => log_retention_cursor_age(
1262+
(*snapshot_reader.lock().latest_ts()).secs_since_f64(checkpoint),
1263+
),
1264+
}
1265+
} else {
1266+
match retention_type {
1267+
RetentionType::Document => log_document_retention_no_cursor(),
1268+
RetentionType::Index => log_retention_no_cursor(),
1269+
}
12591270
}
12601271
Ok(checkpoint)
12611272
}

0 commit comments

Comments
 (0)