@@ -249,7 +249,7 @@ impl<RT: Runtime> TextIndexFlusher2<RT> {
249
249
let snapshot = TextIndexSnapshot {
250
250
data : TextIndexSnapshotData :: MultiSegment ( segments) ,
251
251
ts : backfill_ts,
252
- version : TextSnapshotVersion :: V0 ,
252
+ version : TextSnapshotVersion :: V2UseStringIds ,
253
253
} ;
254
254
let is_snapshotted = matches ! ( on_disk_state, SearchOnDiskState :: SnapshottedAt ( _) ) ;
255
255
if is_snapshotted {
@@ -297,11 +297,16 @@ impl<RT: Runtime> TextIndexFlusher2<RT> {
297
297
#[ cfg( test) ]
298
298
mod tests {
299
299
use common:: {
300
- bootstrap_model:: index:: IndexMetadata ,
300
+ bootstrap_model:: index:: {
301
+ text_index:: TextIndexState ,
302
+ IndexConfig ,
303
+ IndexMetadata ,
304
+ } ,
301
305
runtime:: testing:: TestRuntime ,
302
306
types:: TabletIndexName ,
303
307
} ;
304
308
use maplit:: btreemap;
309
+ use must_let:: must_let;
305
310
use value:: TableNamespace ;
306
311
307
312
use crate :: tests:: text_test_utils:: {
@@ -408,6 +413,30 @@ mod tests {
408
413
Ok ( ( ) )
409
414
}
410
415
416
+ #[ convex_macro:: test_runtime]
417
+ async fn backfill_with_two_documents_leaves_document_backfilling_after_first_flush (
418
+ rt : TestRuntime ,
419
+ ) -> anyhow:: Result < ( ) > {
420
+ let fixtures = TextFixtures :: new ( rt) . await ?;
421
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
422
+
423
+ fixtures. add_document ( "cat" ) . await ?;
424
+ fixtures. add_document ( "dog" ) . await ?;
425
+
426
+ let mut flusher = fixtures
427
+ . new_search_flusher_builder ( )
428
+ . set_incremental_multipart_threshold_bytes ( 0 )
429
+ . build ( ) ;
430
+ // Build the first segment, which stops because the document size is > 0
431
+ flusher. step ( ) . await ?;
432
+ let metadata = fixtures. get_index_metadata ( name) . await ?;
433
+ must_let ! ( let IndexConfig :: Search { on_disk_state, .. } = & metadata. config) ;
434
+ must_let ! ( let TextIndexState :: Backfilling ( backfilling_meta) = on_disk_state) ;
435
+ assert_eq ! ( backfilling_meta. segments. len( ) , 1 ) ;
436
+
437
+ Ok ( ( ) )
438
+ }
439
+
411
440
#[ convex_macro:: test_runtime]
412
441
async fn backfill_with_two_documents_0_max_segment_size_includes_both_documents (
413
442
rt : TestRuntime ,
@@ -437,4 +466,140 @@ mod tests {
437
466
438
467
Ok ( ( ) )
439
468
}
469
+
470
+ #[ convex_macro:: test_runtime]
471
+ async fn backfill_with_empty_index_adds_no_segments ( rt : TestRuntime ) -> anyhow:: Result < ( ) > {
472
+ let fixtures = TextFixtures :: new ( rt) . await ?;
473
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
474
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
475
+ flusher. step ( ) . await ?;
476
+
477
+ let segments = fixtures. get_segments_metadata ( name) . await ?;
478
+ assert_eq ! ( 0 , segments. len( ) ) ;
479
+
480
+ Ok ( ( ) )
481
+ }
482
+
483
+ #[ convex_macro:: test_runtime]
484
+ async fn backfill_with_empty_backfilled_index_new_document_adds_document (
485
+ rt : TestRuntime ,
486
+ ) -> anyhow:: Result < ( ) > {
487
+ let fixtures = TextFixtures :: new ( rt) . await ?;
488
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
489
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
490
+ flusher. step ( ) . await ?;
491
+
492
+ let doc_id = fixtures. add_document ( "cat" ) . await ?;
493
+
494
+ flusher. step ( ) . await ?;
495
+
496
+ fixtures. enable_index ( & name) . await ?;
497
+ let results = fixtures. search ( name, "cat" ) . await ?;
498
+ assert_eq ! ( doc_id, results. first( ) . unwrap( ) . id( ) ) ;
499
+
500
+ Ok ( ( ) )
501
+ }
502
+
503
+ #[ convex_macro:: test_runtime]
504
+ async fn backfill_with_non_empty_backfilled_index_new_document_adds_document (
505
+ rt : TestRuntime ,
506
+ ) -> anyhow:: Result < ( ) > {
507
+ let fixtures = TextFixtures :: new ( rt) . await ?;
508
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
509
+ fixtures. add_document ( "dog" ) . await ?;
510
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
511
+ flusher. step ( ) . await ?;
512
+
513
+ let doc_id = fixtures. add_document ( "cat" ) . await ?;
514
+
515
+ flusher. step ( ) . await ?;
516
+
517
+ fixtures. enable_index ( & name) . await ?;
518
+ let results = fixtures. search ( name, "cat" ) . await ?;
519
+ assert_eq ! ( doc_id, results. first( ) . unwrap( ) . id( ) ) ;
520
+
521
+ Ok ( ( ) )
522
+ }
523
+
524
+ #[ convex_macro:: test_runtime]
525
+ async fn backfill_with_empty_enabled_index_new_document_adds_document (
526
+ rt : TestRuntime ,
527
+ ) -> anyhow:: Result < ( ) > {
528
+ let fixtures = TextFixtures :: new ( rt) . await ?;
529
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
530
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
531
+ flusher. step ( ) . await ?;
532
+ fixtures. enable_index ( & name) . await ?;
533
+
534
+ let doc_id = fixtures. add_document ( "cat" ) . await ?;
535
+
536
+ flusher. step ( ) . await ?;
537
+
538
+ let results = fixtures. search ( name, "cat" ) . await ?;
539
+ assert_eq ! ( doc_id, results. first( ) . unwrap( ) . id( ) ) ;
540
+
541
+ Ok ( ( ) )
542
+ }
543
+
544
+ #[ convex_macro:: test_runtime]
545
+ async fn backfill_with_non_empty_enabled_index_new_document_adds_document (
546
+ rt : TestRuntime ,
547
+ ) -> anyhow:: Result < ( ) > {
548
+ let fixtures = TextFixtures :: new ( rt) . await ?;
549
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
550
+ fixtures. add_document ( "dog" ) . await ?;
551
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
552
+ flusher. step ( ) . await ?;
553
+ fixtures. enable_index ( & name) . await ?;
554
+
555
+ let doc_id = fixtures. add_document ( "cat" ) . await ?;
556
+
557
+ flusher. step ( ) . await ?;
558
+
559
+ let results = fixtures. search ( name, "cat" ) . await ?;
560
+ assert_eq ! ( doc_id, results. first( ) . unwrap( ) . id( ) ) ;
561
+
562
+ Ok ( ( ) )
563
+ }
564
+
565
+ #[ convex_macro:: test_runtime]
566
+ async fn backfill_with_non_empty_enabled_index_new_document_adds_new_segment (
567
+ rt : TestRuntime ,
568
+ ) -> anyhow:: Result < ( ) > {
569
+ let fixtures = TextFixtures :: new ( rt) . await ?;
570
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
571
+ fixtures. add_document ( "dog" ) . await ?;
572
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
573
+ flusher. step ( ) . await ?;
574
+ fixtures. enable_index ( & name) . await ?;
575
+
576
+ fixtures. add_document ( "cat" ) . await ?;
577
+
578
+ flusher. step ( ) . await ?;
579
+
580
+ let segments = fixtures. get_segments_metadata ( name) . await ?;
581
+ assert_eq ! ( segments. len( ) , 2 ) ;
582
+
583
+ Ok ( ( ) )
584
+ }
585
+ #[ convex_macro:: test_runtime]
586
+ async fn backfill_with_non_empty_backfilled_index_new_document_adds_new_segment (
587
+ rt : TestRuntime ,
588
+ ) -> anyhow:: Result < ( ) > {
589
+ let fixtures = TextFixtures :: new ( rt) . await ?;
590
+ let IndexMetadata { name, .. } = fixtures. insert_backfilling_text_index ( ) . await ?;
591
+ fixtures. add_document ( "dog" ) . await ?;
592
+ let mut flusher = fixtures. new_search_flusher2 ( ) ;
593
+ flusher. step ( ) . await ?;
594
+
595
+ fixtures. add_document ( "cat" ) . await ?;
596
+
597
+ flusher. step ( ) . await ?;
598
+
599
+ fixtures. enable_index ( & name) . await ?;
600
+ let segments = fixtures. get_segments_metadata ( name) . await ?;
601
+ assert_eq ! ( segments. len( ) , 2 ) ;
602
+
603
+ Ok ( ( ) )
604
+ }
440
605
}
0 commit comments