Skip to content

Commit bd06353

Browse files
committed
Verification for secondary test fails but at least it is checking something
1 parent f8a0432 commit bd06353

File tree

4 files changed

+104
-56
lines changed

4 files changed

+104
-56
lines changed

db_stress_tool/db_stress_shared_state.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ class SharedState {
265265

266266
Status Restore(DB* db) { return expected_state_manager_->Restore(db); }
267267

268-
Status GetExpectedState(DB* db, std::unique_ptr<ExpectedState>& state) {
269-
return expected_state_manager_->GetExpectedState(db, state);
268+
Status SetSecondaryExpectedState(DB* db) {
269+
return expected_state_manager_->SetSecondaryExpectedState(db);
270270
}
271271

272272
// Requires external locking covering all keys in `cf`.
@@ -299,6 +299,10 @@ class SharedState {
299299
return expected_state_manager_->Get(cf, key);
300300
}
301301

302+
ExpectedValue GetSecondary(int cf, int64_t key) {
303+
return expected_state_manager_->GetSecondary(cf, key);
304+
}
305+
302306
// Prepare a Delete that will be started but not finish yet
303307
// This is useful for crash-recovery testing when the process may crash
304308
// before updating the corresponding expected value

db_stress_tool/expected_state.cc

+30-11
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ Status FileSnapshotExpectedState::Open(bool create) {
208208
if (create) {
209209
return Status::NotSupported();
210210
}
211-
size_t expected_values_size = GetValuesLen();
212211

213212
Env* default_env = Env::Default();
214213
Status status = default_env->NewMemoryMappedFileBuffer(
@@ -217,7 +216,7 @@ Status FileSnapshotExpectedState::Open(bool create) {
217216
return status;
218217
}
219218

220-
assert(expected_state_mmap_buffer_->GetLen() == expected_values_size);
219+
assert(expected_state_mmap_buffer_->GetLen() == GetValuesLen());
221220

222221
values_ = static_cast<std::atomic<uint32_t>*>(
223222
expected_state_mmap_buffer_->GetBase());
@@ -711,9 +710,9 @@ class ExpectedStateTraceRecordHandler : public TraceRecord::Handler,
711710

712711
} // anonymous namespace
713712

714-
Status FileExpectedStateManager::GetExpectedState(
715-
DB* db, std::unique_ptr<ExpectedState>& state) {
716-
std::cout << "Enter FileExpectedStateManager::GetExpectedState" << std::endl;
713+
Status FileExpectedStateManager::SetSecondaryExpectedState(DB* db) {
714+
std::cout << "Enter FileExpectedStateManager::SetSecondaryExpectedState"
715+
<< std::endl;
717716
assert(HasHistory());
718717
SequenceNumber seqno = db->GetLatestSequenceNumber();
719718
if (seqno < saved_seqno_) {
@@ -722,6 +721,7 @@ Status FileExpectedStateManager::GetExpectedState(
722721
return Status::Corruption("DB is older than any restorable expected state");
723722
}
724723

724+
// Create the trace reader. The trace file must exist.
725725
std::string trace_filename =
726726
std::to_string(saved_seqno_) + kTraceFilenameSuffix;
727727
std::string trace_file_path = GetPathForFilename(trace_filename);
@@ -744,26 +744,45 @@ Status FileExpectedStateManager::GetExpectedState(
744744
return s;
745745
}
746746

747+
// Create an expected state by replaying the trace
747748
std::string state_filename =
748749
std::to_string(saved_seqno_) + kStateFilenameSuffix;
749750
std::string state_file_path = GetPathForFilename(state_filename);
751+
std::cout << "state_file_path = " << state_file_path << std::endl;
752+
753+
std::string verification_file_temp_path = GetTempPathForFilename(
754+
"verification_" + std::to_string(seqno) + kStateFilenameSuffix);
755+
if (s.ok()) {
756+
s = CopyFile(FileSystem::Default(), state_file_path, Temperature::kUnknown,
757+
verification_file_temp_path, Temperature::kUnknown,
758+
0 /* size */, false /* use_fsync */, nullptr /* io_tracer */);
759+
}
760+
761+
if (!s.ok()) {
762+
return s;
763+
}
764+
765+
std::cout << "verification_file_temp_path: " << verification_file_temp_path
766+
<< std::endl;
750767
std::unique_ptr<FileSnapshotExpectedState> replay_state(
751-
new FileSnapshotExpectedState(state_file_path, max_key_,
768+
new FileSnapshotExpectedState(verification_file_temp_path, max_key_,
752769
num_column_families_));
753770
s = replay_state->Open(false /* create */);
754771
if (!s.ok()) {
755772
std::cout << "Error opening FileSnapshotExpectedState" << std::endl;
756773
return s;
757774
}
758-
759-
s = ReplayTrace(db, std::move(trace_reader), seqno - saved_seqno_,
760-
replay_state.get());
775+
uint64_t write_ops = seqno - saved_seqno_;
776+
std::cout << "Replaying " << write_ops << " operations from trace from "
777+
<< saved_seqno_ << " to " << seqno << std::endl;
778+
s = ReplayTrace(db, std::move(trace_reader), write_ops, replay_state.get());
761779
if (!s.ok()) {
762780
std::cout << "Error replaying trace" << std::endl;
763781
return s;
764782
}
765-
state = std::move(replay_state);
766-
std::cout << "Successful exit from GetExpectedState" << std::endl;
783+
secondary_expected_state_ = std::move(replay_state);
784+
assert(db->GetLatestSequenceNumber() == seqno);
785+
std::cout << "Successful exit from SetSecondaryExpectedState" << std::endl;
767786
return s;
768787
}
769788

db_stress_tool/expected_state.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ class ExpectedStateManager {
246246
// is executing.
247247
virtual Status Restore(DB* db) = 0;
248248

249-
virtual Status GetExpectedState(DB* db,
250-
std::unique_ptr<ExpectedState>& state) = 0;
249+
virtual Status SetSecondaryExpectedState(DB* db) = 0;
251250

252251
// Requires external locking covering all keys in `cf`.
253252
void ClearColumnFamily(int cf) { return latest_->ClearColumnFamily(cf); }
@@ -266,6 +265,10 @@ class ExpectedStateManager {
266265
// See ExpectedState::Get()
267266
ExpectedValue Get(int cf, int64_t key) { return latest_->Get(cf, key); }
268267

268+
ExpectedValue GetSecondary(int cf, int64_t key) {
269+
return secondary_expected_state_->Get(cf, key);
270+
}
271+
269272
// See ExpectedState::PrepareDelete()
270273
PendingExpectedValue PrepareDelete(int cf, int64_t key) {
271274
return latest_->PrepareDelete(cf, key);
@@ -343,8 +346,7 @@ class FileExpectedStateManager : public ExpectedStateManager {
343346
// file into "LATEST.state".
344347
Status Restore(DB* db) override;
345348

346-
Status GetExpectedState(DB* db,
347-
std::unique_ptr<ExpectedState>& state) override;
349+
Status SetSecondaryExpectedState(DB* db) override;
348350

349351
private:
350352
// Requires external locking preventing concurrent execution with any other
@@ -391,8 +393,7 @@ class AnonExpectedStateManager : public ExpectedStateManager {
391393
// currently have a need to keep history of expected state within a process.
392394
Status Restore(DB* /* db */) override { return Status::NotSupported(); }
393395

394-
Status GetExpectedState(
395-
DB* /* db */, std::unique_ptr<ExpectedState>& /* state */) override {
396+
Status SetSecondaryExpectedState(DB* /* db */) override {
396397
return Status::NotSupported();
397398
}
398399

db_stress_tool/no_batched_ops_stress.cc

+61-37
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class NonBatchedOpsStressTest : public StressTest {
128128
s = Status::NotFound();
129129
}
130130

131-
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
131+
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared,
132+
shared->Get(cf, i), from_db,
132133
/* msg_prefix */ "Iterator verification", s);
133134

134135
if (!from_db.empty()) {
@@ -147,7 +148,8 @@ class NonBatchedOpsStressTest : public StressTest {
147148

148149
Status s = db_->Get(options, column_families_[cf], key, &from_db);
149150

150-
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
151+
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared,
152+
shared->Get(cf, i), from_db,
151153
/* msg_prefix */ "Get verification", s);
152154

153155
if (!from_db.empty()) {
@@ -182,7 +184,8 @@ class NonBatchedOpsStressTest : public StressTest {
182184
}
183185
}
184186

185-
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
187+
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared,
188+
shared->Get(cf, i), from_db,
186189
/* msg_prefix */ "GetEntity verification", s);
187190

188191
if (!from_db.empty()) {
@@ -217,7 +220,8 @@ class NonBatchedOpsStressTest : public StressTest {
217220
const std::string from_db = values[j].ToString();
218221

219222
VerifyOrSyncValue(static_cast<int>(cf), i + j, options, shared,
220-
from_db, /* msg_prefix */ "MultiGet verification",
223+
shared->Get(cf, i + j), from_db,
224+
/* msg_prefix */ "MultiGet verification",
221225
statuses[j]);
222226

223227
if (!from_db.empty()) {
@@ -268,9 +272,10 @@ class NonBatchedOpsStressTest : public StressTest {
268272
}
269273
}
270274

271-
VerifyOrSyncValue(
272-
static_cast<int>(cf), i + j, options, shared, from_db,
273-
/* msg_prefix */ "MultiGetEntity verification", statuses[j]);
275+
VerifyOrSyncValue(static_cast<int>(cf), i + j, options, shared,
276+
shared->Get(cf, i + j), from_db,
277+
/* msg_prefix */ "MultiGetEntity verification",
278+
statuses[j]);
274279

275280
if (!from_db.empty()) {
276281
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i + j),
@@ -321,7 +326,8 @@ class NonBatchedOpsStressTest : public StressTest {
321326
from_db = values[number_of_operands - 1].ToString();
322327
}
323328

324-
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
329+
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared,
330+
shared->Get(cf, i), from_db,
325331
/* msg_prefix */ "GetMergeOperands verification",
326332
s);
327333

@@ -339,24 +345,52 @@ class NonBatchedOpsStressTest : public StressTest {
339345
return;
340346
}
341347

348+
assert(cmp_db_);
349+
assert(!cmp_cfhs_.empty());
350+
Status s = cmp_db_->TryCatchUpWithPrimary();
351+
if (!s.ok()) {
352+
assert(false);
353+
exit(1);
354+
}
355+
356+
auto* shared = thread->shared;
357+
assert(shared);
358+
const int64_t max_key = shared->GetMaxKey();
359+
ReadOptions read_opts(FLAGS_verify_checksum, true);
360+
342361
if (thread->shared->HasHistory()) {
343-
std::unique_ptr<ExpectedState> state;
344-
Status getExpectedStateStatus =
345-
thread->shared->GetExpectedState(db_, state);
346-
if (!getExpectedStateStatus.ok()) {
362+
uint64_t start_get_expected_state = clock_->NowMicros();
363+
Status setSecondaryExpectedStateStatus =
364+
thread->shared->SetSecondaryExpectedState(cmp_db_);
365+
if (!setSecondaryExpectedStateStatus.ok()) {
347366
std::cout << "[NonBatchedOpsStressTest::ContinuouslyVerifyDb]: Failed "
348367
"to get expected state"
349368
<< std::endl;
350369
assert(false);
351370
}
352-
}
371+
uint64_t end_get_expected_state = clock_->NowMicros();
372+
std::cout << "Retrieved expected state in "
373+
<< end_get_expected_state - start_get_expected_state
374+
<< " microseconds" << std::endl;
353375

354-
assert(cmp_db_);
355-
assert(!cmp_cfhs_.empty());
356-
Status s = cmp_db_->TryCatchUpWithPrimary();
357-
if (!s.ok()) {
358-
assert(false);
359-
exit(1);
376+
uint64_t start_secondary_scan = clock_->NowMicros();
377+
for (int64_t i = 0; i < max_key; ++i) {
378+
if (thread->shared->HasVerificationFailedYet()) {
379+
break;
380+
}
381+
const std::string key = Key(i);
382+
std::string from_db;
383+
s = cmp_db_->Get(read_opts, column_families_[0], key, &from_db);
384+
if (!VerifyOrSyncValue(
385+
0, i, read_opts, shared, shared->GetSecondary(0, i), from_db,
386+
/* msg_prefix */ "Secondary get verification", s)) {
387+
std::cout << "Failed on key i=" << i << std::endl;
388+
}
389+
}
390+
uint64_t end_secondary_scan = clock_->NowMicros();
391+
std::cout << "Scanned all of secondary db in "
392+
<< end_secondary_scan - start_secondary_scan << " microseconds"
393+
<< std::endl;
360394
}
361395

362396
const auto checksum_column_family = [](Iterator* iter,
@@ -371,10 +405,6 @@ class NonBatchedOpsStressTest : public StressTest {
371405
return iter->status();
372406
};
373407

374-
auto* shared = thread->shared;
375-
assert(shared);
376-
const int64_t max_key = shared->GetMaxKey();
377-
ReadOptions read_opts(FLAGS_verify_checksum, true);
378408
std::string ts_str;
379409
Slice ts;
380410
if (FLAGS_user_timestamp_size > 0) {
@@ -1644,9 +1674,11 @@ class NonBatchedOpsStressTest : public StressTest {
16441674

16451675
std::string from_db;
16461676
Status s = db_->Get(read_opts, cfh, k, &from_db);
1647-
bool res = VerifyOrSyncValue(
1648-
rand_column_family, rand_key, read_opts, shared,
1649-
/* msg_prefix */ "Pre-Put Get verification", from_db, s);
1677+
// looks like these arguments for msg_prefix and from_db were swapped
1678+
bool res =
1679+
VerifyOrSyncValue(rand_column_family, rand_key, read_opts, shared,
1680+
shared->Get(rand_column_family, rand_key), from_db,
1681+
/* msg_prefix */ "Pre-Put Get verification", s);
16501682

16511683
// Enable back error injection disabled for preparation
16521684
if (fault_fs_guard) {
@@ -2729,21 +2761,13 @@ class NonBatchedOpsStressTest : public StressTest {
27292761
}
27302762

27312763
bool VerifyOrSyncValue(int cf, int64_t key, const ReadOptions& opts,
2732-
SharedState* shared, const std::string& value_from_db,
2764+
SharedState* shared,
2765+
const ExpectedValue& expected_value,
2766+
const std::string& value_from_db,
27332767
std::string msg_prefix, const Status& s) const {
27342768
if (shared->HasVerificationFailedYet()) {
27352769
return false;
27362770
}
2737-
if (shared->HasHistory()) {
2738-
std::unique_ptr<ExpectedState> state;
2739-
Status getExpectedStateStatus = shared->GetExpectedState(db_, state);
2740-
if (!getExpectedStateStatus.ok()) {
2741-
std::cout << "[VerifyOrSyncValue]: Failed to get expected state"
2742-
<< std::endl;
2743-
return false;
2744-
}
2745-
}
2746-
const ExpectedValue expected_value = shared->Get(cf, key);
27472771

27482772
if (expected_value.PendingWrite() || expected_value.PendingDelete()) {
27492773
if (s.ok()) {

0 commit comments

Comments
 (0)