Navigation Menu

Skip to content

Commit

Permalink
Add stress test for GetProperty (facebook#7111)
Browse files Browse the repository at this point in the history
Summary:
Add stress test coverage for `DB::GetProperty()`.

Pull Request resolved: facebook#7111

Test Plan:
```
./db_stress -get_property_one_in=1
make crash_test
```

Reviewed By: ajkr

Differential Revision: D22487906

Pulled By: jay-zhuang

fbshipit-source-id: c118d95cc9b4e2fa669a06e6aa531541fa885dc5
  • Loading branch information
jay-zhuang authored and facebook-github-bot committed Jul 14, 2020
1 parent c628fae commit fc4d5f5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions db_stress_tool/db_stress_common.h
Expand Up @@ -221,6 +221,7 @@ DECLARE_bool(level_compaction_dynamic_level_bytes);
DECLARE_int32(verify_checksum_one_in);
DECLARE_int32(verify_db_one_in);
DECLARE_int32(continuous_verification_interval);
DECLARE_int32(get_property_one_in);

#ifndef ROCKSDB_LITE
DECLARE_bool(use_blob_db);
Expand Down
5 changes: 5 additions & 0 deletions db_stress_tool/db_stress_gflags.cc
Expand Up @@ -693,6 +693,11 @@ DEFINE_int32(approximate_size_one_in, 64,
DEFINE_int32(read_fault_one_in, 1000,
"On non-zero, enables fault injection on read");

DEFINE_int32(get_property_one_in, 1000,
"If non-zero, then DB::GetProperty() will be called to get various"
" properties for every N ops on average. 0 indicates that"
" GetProperty() will be not be called.");

DEFINE_bool(sync_fault_injection, false,
"If true, FaultInjectionTestFS will be used for write operations, "
" and unsynced data in DB will lost after crash.");
Expand Down
61 changes: 61 additions & 0 deletions db_stress_tool/db_stress_test_base.cc
Expand Up @@ -653,6 +653,10 @@ void StressTest::OperateDb(ThreadState* thread) {
VerificationAbort(shared, "VerifyChecksum status not OK", status);
}
}

if (thread->rand.OneInOpt(FLAGS_get_property_one_in)) {
TestGetProperty(thread);
}
#endif

std::vector<int64_t> rand_keys = GenerateKeys(rand_key);
Expand Down Expand Up @@ -1428,6 +1432,63 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
return s;
}

void StressTest::TestGetProperty(ThreadState* thread) const {
std::unordered_set<std::string> levelPropertyNames = {
DB::Properties::kAggregatedTablePropertiesAtLevel,
DB::Properties::kCompressionRatioAtLevelPrefix,
DB::Properties::kNumFilesAtLevelPrefix,
};
std::unordered_set<std::string> unknownPropertyNames = {
DB::Properties::kEstimateOldestKeyTime,
DB::Properties::kOptionsStatistics,
};
unknownPropertyNames.insert(levelPropertyNames.begin(),
levelPropertyNames.end());

std::string prop;
for (const auto& ppt_name_and_info : InternalStats::ppt_name_to_info) {
bool res = db_->GetProperty(ppt_name_and_info.first, &prop);
if (unknownPropertyNames.find(ppt_name_and_info.first) ==
unknownPropertyNames.end()) {
if (!res) {
fprintf(stderr, "Failed to get DB property: %s\n",
ppt_name_and_info.first.c_str());
thread->shared->SetVerificationFailure();
}
if (ppt_name_and_info.second.handle_int != nullptr) {
uint64_t prop_int;
if (!db_->GetIntProperty(ppt_name_and_info.first, &prop_int)) {
fprintf(stderr, "Failed to get Int property: %s\n",
ppt_name_and_info.first.c_str());
thread->shared->SetVerificationFailure();
}
}
}
}

ROCKSDB_NAMESPACE::ColumnFamilyMetaData cf_meta_data;
db_->GetColumnFamilyMetaData(&cf_meta_data);
int level_size = static_cast<int>(cf_meta_data.levels.size());
for (int level = 0; level < level_size; level++) {
for (const auto& ppt_name : levelPropertyNames) {
bool res = db_->GetProperty(ppt_name + std::to_string(level), &prop);
if (!res) {
fprintf(stderr, "Failed to get DB property: %s\n",
(ppt_name + std::to_string(level)).c_str());
thread->shared->SetVerificationFailure();
}
}
}

// Test for an invalid property name
if (thread->rand.OneIn(100)) {
if (db_->GetProperty("rocksdb.invalid_property_name", &prop)) {
fprintf(stderr, "Failed to return false for invalid property name\n");
thread->shared->SetVerificationFailure();
}
}
}

void StressTest::TestCompactFiles(ThreadState* thread,
ColumnFamilyHandle* column_family) {
ROCKSDB_NAMESPACE::ColumnFamilyMetaData cf_meta_data;
Expand Down
1 change: 1 addition & 0 deletions db_stress_tool/db_stress_test_base.h
Expand Up @@ -189,6 +189,7 @@ class StressTest {
Status VerifyGetLiveFiles() const;
Status VerifyGetSortedWalFiles() const;
Status VerifyGetCurrentWalFile() const;
void TestGetProperty(ThreadState* thread) const;

virtual Status TestApproximateSize(
ThreadState* thread, uint64_t iteration,
Expand Down
3 changes: 2 additions & 1 deletion tools/db_crashtest.py
Expand Up @@ -127,7 +127,8 @@
"max_key_len": 3,
"key_len_percent_dist": "1,30,69",
"read_fault_one_in": lambda: random.choice([0, 1000]),
"sync_fault_injection": False
"sync_fault_injection": False,
"get_property_one_in": 1000000,
}

_TEST_DIR_ENV_VAR = 'TEST_TMPDIR'
Expand Down

0 comments on commit fc4d5f5

Please sign in to comment.