mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-30 22:41:48 +00:00
509947ce2c
Summary: Part of the procedures to handle manifest IO error is to disable file deletion in case some files in limbo state get deleted prematurely. This is not ideal because: 1) not all the VersionEdits whose commit encounter such an error contain updates for files, disabling file deletion sometimes are not necessary. 2) `EnableFileDeletion` has a force mode that could make other threads accidentally disrupt this procedure in recovery. 3) Disabling file deletion as a whole is also not as efficient as more precisely tracking impacted files from being prematurely deleted. This PR replaces this mechanism with tracking such files and quarantine them from being deleted in `ErrorHandler`. These are the types of files being actively tracked in quarantine in this PR: 1) new table files and blob files from a background job 2) old manifest file whose immediately following new manifest file's CURRENT file creation gets into unclear state. Current handling is not sufficient to make sure the old manifest file is kept in case it's needed. Note that WAL logs are not part of the quarantine because `min_log_number_to_keep` is a safe mechanism and it's only updated after successful manifest commits so it can prevent this premature deletion issue from happening. We track these files' file numbers because they share the same file number space. Pull Request resolved: https://github.com/facebook/rocksdb/pull/12030 Test Plan: Modified existing unit tests Reviewed By: ajkr Differential Revision: D51036774 Pulled By: jowlyzhang fbshipit-source-id: 84ef26271fbbc888ef70da5c40fe843bd7038716
75 lines
3 KiB
C++
75 lines
3 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates. 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).
|
|
|
|
#pragma once
|
|
|
|
#include "db/version_set.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// Instead of opening a `DB` to perform certain manifest updates, this
|
|
// uses the underlying `VersionSet` API to read and modify the MANIFEST. This
|
|
// allows us to use the user's real options, while not having to worry about
|
|
// the DB persisting new SST files via flush/compaction or attempting to read/
|
|
// compact files which may fail, particularly for the file we intend to remove
|
|
// (the user may want to remove an already deleted file from MANIFEST).
|
|
class OfflineManifestWriter {
|
|
public:
|
|
OfflineManifestWriter(const DBOptions& options, const std::string& db_path)
|
|
: wc_(options.delayed_write_rate),
|
|
wb_(options.db_write_buffer_size),
|
|
immutable_db_options_(WithDbPath(options, db_path)),
|
|
tc_(NewLRUCache(1 << 20 /* capacity */,
|
|
options.table_cache_numshardbits)),
|
|
versions_(db_path, &immutable_db_options_, sopt_, tc_.get(), &wb_, &wc_,
|
|
/*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr,
|
|
/*db_id=*/"", /*db_session_id=*/"",
|
|
options.daily_offpeak_time_utc,
|
|
/*error_handler=*/nullptr) {}
|
|
|
|
Status Recover(const std::vector<ColumnFamilyDescriptor>& column_families) {
|
|
return versions_.Recover(column_families, /*read_only*/ false,
|
|
/*db_id*/ nullptr,
|
|
/*no_error_if_files_missing*/ true);
|
|
}
|
|
|
|
Status LogAndApply(const ReadOptions& read_options, ColumnFamilyData* cfd,
|
|
VersionEdit* edit,
|
|
FSDirectory* dir_contains_current_file) {
|
|
// Use `mutex` to imitate a locked DB mutex when calling `LogAndApply()`.
|
|
InstrumentedMutex mutex;
|
|
mutex.Lock();
|
|
Status s = versions_.LogAndApply(
|
|
cfd, *cfd->GetLatestMutableCFOptions(), read_options, edit, &mutex,
|
|
dir_contains_current_file, false /* new_descriptor_log */);
|
|
mutex.Unlock();
|
|
return s;
|
|
}
|
|
|
|
VersionSet& Versions() { return versions_; }
|
|
const ImmutableDBOptions& IOptions() { return immutable_db_options_; }
|
|
|
|
private:
|
|
WriteController wc_;
|
|
WriteBufferManager wb_;
|
|
ImmutableDBOptions immutable_db_options_;
|
|
std::shared_ptr<Cache> tc_;
|
|
EnvOptions sopt_;
|
|
VersionSet versions_;
|
|
|
|
static ImmutableDBOptions WithDbPath(const DBOptions& options,
|
|
const std::string& db_path) {
|
|
ImmutableDBOptions rv(options);
|
|
if (rv.db_paths.empty()) {
|
|
// `VersionSet` expects options that have been through
|
|
// `SanitizeOptions()`, which would sanitize an empty `db_paths`.
|
|
rv.db_paths.emplace_back(db_path, 0 /* target_size */);
|
|
}
|
|
return rv;
|
|
}
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|