@@ -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