summaryrefslogtreecommitdiff
path: root/db/repair.cc
diff options
context:
space:
mode:
authormrambacher <mrambach@gmail.com>2021-07-30 12:15:04 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2021-07-30 12:16:44 -0700
commitab7f7c9e497a18c48837556bf2e68b4cc5d2a498 (patch)
treee6000afde87aa4df0620d5c770c54c4b24ab5356 /db/repair.cc
parent066b51126dcfc4f167d17251e8926f131ffc8a38 (diff)
Allow WAL dir to change with db dir (#8582)
Summary: Prior to this change, the "wal_dir" DBOption would always be set (defaults to dbname) when the DBOptions were sanitized. Because of this setitng in the options file, it was not possible to rename/relocate a database directory after it had been created and use the existing options file. After this change, the "wal_dir" option is only set under specific circumstances. Methods were added to the ImmutableDBOptions class to see if it is set and if it is set to something other than the dbname. Additionally, a method was added to retrieve the effective value of the WAL dir (either the option or the dbname/path). Tests were added to the core and ldb to test that a database could be created and renamed without issue. Additional tests for various permutations of wal_dir were also added. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8582 Reviewed By: pdillinger, autopear Differential Revision: D29881122 Pulled By: mrambacher fbshipit-source-id: 67d3d033dc8813d59917b0a3fba2550c0efd6dfb
Diffstat (limited to 'db/repair.cc')
-rw-r--r--db/repair.cc23
1 files changed, 8 insertions, 15 deletions
diff --git a/db/repair.cc b/db/repair.cc
index 28f28d440..7eaf8adcc 100644
--- a/db/repair.cc
+++ b/db/repair.cc
@@ -286,23 +286,15 @@ class Repairer {
}
// search wal_dir if user uses a customize wal_dir
- bool same = false;
- Status status = env_->AreFilesSame(db_options_.wal_dir, dbname_, &same);
- if (status.IsNotSupported()) {
- same = db_options_.wal_dir == dbname_;
- status = Status::OK();
- } else if (!status.ok()) {
- return status;
- }
-
+ bool same = immutable_db_options_.IsWalDirSameAsDBPath(dbname_);
if (!same) {
- to_search_paths.push_back(db_options_.wal_dir);
+ to_search_paths.push_back(immutable_db_options_.wal_dir);
}
for (size_t path_id = 0; path_id < to_search_paths.size(); path_id++) {
ROCKS_LOG_INFO(db_options_.info_log, "Searching path %s\n",
to_search_paths[path_id].c_str());
- status = env_->GetChildren(to_search_paths[path_id], &filenames);
+ Status status = env_->GetChildren(to_search_paths[path_id], &filenames);
if (!status.ok()) {
return status;
}
@@ -339,10 +331,11 @@ class Repairer {
}
void ConvertLogFilesToTables() {
+ const auto& wal_dir = immutable_db_options_.GetWalDir();
for (size_t i = 0; i < logs_.size(); i++) {
// we should use LogFileName(wal_dir, logs_[i]) here. user might uses wal_dir option.
- std::string logname = LogFileName(db_options_.wal_dir, logs_[i]);
- Status status = ConvertLogToTable(logs_[i]);
+ std::string logname = LogFileName(wal_dir, logs_[i]);
+ Status status = ConvertLogToTable(wal_dir, logs_[i]);
if (!status.ok()) {
ROCKS_LOG_WARN(db_options_.info_log,
"Log #%" PRIu64 ": ignoring conversion error: %s",
@@ -352,7 +345,7 @@ class Repairer {
}
}
- Status ConvertLogToTable(uint64_t log) {
+ Status ConvertLogToTable(const std::string& wal_dir, uint64_t log) {
struct LogReporter : public log::Reader::Reporter {
Env* env;
std::shared_ptr<Logger> info_log;
@@ -365,7 +358,7 @@ class Repairer {
};
// Open the log file
- std::string logname = LogFileName(db_options_.wal_dir, log);
+ std::string logname = LogFileName(wal_dir, log);
const auto& fs = env_->GetFileSystem();
std::unique_ptr<SequentialFileReader> lfile_reader;
Status status = SequentialFileReader::Create(