Skip to content

Commit

Permalink
Use copy of option in restore
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Oct 25, 2023
1 parent 0f14135 commit f63f5b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
53 changes: 48 additions & 5 deletions db_stress_tool/db_stress_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#include <ios>
#include <thread>

#include "rocksdb/options.h"
#include "util/compression.h"
#ifdef GFLAGS
#include "db_stress_tool/db_stress_common.h"
#include "db_stress_tool/db_stress_compaction_filter.h"
#include "db_stress_tool/db_stress_driver.h"
#include "db_stress_tool/db_stress_table_properties_collector.h"
#include "db_stress_tool/db_stress_wide_merge_operator.h"
#include "options/options_parser.h"
#include "rocksdb/convenience.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/secondary_cache.h"
Expand Down Expand Up @@ -1765,13 +1767,16 @@ Status StressTest::TestBackupRestore(
}
DB* restored_db = nullptr;
std::vector<ColumnFamilyHandle*> restored_cf_handles;

// Not yet implemented: opening restored BlobDB or TransactionDB
Options restore_options;
if (s.ok() && !FLAGS_use_txn && !FLAGS_use_blob_db) {
s = PrepareOptionsForRestoredDB(&restore_options);
if (!s.ok()) {
from = "PrepareRestoredDBOptions in backup/restore";
}
}
if (s.ok() && !FLAGS_use_txn && !FLAGS_use_blob_db) {
Options restore_options(options_);
restore_options.best_efforts_recovery = false;
restore_options.listeners.clear();
// Avoid dangling/shared file descriptors, for reliable destroy
restore_options.sst_file_manager = nullptr;
std::vector<ColumnFamilyDescriptor> cf_descriptors;
// TODO(ajkr): `column_family_names_` is not safe to access here when
// `clear_column_family_one_in != 0`. But we can't easily switch to
Expand Down Expand Up @@ -1889,6 +1894,44 @@ Status StressTest::TestBackupRestore(
return s;
}

Status StressTest::PrepareOptionsForRestoredDB(Options* options) {
assert(options);

Status s;
ConfigOptions config_opts;

std::string db_options_str;
s = GetStringFromDBOptions(config_opts, options_, &db_options_str);
if (!s.ok()) {
return s;
}
DBOptions db_options;
s = GetDBOptionsFromString(config_opts, Options(), db_options_str,
&db_options);
if (!s.ok()) {
return s;
}

std::string cf_options_str;
s = GetStringFromColumnFamilyOptions(config_opts, options_, &cf_options_str);
if (!s.ok()) {
return s;
}
ColumnFamilyOptions cf_options;
s = GetColumnFamilyOptionsFromString(config_opts, Options(), cf_options_str,
&cf_options);
if (!s.ok()) {
return s;
}

*options = Options(db_options, cf_options);
options->best_efforts_recovery = false;
options->listeners.clear();
// Avoid dangling/shared file descriptors, for reliable destroy
options->sst_file_manager = nullptr;

return Status::OK();
}
Status StressTest::TestApproximateSize(
ThreadState* thread, uint64_t iteration,
const std::vector<int>& rand_column_families,
Expand Down
2 changes: 2 additions & 0 deletions db_stress_tool/db_stress_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class StressTest {
const std::vector<int>& rand_column_families,
const std::vector<int64_t>& rand_keys);

virtual Status PrepareOptionsForRestoredDB(Options* options);

virtual Status TestCheckpoint(ThreadState* thread,
const std::vector<int>& rand_column_families,
const std::vector<int64_t>& rand_keys);
Expand Down

0 comments on commit f63f5b7

Please sign in to comment.