diff --git a/tools/db_stress.cc b/tools/db_stress.cc index e4aa85e0d..da2a122d4 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -2372,6 +2372,11 @@ class StressTest { } #endif } + while (!thread->snapshot_queue.empty()) { + db_->ReleaseSnapshot(thread->snapshot_queue.front().second.snapshot); + delete thread->snapshot_queue.front().second.key_vec; + thread->snapshot_queue.pop(); + } thread->stats.Stop(); } @@ -2486,8 +2491,7 @@ class StressTest { ReadOptions cmp_ro; cmp_ro.snapshot = snapshot; cmp_ro.total_order_seek = true; - std::unique_ptr cmp_iter( - db_->NewIterator(readoptionscopy, cfh)); + std::unique_ptr cmp_iter(db_->NewIterator(cmp_ro, cfh)); bool diverged = false; iter->Seek(key); @@ -2539,12 +2543,27 @@ class StressTest { return; } + if (ro.iterate_lower_bound != nullptr) { + // Lower bound would create a lot of discrepency for now so disabling + // the verification for now. + *diverged = true; + return; + } + if (iter->Valid() && !cmp_iter->Valid()) { fprintf(stderr, - "Control interator is invalid but iterator has value %s seek key " + "Control interator is invalid but iterator has key %s seek key " "%s\n", iter->key().ToString(true).c_str(), seek_key.ToString(true).c_str()); + if (ro.iterate_upper_bound != nullptr) { + fprintf(stderr, "upper bound %s\n", + ro.iterate_upper_bound->ToString(true).c_str()); + } + if (ro.iterate_lower_bound != nullptr) { + fprintf(stderr, "lower bound %s\n", + ro.iterate_lower_bound->ToString(true).c_str()); + } *diverged = true; } else if (cmp_iter->Valid()) { @@ -2582,8 +2601,8 @@ class StressTest { } // Check upper or lower bounds. if (!*diverged) { - if (!iter->Valid() || - (iter->key() != cmp_iter->key() && + if ((iter->Valid() && iter->key() != cmp_iter->key()) || + (!iter->Valid() && (ro.iterate_upper_bound == nullptr || cmp->Compare(total_order_key, *ro.iterate_upper_bound) < 0) && (ro.iterate_lower_bound == nullptr || @@ -3280,6 +3299,8 @@ class NonBatchedOpsStressTest : public StressTest { const int64_t keys_per_thread = max_key / shared->GetNumThreads(); int64_t start = keys_per_thread * thread->tid; int64_t end = start + keys_per_thread; + uint64_t prefix_to_use = + (FLAGS_prefix_size < 0) ? 1 : static_cast(FLAGS_prefix_size); if (thread->tid == shared->GetNumThreads() - 1) { end = max_key; } @@ -3298,8 +3319,7 @@ class NonBatchedOpsStressTest : public StressTest { } // TODO(ljin): update "long" to uint64_t // Reseek when the prefix changes - if (i % (static_cast(1) << 8 * (8 - FLAGS_prefix_size)) == - 0) { + if (i % (static_cast(1) << 8 * (8 - prefix_to_use)) == 0) { iter->Seek(Key(i)); } std::string from_db; @@ -4042,6 +4062,8 @@ class BatchedOpsStressTest : public StressTest { virtual Status TestPrefixScan(ThreadState* thread, const ReadOptions& readoptions, const std::vector& rand_column_families, const std::vector& rand_keys) { + size_t prefix_to_use = + (FLAGS_prefix_size < 0) ? 7 : static_cast(FLAGS_prefix_size); std::string key_str = Key(rand_keys[0]); Slice key = key_str; auto cfh = column_families_[rand_column_families[0]]; @@ -4056,7 +4078,7 @@ class BatchedOpsStressTest : public StressTest { Status s = Status::OK(); for (int i = 0; i < 10; i++) { prefixes[i] += key.ToString(); - prefixes[i].resize(FLAGS_prefix_size); + prefixes[i].resize(prefix_to_use); prefix_slices[i] = Slice(prefixes[i]); readoptionscopy[i] = readoptions; readoptionscopy[i].snapshot = snapshot;