From 5cd8aaf75f24509edc77f75ccb08d09ff62ebb55 Mon Sep 17 00:00:00 2001 From: sdong Date: Fri, 27 Sep 2019 16:53:49 -0700 Subject: [PATCH] db_stress: fix run time error when prefix_size = -1 (#5862) Summary: When prefix_size = -1, stress test crashes with run time error because of overflow. Fix it by not using -1 but 7 in prefix scan mode. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5862 Test Plan: Run python -u tools/db_crashtest.py --simple whitebox --random_kill_odd \ 888887 --compression_type=zstd and see it doesn't crash. Differential Revision: D17642313 fbshipit-source-id: f029e7651498c905af1b1bee6d310ae50cdcda41 --- tools/db_stress.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 30a62e7f2..e4aa85e0d 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -4285,9 +4285,12 @@ class CfConsistencyStressTest : public StressTest { 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; - Slice prefix = Slice(key.data(), FLAGS_prefix_size); + Slice prefix = Slice(key.data(), prefix_to_use); std::string upper_bound; Slice ub_slice; @@ -4305,7 +4308,7 @@ class CfConsistencyStressTest : public StressTest { iter->Next()) { ++count; } - assert(count <= (static_cast(1) << ((8 - FLAGS_prefix_size) * 8))); + assert(count <= (static_cast(1) << ((8 - prefix_to_use) * 8))); Status s = iter->status(); if (s.ok()) { thread->stats.AddPrefixes(1, count);