@@ -244,7 +244,7 @@ impl VidBatcher {
244
244
}
245
245
}
246
246
247
- #[ derive( Copy , Clone , QueryableByName ) ]
247
+ #[ derive( Debug , Copy , Clone , QueryableByName ) ]
248
248
pub ( crate ) struct VidRange {
249
249
#[ diesel( sql_type = BigInt , column_name = "min_vid" ) ]
250
250
pub min : i64 ,
@@ -470,4 +470,103 @@ mod tests {
470
470
assert_eq ! ( 1 , ogive. start( ) ) ;
471
471
assert_eq ! ( 100_000 , ogive. end( ) ) ;
472
472
}
473
+
474
+ #[ test]
475
+ fn vid_batcher_handles_large_vid ( ) {
476
+ // An example with very large `vid` values which come from the new
477
+ // schema of setting the `vid` to `block_num << 32 + sequence_num`.
478
+ // These values are taken from an actual example subgraph and cuased
479
+ // errors because of numerical roundoff issues
480
+ const MIN : i64 = 186155521970012263 ;
481
+ const MAX : i64 = 187989601854423140 ;
482
+ const BOUNDS : & [ i64 ] = & [
483
+ 186155521970012263 ,
484
+ 186155552034783334 ,
485
+ 186166744719556711 ,
486
+ 187571594162339943 ,
487
+ 187571628522078310 ,
488
+ 187576619274076263 ,
489
+ 187576649338847334 ,
490
+ 187580570643988583 ,
491
+ 187590242910339175 ,
492
+ 187590268680142950 ,
493
+ 187963647367053415 ,
494
+ 187970828552372324 ,
495
+ 187986749996138596 ,
496
+ 187989601854423140 ,
497
+ ] ;
498
+
499
+ // The start, end, and batch size we expect when we run through the
500
+ // `vid_batcher` we set up below with `MIN`, `MAX` and `BOUNDS`
501
+ const STEPS : & [ ( i64 , i64 , i64 ) ] = & [
502
+ ( 186155521970012263 , 186155521970012265 , 2 ) ,
503
+ ( 186155521970012266 , 186155521970012269 , 3 ) ,
504
+ ( 186155521970012270 , 186155521970012276 , 6 ) ,
505
+ ( 186155521970012277 , 186155521970012289 , 12 ) ,
506
+ ( 186155521970012290 , 186155521970012312 , 22 ) ,
507
+ ( 186155521970012313 , 186155521970012353 , 40 ) ,
508
+ ( 186155521970012354 , 186155521970012426 , 72 ) ,
509
+ ( 186155521970012427 , 186155521970012557 , 130 ) ,
510
+ ( 186155521970012558 , 186155521970012792 , 234 ) ,
511
+ ( 186155521970012793 , 186155521970013215 , 422 ) ,
512
+ ( 186155521970013216 , 186155521970013976 , 760 ) ,
513
+ ( 186155521970013977 , 186155521970015346 , 1369 ) ,
514
+ ( 186155521970015347 , 186155521970017812 , 2465 ) ,
515
+ ( 186155521970017813 , 186155521970022250 , 4437 ) ,
516
+ ( 186155521970022251 , 186155521970030238 , 7987 ) ,
517
+ ( 186155521970030239 , 186155521970044616 , 14377 ) ,
518
+ ( 186155521970044617 , 186155521970070495 , 25878 ) ,
519
+ ( 186155521970070496 , 186155521970117077 , 46581 ) ,
520
+ ( 186155521970117078 , 186155521970200925 , 83847 ) ,
521
+ ( 186155521970200926 , 186155521970351851 , 150925 ) ,
522
+ ( 186155521970351852 , 186155521970623517 , 271665 ) ,
523
+ ( 186155521970623518 , 186155521971112515 , 488997 ) ,
524
+ ( 186155521971112516 , 186155521971992710 , 880194 ) ,
525
+ ( 186155521971992711 , 186155521973577061 , 1584350 ) ,
526
+ ( 186155521973577062 , 186155521976428893 , 2851831 ) ,
527
+ ( 186155521976428894 , 186155521981562190 , 5133296 ) ,
528
+ ( 186155521981562191 , 186155521990802124 , 9239933 ) ,
529
+ ( 186155521990802125 , 186155522007434004 , 16631879 ) ,
530
+ ( 186155522007434005 , 186155522037371388 , 29937383 ) ,
531
+ ( 186155522037371389 , 186155522091258678 , 53887289 ) ,
532
+ ( 186155522091258679 , 186155522188255800 , 96997121 ) ,
533
+ ( 186155522188255801 , 186155522362850619 , 174594818 ) ,
534
+ ( 186155522362850620 , 186155522677121292 , 314270672 ) ,
535
+ ( 186155522677121293 , 186155523242808503 , 565687210 ) ,
536
+ ( 186155523242808504 , 186155524261045483 , 1018236979 ) ,
537
+ ( 186155524261045484 , 186155526093872046 , 1832826562 ) ,
538
+ ( 186155526093872047 , 186155529392959859 , 3299087812 ) ,
539
+ ( 186155529392959860 , 186155535331317922 , 5938358062 ) ,
540
+ ( 186155535331317923 , 186155546020362436 , 10689044513 ) ,
541
+ ( 186155546020362437 , 186160475833232786 , 4929812870349 ) ,
542
+ ( 186160475833232787 , 186998193536485260 , 837717703252473 ) ,
543
+ ( 186998193536485261 , 187574948946679478 , 576755410194217 ) ,
544
+ ( 187574948946679479 , 187590253155585376 , 15304208905897 ) ,
545
+ ( 187590253155585377 , 187989601854423140 , 399348698837763 ) ,
546
+ ] ;
547
+
548
+ let vid_range = VidRange :: new ( MIN , MAX ) ;
549
+ let batch_size = AdaptiveBatchSize {
550
+ size : 10000 ,
551
+ target : Duration :: from_secs ( 180 ) ,
552
+ } ;
553
+
554
+ let mut vid_batcher = VidBatcher :: new ( BOUNDS . to_vec ( ) , vid_range, batch_size) . unwrap ( ) ;
555
+ vid_batcher. step_timer . set ( Duration :: from_secs ( 100 ) ) ;
556
+
557
+ // Run through the entire `vid_batcher`, collecting start and end in
558
+ // `steps`
559
+ let steps = std:: iter:: from_fn ( || {
560
+ vid_batcher
561
+ . step ( |start, end| Ok ( ( start, end, end - start) ) )
562
+ . unwrap ( )
563
+ . 1
564
+ } )
565
+ . fold ( Vec :: new ( ) , |mut steps, ( start, end, step) | {
566
+ steps. push ( ( start, end, step) ) ;
567
+ steps
568
+ } ) ;
569
+
570
+ assert_eq ! ( STEPS , & steps) ;
571
+ }
473
572
}
0 commit comments