@@ -212,7 +212,21 @@ class ColumnFamilyTest {
212
212
int CountLiveLogFiles () {
213
213
int ret = 0 ;
214
214
VectorLogPtr wal_files;
215
- ASSERT_OK (db_->GetSortedWalFiles (wal_files));
215
+ Status s;
216
+ // GetSortedWalFiles is a flakey function -- it gets all the wal_dir
217
+ // children files and then later checks for their existance. if some of the
218
+ // log files doesn't exist anymore, it reports an error. it does all of this
219
+ // without DB mutex held, so if a background process deletes the log file
220
+ // while the function is being executed, it returns an error. We retry the
221
+ // function 10 times to avoid the error failing the test
222
+ for (int retries = 0 ; retries < 10 ; ++retries) {
223
+ wal_files.clear ();
224
+ s = db_->GetSortedWalFiles (wal_files);
225
+ if (s.ok ()) {
226
+ break ;
227
+ }
228
+ }
229
+ ASSERT_OK (s);
216
230
for (const auto & wal : wal_files) {
217
231
if (wal->Type () == kAliveLogFile ) {
218
232
++ret;
@@ -449,6 +463,7 @@ TEST(ColumnFamilyTest, FlushTest) {
449
463
TEST (ColumnFamilyTest, LogDeletionTest) {
450
464
column_family_options_.write_buffer_size = 100000 ; // 100KB
451
465
Open ();
466
+ int micros_wait_for_log_deletion = 20000 ;
452
467
CreateColumnFamilies ({" one" , " two" , " three" , " four" });
453
468
// Each bracket is one log file. if number is in (), it means
454
469
// we don't need it anymore (it's been flushed)
@@ -461,52 +476,63 @@ TEST(ColumnFamilyTest, LogDeletionTest) {
461
476
PutRandomData (1 , 1000 , 100 );
462
477
WaitForFlush (1 );
463
478
// [0, (1)] [1]
479
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
464
480
ASSERT_EQ (CountLiveLogFiles (), 2 );
465
481
PutRandomData (0 , 1 , 100 );
466
482
// [0, (1)] [0, 1]
483
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
467
484
ASSERT_EQ (CountLiveLogFiles (), 2 );
468
485
PutRandomData (2 , 1 , 100 );
469
486
// [0, (1)] [0, 1, 2]
470
487
PutRandomData (2 , 1000 , 100 );
471
488
WaitForFlush (2 );
472
489
// [0, (1)] [0, 1, (2)] [2]
490
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
473
491
ASSERT_EQ (CountLiveLogFiles (), 3 );
474
492
PutRandomData (2 , 1000 , 100 );
475
493
WaitForFlush (2 );
476
494
// [0, (1)] [0, 1, (2)] [(2)] [2]
495
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
477
496
ASSERT_EQ (CountLiveLogFiles (), 4 );
478
497
PutRandomData (3 , 1 , 100 );
479
498
// [0, (1)] [0, 1, (2)] [(2)] [2, 3]
480
499
PutRandomData (1 , 1 , 100 );
481
500
// [0, (1)] [0, 1, (2)] [(2)] [1, 2, 3]
501
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
482
502
ASSERT_EQ (CountLiveLogFiles (), 4 );
483
503
PutRandomData (1 , 1000 , 100 );
484
504
WaitForFlush (1 );
485
505
// [0, (1)] [0, (1), (2)] [(2)] [(1), 2, 3] [1]
506
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
486
507
ASSERT_EQ (CountLiveLogFiles (), 5 );
487
508
PutRandomData (0 , 1000 , 100 );
488
509
WaitForFlush (0 );
489
510
// [(0), (1)] [(0), (1), (2)] [(2)] [(1), 2, 3] [1, (0)] [0]
490
511
// delete obsolete logs -->
491
512
// [(1), 2, 3] [1, (0)] [0]
513
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
492
514
ASSERT_EQ (CountLiveLogFiles (), 3 );
493
515
PutRandomData (0 , 1000 , 100 );
494
516
WaitForFlush (0 );
495
517
// [(1), 2, 3] [1, (0)], [(0)] [0]
518
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
496
519
ASSERT_EQ (CountLiveLogFiles (), 4 );
497
520
PutRandomData (1 , 1000 , 100 );
498
521
WaitForFlush (1 );
499
522
// [(1), 2, 3] [(1), (0)] [(0)] [0, (1)] [1]
523
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
500
524
ASSERT_EQ (CountLiveLogFiles (), 5 );
501
525
PutRandomData (2 , 1000 , 100 );
502
526
WaitForFlush (2 );
503
527
// [(1), (2), 3] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2]
528
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
504
529
ASSERT_EQ (CountLiveLogFiles (), 6 );
505
530
PutRandomData (3 , 1000 , 100 );
506
531
WaitForFlush (3 );
507
532
// [(1), (2), (3)] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2, (3)] [3]
508
533
// delete obsolete logs -->
509
534
// [0, (1)] [1, (2)], [2, (3)] [3]
535
+ env_->SleepForMicroseconds (micros_wait_for_log_deletion);
510
536
ASSERT_EQ (CountLiveLogFiles (), 4 );
511
537
Close ();
512
538
}
0 commit comments