summaryrefslogtreecommitdiff
path: root/file/delete_scheduler.cc
diff options
context:
space:
mode:
authoranand76 <anand76@devvm1373.frc2.facebook.com>2019-12-13 14:47:08 -0800
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>2019-12-13 14:48:41 -0800
commitafa2420c2bf0304a4b8796cab219e859146cc031 (patch)
treefd2aee1b4ec5c3ac91ee5137b94992218b071ea5 /file/delete_scheduler.cc
parent58d46d19158c95a4f05e3609579e65e9181b19cb (diff)
Introduce a new storage specific Env API (#5761)
Summary: The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc. This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO. The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before. This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection. The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761 Differential Revision: D18868376 Pulled By: anand1976 fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
Diffstat (limited to 'file/delete_scheduler.cc')
-rw-r--r--file/delete_scheduler.cc39
1 files changed, 21 insertions, 18 deletions
diff --git a/file/delete_scheduler.cc b/file/delete_scheduler.cc
index b66956ca0..d528d6713 100644
--- a/file/delete_scheduler.cc
+++ b/file/delete_scheduler.cc
@@ -19,12 +19,13 @@
namespace rocksdb {
-DeleteScheduler::DeleteScheduler(Env* env, int64_t rate_bytes_per_sec,
- Logger* info_log,
+DeleteScheduler::DeleteScheduler(Env* env, FileSystem* fs,
+ int64_t rate_bytes_per_sec, Logger* info_log,
SstFileManagerImpl* sst_file_manager,
double max_trash_db_ratio,
uint64_t bytes_max_delete_chunk)
: env_(env),
+ fs_(fs),
total_trash_size_(0),
rate_bytes_per_sec_(rate_bytes_per_sec),
pending_files_(0),
@@ -61,7 +62,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
// Rate limiting is disabled or trash size makes up more than
// max_trash_db_ratio_ (default 25%) of the total DB size
TEST_SYNC_POINT("DeleteScheduler::DeleteFile");
- s = env_->DeleteFile(file_path);
+ s = fs_->DeleteFile(file_path, IOOptions(), nullptr);
if (s.ok()) {
sst_file_manager_->OnDeleteFile(file_path);
}
@@ -74,7 +75,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
if (!s.ok()) {
ROCKS_LOG_ERROR(info_log_, "Failed to mark %s as trash", file_path.c_str());
- s = env_->DeleteFile(file_path);
+ s = fs_->DeleteFile(file_path, IOOptions(), nullptr);
if (s.ok()) {
sst_file_manager_->OnDeleteFile(file_path);
}
@@ -83,7 +84,7 @@ Status DeleteScheduler::DeleteFile(const std::string& file_path,
// Update the total trash size
uint64_t trash_file_size = 0;
- env_->GetFileSize(trash_file, &trash_file_size);
+ fs_->GetFileSize(trash_file, IOOptions(), &trash_file_size, nullptr);
total_trash_size_.fetch_add(trash_file_size);
// Add file to delete queue
@@ -165,10 +166,10 @@ Status DeleteScheduler::MarkAsTrash(const std::string& file_path,
int cnt = 0;
InstrumentedMutexLock l(&file_move_mu_);
while (true) {
- s = env_->FileExists(*trash_file);
+ s = fs_->FileExists(*trash_file, IOOptions(), nullptr);
if (s.IsNotFound()) {
// We found a path for our file in trash
- s = env_->RenameFile(file_path, *trash_file);
+ s = fs_->RenameFile(file_path, *trash_file, IOOptions(), nullptr);
break;
} else if (s.ok()) {
// Name conflict, generate new random suffix
@@ -262,7 +263,7 @@ Status DeleteScheduler::DeleteTrashFile(const std::string& path_in_trash,
uint64_t* deleted_bytes,
bool* is_complete) {
uint64_t file_size;
- Status s = env_->GetFileSize(path_in_trash, &file_size);
+ Status s = fs_->GetFileSize(path_in_trash, IOOptions(), &file_size, nullptr);
*is_complete = true;
TEST_SYNC_POINT("DeleteScheduler::DeleteTrashFile:DeleteFile");
if (s.ok()) {
@@ -273,17 +274,19 @@ Status DeleteScheduler::DeleteTrashFile(const std::string& path_in_trash,
// file after the number of file link check and ftruncte because
// the file is now in trash and no hardlink is supposed to create
// to trash files by RocksDB.
- Status my_status = env_->NumFileLinks(path_in_trash, &num_hard_links);
+ Status my_status = fs_->NumFileLinks(path_in_trash, IOOptions(),
+ &num_hard_links, nullptr);
if (my_status.ok()) {
if (num_hard_links == 1) {
- std::unique_ptr<WritableFile> wf;
- my_status =
- env_->ReopenWritableFile(path_in_trash, &wf, EnvOptions());
+ std::unique_ptr<FSWritableFile> wf;
+ my_status = fs_->ReopenWritableFile(path_in_trash, FileOptions(),
+ &wf, nullptr);
if (my_status.ok()) {
- my_status = wf->Truncate(file_size - bytes_max_delete_chunk_);
+ my_status = wf->Truncate(file_size - bytes_max_delete_chunk_,
+ IOOptions(), nullptr);
if (my_status.ok()) {
TEST_SYNC_POINT("DeleteScheduler::DeleteTrashFile:Fsync");
- my_status = wf->Fsync();
+ my_status = wf->Fsync(IOOptions(), nullptr);
}
}
if (my_status.ok()) {
@@ -312,14 +315,14 @@ Status DeleteScheduler::DeleteTrashFile(const std::string& path_in_trash,
}
if (need_full_delete) {
- s = env_->DeleteFile(path_in_trash);
+ s = fs_->DeleteFile(path_in_trash, IOOptions(), nullptr);
if (!dir_to_sync.empty()) {
- std::unique_ptr<Directory> dir_obj;
+ std::unique_ptr<FSDirectory> dir_obj;
if (s.ok()) {
- s = env_->NewDirectory(dir_to_sync, &dir_obj);
+ s = fs_->NewDirectory(dir_to_sync, IOOptions(), &dir_obj, nullptr);
}
if (s.ok()) {
- s = dir_obj->Fsync();
+ s = dir_obj->Fsync(IOOptions(), nullptr);
TEST_SYNC_POINT_CALLBACK(
"DeleteScheduler::DeleteTrashFile::AfterSyncDir",
reinterpret_cast<void*>(const_cast<std::string*>(&dir_to_sync)));