Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed May 12, 2023
1 parent bf280f0 commit 756af42
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 415 deletions.
6 changes: 5 additions & 1 deletion db_stress_tool/batched_ops_stress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BatchedOpsStressTest : public StressTest {
const std::string key_body = Key(rand_keys[0]);

const uint32_t value_base =
thread->rand.Next() % thread->shared->RANDOM_VALUE_BASE_GENERATOR;
thread->rand.Next() % RANDOM_VALUE_BASE_GENERATOR;
const size_t sz = GenerateValue(value_base, value, sizeof(value));
const std::string value_body = Slice(value, sz).ToString();

Expand Down Expand Up @@ -586,6 +586,10 @@ class BatchedOpsStressTest : public StressTest {

return true;
}

private:
// Used to generate random value base
static constexpr uint32_t RANDOM_VALUE_BASE_GENERATOR = 0xfffffffe;
};

StressTest* CreateBatchedOpsStressTest() { return new BatchedOpsStressTest(); }
Expand Down
52 changes: 26 additions & 26 deletions db_stress_tool/db_stress_shared_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class StressTest;
// State shared by all concurrent executions of the same benchmark.
class SharedState {
public:
// Used to generate random value base for non-NonBatchedOpsStressTest
static constexpr uint32_t RANDOM_VALUE_BASE_GENERATOR = 0xfffffffe;

// Errors when reading filter blocks are ignored, so we use a thread
// local variable updated via sync points to keep track of errors injected
// while reading filter blocks in order to ignore the Get/MultiGet result
Expand Down Expand Up @@ -251,47 +248,43 @@ class SharedState {
return expected_state_manager_->ClearColumnFamily(cf);
}

// @param pending True if the update may have started but is not yet
// guaranteed finished. This is useful for crash-recovery testing when the
// process may crash before updating the expected values array.
// Prepare a Put that will be started but not finish yet
// This is useful for crash-recovery testing when the process may crash
// before updating the corresponding expected value
//
// Requires external locking covering `key` in `cf` to prevent concurrent
// write or delete to the same `key`.
ExpectedValue& Put(int cf, int64_t key, bool pending) {
return expected_state_manager_->Put(cf, key, pending);
PendingExpectedValue PreparePut(int cf, int64_t key) {
return expected_state_manager_->PreparePut(cf, key);
}

// Does not requires external locking.
uint32_t Get(int cf, int64_t key) {
ExpectedValue Get(int cf, int64_t key) {
return expected_state_manager_->Get(cf, key);
}

// @param pending See comment above Put()
// Returns true if the key was not yet deleted.
// Prepare a Delete that will be started but not finish yet
// This is useful for crash-recovery testing when the process may crash
// before updating the corresponding expected value
//
// Requires external locking covering `key` in `cf` to prevent concurrent
// write or delete to the same `key`.
bool Delete(int cf, int64_t key, bool pending) {
return expected_state_manager_->Delete(cf, key, pending);
PendingExpectedValue PrepareDelete(int cf, int64_t key) {
return expected_state_manager_->PrepareDelete(cf, key);
}

// @param pending See comment above Put()
// Returns true if the key was not yet deleted.
//
// Requires external locking covering `key` in `cf` to prevent concurrent
// write or delete to the same `key`.
bool SingleDelete(int cf, int64_t key, bool pending) {
return expected_state_manager_->Delete(cf, key, pending);
PendingExpectedValue PrepareSingleDelete(int cf, int64_t key) {
return expected_state_manager_->PrepareSingleDelete(cf, key);
}

// @param pending See comment above Put()
// Returns number of keys deleted by the call.
//
// Requires external locking covering keys in `[begin_key, end_key)` in `cf`
// to prevent concurrent write or delete to the same `key`.
int DeleteRange(int cf, int64_t begin_key, int64_t end_key, bool pending) {
return expected_state_manager_->DeleteRange(cf, begin_key, end_key,
pending);
std::vector<PendingExpectedValue> PrepareDeleteRange(int cf,
int64_t begin_key,
int64_t end_key) {
return expected_state_manager_->PrepareDeleteRange(cf, begin_key, end_key);
}

bool AllowsOverwrite(int64_t key) const {
Expand All @@ -304,12 +297,19 @@ class SharedState {
return expected_state_manager_->Exists(cf, key);
}

// Sync the `value_base` to the corresponding expected value
void SyncPut(int cf, int64_t key, uint32_t value_base) {
return expected_state_manager_->SyncPut(cf, key, value_base);
}

void SyncSingleDelete(int cf, int64_t key) {
return expected_state_manager_->SyncSingleDelete(cf, key);
// Sync the corresponding expected value to be pending Put
void SyncPendingPut(int cf, int64_t key) {
return expected_state_manager_->SyncPendingPut(cf, key);
}

// Sync the corresponding expected value to be deleted
void SyncDelete(int cf, int64_t key) {
return expected_state_manager_->SyncDelete(cf, key);
}

uint32_t GetSeed() const { return seed_; }
Expand Down
11 changes: 5 additions & 6 deletions db_stress_tool/db_stress_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
for (int64_t k = 0; k != number_of_keys; ++k) {
const std::string key = Key(k);

const ExpectedValue& expected_value =
shared->Put(cf_idx, k, true /* pending */);
const uint32_t value_base = expected_value.GetFinalValueBase();
PendingExpectedValue pending_expected_value =
shared->PreparePut(cf_idx, k);
const uint32_t value_base = pending_expected_value.GetFinalValueBase();
const size_t sz = GenerateValue(value_base, value, sizeof(value));

const Slice v(value, sz);
Expand Down Expand Up @@ -535,7 +535,7 @@ void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
}
}

shared->Put(cf_idx, k, false /* pending */);
pending_expected_value.Commit();
if (!s.ok()) {
break;
}
Expand Down Expand Up @@ -615,8 +615,7 @@ void StressTest::ProcessRecoveredPreparedTxnsHelper(Transaction* txn,
for (wbwi_iter->SeekToFirst(); wbwi_iter->Valid(); wbwi_iter->Next()) {
uint64_t key_val;
if (GetIntVal(wbwi_iter->Entry().key.ToString(), &key_val)) {
shared->Put(static_cast<int>(i) /* cf_idx */, key_val,
true /* pending */);
shared->SyncPendingPut(static_cast<int>(i) /* cf_idx */, key_val);
}
}
}
Expand Down
Loading

0 comments on commit 756af42

Please sign in to comment.