Fix Statistics in db_stress (#9260)

Summary:
The `Statistics` objects are meant to be shared across translation
units, but this was prevented by declaring them static. We need to
ensure they are defined once in the program. The effect is now
`StressTest::PrintStatistics()` can actually print statistics since it
now sees non-null values when `--statistics=1`.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9260

Reviewed By: zhichao-cao

Differential Revision: D32910162

Pulled By: ajkr

fbshipit-source-id: c926d6f556177987bee5fa3cbc87597803b230ee
This commit is contained in:
Andrew Kryczka 2021-12-07 16:22:52 -08:00 committed by Facebook GitHub Bot
parent a6a6aad74e
commit ce42ae6ffd
5 changed files with 23 additions and 2 deletions

View File

@ -871,6 +871,7 @@ cpp_library(
"db_stress_tool/db_stress_gflags.cc",
"db_stress_tool/db_stress_listener.cc",
"db_stress_tool/db_stress_shared_state.cc",
"db_stress_tool/db_stress_stat.cc",
"db_stress_tool/db_stress_test_base.cc",
"db_stress_tool/db_stress_tool.cc",
"db_stress_tool/expected_state.cc",

View File

@ -7,6 +7,7 @@ add_executable(db_stress${ARTIFACT_SUFFIX}
db_stress_gflags.cc
db_stress_listener.cc
db_stress_shared_state.cc
db_stress_stat.cc
db_stress_test_base.cc
db_stress_tool.cc
expected_state.cc

View File

@ -0,0 +1,17 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#ifdef GFLAGS
#include "db_stress_tool/db_stress_stat.h"
namespace ROCKSDB_NAMESPACE {
std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;
} // namespace ROCKSDB_NAMESPACE
#endif // GFLAGS

View File

@ -21,9 +21,10 @@ DECLARE_bool(histogram);
DECLARE_bool(progress_reports);
namespace ROCKSDB_NAMESPACE {
// Database statistics
static std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
static std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;
extern std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats;
extern std::shared_ptr<ROCKSDB_NAMESPACE::Statistics> dbstats_secondaries;
class Stats {
private:

1
src.mk
View File

@ -349,6 +349,7 @@ STRESS_LIB_SOURCES = \
db_stress_tool/db_stress_gflags.cc \
db_stress_tool/db_stress_listener.cc \
db_stress_tool/db_stress_shared_state.cc \
db_stress_tool/db_stress_stat.cc \
db_stress_tool/db_stress_test_base.cc \
db_stress_tool/db_stress_tool.cc \
db_stress_tool/expected_state.cc \