Skip to content

Commit 99cdb0d

Browse files
goffrieConvex, Inc.
authored andcommitted
Do not panic if backfilling forwards through deleted tables (#42317)
GitOrigin-RevId: f2f840bd69101fb77d8df05aa64f935fe4af78fa
1 parent ae5ef28 commit 99cdb0d

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

crates/database/src/database_index_workers/index_writer.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
BTreeSet,
55
},
66
fmt::Display,
7+
num::NonZeroU32,
78
sync::Arc,
89
time::Duration,
910
};
@@ -521,22 +522,23 @@ impl<RT: Runtime> IndexWriter<RT> {
521522
})
522523
})
523524
.collect();
524-
let size = index_updates.len();
525-
while let Err(not_until) = rate_limiter
526-
.check_n(
527-
(size as u32)
528-
.try_into()
529-
.expect("Chunk size must be nonzero"),
530-
)
531-
.expect("RateLimiter capacity impossibly small")
532-
{
533-
let delay = not_until.wait_time_from(self.runtime.monotonic_now().into());
534-
self.runtime.wait(delay).await;
525+
let size = u32::try_from(index_updates.len())?;
526+
// N.B: it's possible to end up with no entries if we're
527+
// backfilling forward through historical documents that have no
528+
// present indexes in `index_registry`.
529+
if let Some(size) = NonZeroU32::new(size) {
530+
while let Err(not_until) = rate_limiter
531+
.check_n(size)
532+
.expect("RateLimiter capacity impossibly small")
533+
{
534+
let delay = not_until.wait_time_from(self.runtime.monotonic_now().into());
535+
self.runtime.wait(delay).await;
536+
}
537+
persistence
538+
.write(&[], &index_updates, ConflictStrategy::Overwrite)
539+
.await?;
535540
}
536-
persistence
537-
.write(&[], &index_updates, ConflictStrategy::Overwrite)
538-
.await?;
539-
anyhow::Ok((size, cursor))
541+
anyhow::Ok((u64::from(size), cursor))
540542
})
541543
.buffered(*INDEX_BACKFILL_WORKERS);
542544
pin_mut!(updates);
@@ -554,7 +556,7 @@ impl<RT: Runtime> IndexWriter<RT> {
554556
tablet_id: cursor.table(),
555557
index_ids: index_selector.index_ids().collect(),
556558
cursor,
557-
num_docs_indexed: num_docs_indexed as u64,
559+
num_docs_indexed,
558560
})
559561
.await?;
560562
num_docs_indexed = 0;

0 commit comments

Comments
 (0)