RocksDB: fix bug in crash-recovery correctness testing (#9897)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9897 Fixes https://github.com/facebook/rocksdb/issues/9385. Update State to reflect the value in the DB after a crash Reviewed By: ajkr Differential Revision: D35788808 fbshipit-source-id: 2d21d8537ab380a17cad3e90ac72b3eb1b56de9f
This commit is contained in:
parent
9d0cae7104
commit
68ee228dec
@ -84,8 +84,8 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
// move to the next item in the iterator
|
// move to the next item in the iterator
|
||||||
s = Status::NotFound();
|
s = Status::NotFound();
|
||||||
}
|
}
|
||||||
VerifyValue(static_cast<int>(cf), i, options, shared, from_db, s,
|
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
|
||||||
true);
|
s, true);
|
||||||
if (from_db.length()) {
|
if (from_db.length()) {
|
||||||
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
||||||
from_db.data(), from_db.length());
|
from_db.data(), from_db.length());
|
||||||
@ -101,8 +101,8 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
std::string keystr = Key(i);
|
std::string keystr = Key(i);
|
||||||
Slice k = keystr;
|
Slice k = keystr;
|
||||||
Status s = db_->Get(options, column_families_[cf], k, &from_db);
|
Status s = db_->Get(options, column_families_[cf], k, &from_db);
|
||||||
VerifyValue(static_cast<int>(cf), i, options, shared, from_db, s,
|
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
|
||||||
true);
|
s, true);
|
||||||
if (from_db.length()) {
|
if (from_db.length()) {
|
||||||
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
||||||
from_db.data(), from_db.length());
|
from_db.data(), from_db.length());
|
||||||
@ -130,8 +130,8 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
for (size_t j = 0; j < batch_size; ++j) {
|
for (size_t j = 0; j < batch_size; ++j) {
|
||||||
Status s = statuses[j];
|
Status s = statuses[j];
|
||||||
std::string from_db = values[j].ToString();
|
std::string from_db = values[j].ToString();
|
||||||
VerifyValue(static_cast<int>(cf), i + j, options, shared, from_db,
|
VerifyOrSyncValue(static_cast<int>(cf), i + j, options, shared,
|
||||||
s, true);
|
from_db, s, true);
|
||||||
if (from_db.length()) {
|
if (from_db.length()) {
|
||||||
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i + j),
|
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i + j),
|
||||||
from_db.data(), from_db.length());
|
from_db.data(), from_db.length());
|
||||||
@ -174,8 +174,8 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
if (number_of_operands) {
|
if (number_of_operands) {
|
||||||
from_db = values[number_of_operands - 1].ToString();
|
from_db = values[number_of_operands - 1].ToString();
|
||||||
}
|
}
|
||||||
VerifyValue(static_cast<int>(cf), i, options, shared, from_db, s,
|
VerifyOrSyncValue(static_cast<int>(cf), i, options, shared, from_db,
|
||||||
true);
|
s, true);
|
||||||
if (from_db.length()) {
|
if (from_db.length()) {
|
||||||
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
|
||||||
from_db.data(), from_db.length());
|
from_db.data(), from_db.length());
|
||||||
@ -562,8 +562,8 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
Slice k = key_str2;
|
Slice k = key_str2;
|
||||||
std::string from_db;
|
std::string from_db;
|
||||||
Status s = db_->Get(read_opts, cfh, k, &from_db);
|
Status s = db_->Get(read_opts, cfh, k, &from_db);
|
||||||
if (!VerifyValue(rand_column_family, rand_key, read_opts, shared, from_db,
|
if (!VerifyOrSyncValue(rand_column_family, rand_key, read_opts, shared,
|
||||||
s, true)) {
|
from_db, s, true)) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -882,16 +882,24 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
}
|
}
|
||||||
#endif // ROCKSDB_LITE
|
#endif // ROCKSDB_LITE
|
||||||
|
|
||||||
bool VerifyValue(int cf, int64_t key, const ReadOptions& /*opts*/,
|
bool VerifyOrSyncValue(int cf, int64_t key, const ReadOptions& /*opts*/,
|
||||||
SharedState* shared, const std::string& value_from_db,
|
SharedState* shared, const std::string& value_from_db,
|
||||||
const Status& s, bool strict = false) const {
|
const Status& s, bool strict = false) const {
|
||||||
if (shared->HasVerificationFailedYet()) {
|
if (shared->HasVerificationFailedYet()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// compare value_from_db with the value in the shared state
|
// compare value_from_db with the value in the shared state
|
||||||
char value[kValueMaxLen];
|
|
||||||
uint32_t value_base = shared->Get(cf, key);
|
uint32_t value_base = shared->Get(cf, key);
|
||||||
if (value_base == SharedState::UNKNOWN_SENTINEL) {
|
if (value_base == SharedState::UNKNOWN_SENTINEL) {
|
||||||
|
if (s.ok()) {
|
||||||
|
// Value exists in db, update state to reflect that
|
||||||
|
Slice slice(value_from_db);
|
||||||
|
value_base = GetValueBase(slice);
|
||||||
|
shared->Put(cf, key, value_base, false);
|
||||||
|
} else if (s.IsNotFound()) {
|
||||||
|
// Value doesn't exist in db, update state to reflect that
|
||||||
|
shared->SingleDelete(cf, key, false);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (value_base == SharedState::DELETION_SENTINEL && !strict) {
|
if (value_base == SharedState::DELETION_SENTINEL && !strict) {
|
||||||
@ -899,6 +907,7 @@ class NonBatchedOpsStressTest : public StressTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
|
char value[kValueMaxLen];
|
||||||
if (value_base == SharedState::DELETION_SENTINEL) {
|
if (value_base == SharedState::DELETION_SENTINEL) {
|
||||||
VerificationAbort(shared, "Unexpected value found", cf, key);
|
VerificationAbort(shared, "Unexpected value found", cf, key);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user