Update stress test

This commit is contained in:
Yanqin Jin 2022-04-17 17:14:07 -07:00
parent 6712cd8270
commit c4548d6254
6 changed files with 23 additions and 6 deletions

View File

@ -290,6 +290,8 @@ DECLARE_bool(adaptive_readahead);
DECLARE_bool(async_io); DECLARE_bool(async_io);
DECLARE_string(wal_compression); DECLARE_string(wal_compression);
DECLARE_int32(create_shared_snapshot_one_in);
constexpr long KB = 1024; constexpr long KB = 1024;
constexpr int kRandomValueMaxFactor = 3; constexpr int kRandomValueMaxFactor = 3;
constexpr int kValueMaxLen = 100; constexpr int kValueMaxLen = 100;

View File

@ -936,4 +936,7 @@ DEFINE_bool(
DEFINE_string(wal_compression, "none", DEFINE_string(wal_compression, "none",
"Algorithm to use for WAL compression. none to disable."); "Algorithm to use for WAL compression. none to disable.");
DEFINE_int32(create_shared_snapshot_one_in, 0,
"On non-zero, create shared snapshots upon transaction commits.");
#endif // GFLAGS #endif // GFLAGS

View File

@ -617,13 +617,24 @@ Status StressTest::NewTxn(WriteOptions& write_opts, Transaction** txn) {
return s; return s;
} }
Status StressTest::CommitTxn(Transaction* txn) { Status StressTest::CommitTxn(Transaction* txn, ThreadState* thread) {
if (!FLAGS_use_txn) { if (!FLAGS_use_txn) {
return Status::InvalidArgument("CommitTxn when FLAGS_use_txn is not set"); return Status::InvalidArgument("CommitTxn when FLAGS_use_txn is not set");
} }
Status s = txn->Prepare(); Status s = txn->Prepare();
if (s.ok()) { if (s.ok()) {
if (thread && FLAGS_create_shared_snapshot_one_in &&
thread->rand.OneIn(FLAGS_create_shared_snapshot_one_in)) {
uint64_t ts = db_stress_env->NowNanos();
s = txn->SetCommitTimestamp(ts);
assert(s.ok());
txn->SetSnapshotOnNextOperation();
}
s = txn->Commit(); s = txn->Commit();
assert(txn_db_);
uint64_t ts2 = db_stress_env->NowNanos();
uint64_t ts_delta = 5ULL * 1000 * 1000 * 1000;
txn_db_->ReleaseSharedSnapshotsOlderThan(ts2 - ts_delta);
} }
delete txn; delete txn;
return s; return s;

View File

@ -59,7 +59,7 @@ class StressTest {
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
Status NewTxn(WriteOptions& write_opts, Transaction** txn); Status NewTxn(WriteOptions& write_opts, Transaction** txn);
Status CommitTxn(Transaction* txn); Status CommitTxn(Transaction* txn, ThreadState* thread = nullptr);
Status RollbackTxn(Transaction* txn); Status RollbackTxn(Transaction* txn);
#endif #endif

View File

@ -568,7 +568,7 @@ class NonBatchedOpsStressTest : public StressTest {
if (s.ok()) { if (s.ok()) {
s = txn->Merge(cfh, key, v); s = txn->Merge(cfh, key, v);
if (s.ok()) { if (s.ok()) {
s = CommitTxn(txn); s = CommitTxn(txn, thread);
} }
} }
#endif #endif
@ -587,7 +587,7 @@ class NonBatchedOpsStressTest : public StressTest {
if (s.ok()) { if (s.ok()) {
s = txn->Put(cfh, key, v); s = txn->Put(cfh, key, v);
if (s.ok()) { if (s.ok()) {
s = CommitTxn(txn); s = CommitTxn(txn, thread);
} }
} }
#endif #endif
@ -648,7 +648,7 @@ class NonBatchedOpsStressTest : public StressTest {
if (s.ok()) { if (s.ok()) {
s = txn->Delete(cfh, key); s = txn->Delete(cfh, key);
if (s.ok()) { if (s.ok()) {
s = CommitTxn(txn); s = CommitTxn(txn, thread);
} }
} }
#endif #endif
@ -685,7 +685,7 @@ class NonBatchedOpsStressTest : public StressTest {
if (s.ok()) { if (s.ok()) {
s = txn->SingleDelete(cfh, key); s = txn->SingleDelete(cfh, key);
if (s.ok()) { if (s.ok()) {
s = CommitTxn(txn); s = CommitTxn(txn, thread);
} }
} }
#endif #endif

View File

@ -310,6 +310,7 @@ txn_params = {
"checkpoint_one_in": 0, "checkpoint_one_in": 0,
# pipeline write is not currnetly compatible with WritePrepared txns # pipeline write is not currnetly compatible with WritePrepared txns
"enable_pipelined_write": 0, "enable_pipelined_write": 0,
"create_shared_snapshot_one_in": 10,
} }
best_efforts_recovery_params = { best_efforts_recovery_params = {