Skip to content

Commit 2479ca0

Browse files
committed
use all threads to verify different portions
1 parent 4eb561a commit 2479ca0

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

db_stress_tool/no_batched_ops_stress.cc

+39-18
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,26 @@ class NonBatchedOpsStressTest : public StressTest {
339339
}
340340
assert(cmp_db_);
341341
assert(!cmp_cfhs_.empty());
342+
342343
auto* shared = thread->shared;
343344
assert(shared);
345+
346+
const int64_t max_key = shared->GetMaxKey();
347+
const int64_t keys_per_thread = max_key / shared->GetNumThreads();
348+
int64_t start = keys_per_thread * thread->tid;
349+
int64_t end = thread->tid == shared->GetNumThreads() - 1
350+
? max_key
351+
: start + keys_per_thread;
352+
353+
// We are going to read in the expected values before catching up to the
354+
// primary to determine the lower bound of the acceptable values that can be
355+
// returned from the secondary. After each Get() to the secondary, we are
356+
// going to read in the expected value again to determine the upper bound.
357+
// As long as the returned value from Get() is within these bounds, we
358+
// consider that okay. The lower bound will always be moving forwards
359+
// anyways as TryCatchUpWithPrimary() gets called.
344360
std::vector<ExpectedValue> pre_read_expected_values;
345-
for (int64_t i = 0; i < 1000; ++i) {
361+
for (int64_t i = start; i < end; ++i) {
346362
pre_read_expected_values.push_back(shared->Get(0, i));
347363
}
348364

@@ -354,10 +370,14 @@ class NonBatchedOpsStressTest : public StressTest {
354370

355371
ReadOptions read_opts(FLAGS_verify_checksum, true);
356372

357-
for (int64_t i = 0; i < 1000; ++i) {
358-
const ExpectedValue pre_read_expected_value = pre_read_expected_values[i];
373+
for (int64_t i = start; i < end; ++i) {
374+
if (shared->HasVerificationFailedYet()) {
375+
break;
376+
}
377+
const ExpectedValue pre_read_expected_value =
378+
pre_read_expected_values[i - start];
359379
std::string from_db;
360-
std::string key_str = Key(rand_keys[0]);
380+
std::string key_str = Key(i);
361381
Slice key = key_str;
362382
s = db_->Get(read_opts, column_families_[0], key_str, &from_db);
363383
const ExpectedValue post_read_expected_value = shared->Get(0, i);
@@ -369,7 +389,7 @@ class NonBatchedOpsStressTest : public StressTest {
369389
post_read_expected_value)) {
370390
std::cout << "Secondary verification failed for i=" << i
371391
<< ", key=" << key.ToString(true)
372-
<< ". The value_base from the db was " << value_base_from_db
392+
<< ". Get() returned a value base " << value_base_from_db
373393
<< " which was outside of the value base range of"
374394
<< pre_read_expected_value.GetValueBase() << " to"
375395
<< post_read_expected_value.GetFinalValueBase()
@@ -403,7 +423,6 @@ class NonBatchedOpsStressTest : public StressTest {
403423
return iter->status();
404424
};
405425

406-
const int64_t max_key = shared->GetMaxKey();
407426
std::string ts_str;
408427
Slice ts;
409428
if (FLAGS_user_timestamp_size > 0) {
@@ -414,17 +433,6 @@ class NonBatchedOpsStressTest : public StressTest {
414433

415434
static Random64 rand64(shared->GetSeed());
416435

417-
{
418-
uint32_t crc = 0;
419-
std::unique_ptr<Iterator> it(cmp_db_->NewIterator(read_opts));
420-
s = checksum_column_family(it.get(), &crc);
421-
if (!s.ok()) {
422-
fprintf(stderr, "Computing checksum of default cf: %s\n",
423-
s.ToString().c_str());
424-
assert(false);
425-
}
426-
}
427-
428436
for (auto* handle : cmp_cfhs_) {
429437
if (thread->rand.OneInOpt(3)) {
430438
// Use Get()
@@ -435,7 +443,10 @@ class NonBatchedOpsStressTest : public StressTest {
435443
s = cmp_db_->Get(read_opts, handle, key_str, &value,
436444
FLAGS_user_timestamp_size > 0 ? &key_ts : nullptr);
437445
s.PermitUncheckedError();
438-
} else {
446+
} else if (!FLAGS_inplace_update_support) {
447+
// The combination of inplace_update_support=true and backward iteration
448+
// is not allowed
449+
439450
// Use range scan
440451
std::unique_ptr<Iterator> iter(cmp_db_->NewIterator(read_opts, handle));
441452
uint32_t rnd = (thread->rand.Next()) % 4;
@@ -458,6 +469,7 @@ class NonBatchedOpsStressTest : public StressTest {
458469
iter->Seek(key_str);
459470
for (int i = 0; i < 5 && iter->Valid(); ++i, iter->Next()) {
460471
}
472+
461473
} else {
462474
// SeekForPrev() + Prev()*5
463475
uint64_t key = rand64.Uniform(static_cast<uint64_t>(max_key));
@@ -466,6 +478,15 @@ class NonBatchedOpsStressTest : public StressTest {
466478
for (int i = 0; i < 5 && iter->Valid(); ++i, iter->Prev()) {
467479
}
468480
}
481+
} else {
482+
uint32_t crc = 0;
483+
std::unique_ptr<Iterator> it(cmp_db_->NewIterator(read_opts, handle));
484+
s = checksum_column_family(it.get(), &crc);
485+
if (!s.ok()) {
486+
fprintf(stderr, "Computing checksum of default cf: %s\n",
487+
s.ToString().c_str());
488+
assert(false);
489+
}
469490
}
470491
}
471492
}

0 commit comments

Comments
 (0)