Skip to content

Commit 3c81546

Browse files
committed
[CF] Make LogDeletionTest less flakey
Summary: Retry GetSortedWalFiles() and also wait 20ms before counting number of log files. WaitForFlush() doesn't necessarily wait for logs to be deleted, since logs are deleted outside of the mutex. Test Plan: column_family_test Reviewers: dhruba, haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D16371
1 parent 6e7cae7 commit 3c81546

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

db/column_family_test.cc

+27-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,21 @@ class ColumnFamilyTest {
212212
int CountLiveLogFiles() {
213213
int ret = 0;
214214
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);
216230
for (const auto& wal : wal_files) {
217231
if (wal->Type() == kAliveLogFile) {
218232
++ret;
@@ -449,6 +463,7 @@ TEST(ColumnFamilyTest, FlushTest) {
449463
TEST(ColumnFamilyTest, LogDeletionTest) {
450464
column_family_options_.write_buffer_size = 100000; // 100KB
451465
Open();
466+
int micros_wait_for_log_deletion = 20000;
452467
CreateColumnFamilies({"one", "two", "three", "four"});
453468
// Each bracket is one log file. if number is in (), it means
454469
// we don't need it anymore (it's been flushed)
@@ -461,52 +476,63 @@ TEST(ColumnFamilyTest, LogDeletionTest) {
461476
PutRandomData(1, 1000, 100);
462477
WaitForFlush(1);
463478
// [0, (1)] [1]
479+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
464480
ASSERT_EQ(CountLiveLogFiles(), 2);
465481
PutRandomData(0, 1, 100);
466482
// [0, (1)] [0, 1]
483+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
467484
ASSERT_EQ(CountLiveLogFiles(), 2);
468485
PutRandomData(2, 1, 100);
469486
// [0, (1)] [0, 1, 2]
470487
PutRandomData(2, 1000, 100);
471488
WaitForFlush(2);
472489
// [0, (1)] [0, 1, (2)] [2]
490+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
473491
ASSERT_EQ(CountLiveLogFiles(), 3);
474492
PutRandomData(2, 1000, 100);
475493
WaitForFlush(2);
476494
// [0, (1)] [0, 1, (2)] [(2)] [2]
495+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
477496
ASSERT_EQ(CountLiveLogFiles(), 4);
478497
PutRandomData(3, 1, 100);
479498
// [0, (1)] [0, 1, (2)] [(2)] [2, 3]
480499
PutRandomData(1, 1, 100);
481500
// [0, (1)] [0, 1, (2)] [(2)] [1, 2, 3]
501+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
482502
ASSERT_EQ(CountLiveLogFiles(), 4);
483503
PutRandomData(1, 1000, 100);
484504
WaitForFlush(1);
485505
// [0, (1)] [0, (1), (2)] [(2)] [(1), 2, 3] [1]
506+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
486507
ASSERT_EQ(CountLiveLogFiles(), 5);
487508
PutRandomData(0, 1000, 100);
488509
WaitForFlush(0);
489510
// [(0), (1)] [(0), (1), (2)] [(2)] [(1), 2, 3] [1, (0)] [0]
490511
// delete obsolete logs -->
491512
// [(1), 2, 3] [1, (0)] [0]
513+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
492514
ASSERT_EQ(CountLiveLogFiles(), 3);
493515
PutRandomData(0, 1000, 100);
494516
WaitForFlush(0);
495517
// [(1), 2, 3] [1, (0)], [(0)] [0]
518+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
496519
ASSERT_EQ(CountLiveLogFiles(), 4);
497520
PutRandomData(1, 1000, 100);
498521
WaitForFlush(1);
499522
// [(1), 2, 3] [(1), (0)] [(0)] [0, (1)] [1]
523+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
500524
ASSERT_EQ(CountLiveLogFiles(), 5);
501525
PutRandomData(2, 1000, 100);
502526
WaitForFlush(2);
503527
// [(1), (2), 3] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2]
528+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
504529
ASSERT_EQ(CountLiveLogFiles(), 6);
505530
PutRandomData(3, 1000, 100);
506531
WaitForFlush(3);
507532
// [(1), (2), (3)] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2, (3)] [3]
508533
// delete obsolete logs -->
509534
// [0, (1)] [1, (2)], [2, (3)] [3]
535+
env_->SleepForMicroseconds(micros_wait_for_log_deletion);
510536
ASSERT_EQ(CountLiveLogFiles(), 4);
511537
Close();
512538
}

0 commit comments

Comments
 (0)