2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2015-08-05 05:45:27 +02:00
|
|
|
|
2016-12-22 02:35:00 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2019-05-30 05:44:08 +02:00
|
|
|
#include "file/delete_scheduler.h"
|
2015-08-20 00:02:17 +02:00
|
|
|
|
2020-06-05 18:41:03 +02:00
|
|
|
#include <cinttypes>
|
2015-08-05 05:45:27 +02:00
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-05-30 05:44:08 +02:00
|
|
|
#include "file/sst_file_manager_impl.h"
|
2019-06-01 02:19:43 +02:00
|
|
|
#include "logging/logging.h"
|
2015-08-05 05:45:27 +02:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/env.h"
|
2021-01-26 07:07:26 +01:00
|
|
|
#include "rocksdb/file_system.h"
|
|
|
|
#include "rocksdb/system_clock.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "test_util/sync_point.h"
|
2015-08-05 05:45:27 +02:00
|
|
|
#include "util/mutexlock.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-08-05 05:45:27 +02:00
|
|
|
|
2021-03-15 12:32:24 +01:00
|
|
|
DeleteScheduler::DeleteScheduler(SystemClock* clock, FileSystem* fs,
|
|
|
|
int64_t rate_bytes_per_sec, Logger* info_log,
|
2017-11-17 20:56:41 +01:00
|
|
|
SstFileManagerImpl* sst_file_manager,
|
2018-03-22 23:42:44 +01:00
|
|
|
double max_trash_db_ratio,
|
|
|
|
uint64_t bytes_max_delete_chunk)
|
2021-01-26 07:07:26 +01:00
|
|
|
: clock_(clock),
|
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
2019-12-13 23:47:08 +01:00
|
|
|
fs_(fs),
|
2017-06-13 01:51:37 +02:00
|
|
|
total_trash_size_(0),
|
2015-08-05 05:45:27 +02:00
|
|
|
rate_bytes_per_sec_(rate_bytes_per_sec),
|
|
|
|
pending_files_(0),
|
2018-03-22 23:42:44 +01:00
|
|
|
bytes_max_delete_chunk_(bytes_max_delete_chunk),
|
2015-08-05 05:45:27 +02:00
|
|
|
closing_(false),
|
|
|
|
cv_(&mu_),
|
2020-03-24 19:24:53 +01:00
|
|
|
bg_thread_(nullptr),
|
2016-01-29 03:35:01 +01:00
|
|
|
info_log_(info_log),
|
2017-11-17 20:56:41 +01:00
|
|
|
sst_file_manager_(sst_file_manager),
|
|
|
|
max_trash_db_ratio_(max_trash_db_ratio) {
|
2017-06-13 01:51:37 +02:00
|
|
|
assert(sst_file_manager != nullptr);
|
2017-11-17 20:56:41 +01:00
|
|
|
assert(max_trash_db_ratio >= 0);
|
2020-03-24 19:24:53 +01:00
|
|
|
MaybeCreateBackgroundThread();
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
2016-01-29 03:35:01 +01:00
|
|
|
DeleteScheduler::~DeleteScheduler() {
|
2015-08-05 05:45:27 +02:00
|
|
|
{
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2015-08-05 05:45:27 +02:00
|
|
|
closing_ = true;
|
|
|
|
cv_.SignalAll();
|
|
|
|
}
|
|
|
|
if (bg_thread_) {
|
|
|
|
bg_thread_->join();
|
|
|
|
}
|
2021-01-08 00:21:51 +01:00
|
|
|
for (const auto& it : bg_errors_) {
|
|
|
|
it.second.PermitUncheckedError();
|
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 22:51:39 +02:00
|
|
|
Status DeleteScheduler::DeleteFile(const std::string& file_path,
|
2019-01-29 23:27:30 +01:00
|
|
|
const std::string& dir_to_sync,
|
|
|
|
const bool force_bg) {
|
|
|
|
if (rate_bytes_per_sec_.load() <= 0 || (!force_bg &&
|
2017-06-13 01:51:37 +02:00
|
|
|
total_trash_size_.load() >
|
2019-01-29 23:27:30 +01:00
|
|
|
sst_file_manager_->GetTotalSize() * max_trash_db_ratio_.load())) {
|
2017-06-13 01:51:37 +02:00
|
|
|
// Rate limiting is disabled or trash size makes up more than
|
|
|
|
// max_trash_db_ratio_ (default 25%) of the total DB size
|
2017-03-16 20:06:04 +01:00
|
|
|
TEST_SYNC_POINT("DeleteScheduler::DeleteFile");
|
2020-12-23 08:44:44 +01:00
|
|
|
Status s = fs_->DeleteFile(file_path, IOOptions(), nullptr);
|
2017-06-13 01:51:37 +02:00
|
|
|
if (s.ok()) {
|
2020-08-21 04:16:56 +02:00
|
|
|
s = sst_file_manager_->OnDeleteFile(file_path);
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_,
|
|
|
|
"Deleted file %s immediately, rate_bytes_per_sec %" PRIi64
|
|
|
|
", total_trash_size %" PRIu64 " max_trash_db_ratio %lf",
|
|
|
|
file_path.c_str(), rate_bytes_per_sec_.load(),
|
|
|
|
total_trash_size_.load(), max_trash_db_ratio_.load());
|
2020-06-27 00:33:51 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2020-06-05 18:41:03 +02:00
|
|
|
RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY);
|
2016-01-29 03:35:01 +01:00
|
|
|
}
|
|
|
|
return s;
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move file to trash
|
2017-10-27 22:25:54 +02:00
|
|
|
std::string trash_file;
|
2020-12-23 08:44:44 +01:00
|
|
|
Status s = MarkAsTrash(file_path, &trash_file);
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_, "Mark file: %s as trash -- %s", trash_file.c_str(),
|
|
|
|
s.ToString().c_str());
|
2017-10-27 22:25:54 +02:00
|
|
|
|
2015-08-05 05:45:27 +02:00
|
|
|
if (!s.ok()) {
|
2019-12-18 05:07:21 +01:00
|
|
|
ROCKS_LOG_ERROR(info_log_, "Failed to mark %s as trash -- %s",
|
|
|
|
file_path.c_str(), s.ToString().c_str());
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = fs_->DeleteFile(file_path, IOOptions(), nullptr);
|
2017-06-13 01:51:37 +02:00
|
|
|
if (s.ok()) {
|
2020-08-21 04:16:56 +02:00
|
|
|
s = sst_file_manager_->OnDeleteFile(file_path);
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_, "Deleted file %s immediately",
|
|
|
|
trash_file.c_str());
|
2020-06-27 00:33:51 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2020-06-05 18:41:03 +02:00
|
|
|
RecordTick(stats_.get(), FILES_DELETED_IMMEDIATELY);
|
2016-01-29 03:35:01 +01:00
|
|
|
}
|
|
|
|
return s;
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:25:54 +02:00
|
|
|
// Update the total trash size
|
|
|
|
uint64_t trash_file_size = 0;
|
2021-01-06 23:14:01 +01:00
|
|
|
IOStatus io_s =
|
2020-12-23 08:44:44 +01:00
|
|
|
fs_->GetFileSize(trash_file, IOOptions(), &trash_file_size, nullptr);
|
2021-01-06 23:14:01 +01:00
|
|
|
if (io_s.ok()) {
|
|
|
|
total_trash_size_.fetch_add(trash_file_size);
|
|
|
|
}
|
|
|
|
//**TODO: What should we do if we failed to
|
|
|
|
// get the file size?
|
2017-10-27 22:25:54 +02:00
|
|
|
|
2015-08-05 05:45:27 +02:00
|
|
|
// Add file to delete queue
|
|
|
|
{
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2020-06-27 00:33:51 +02:00
|
|
|
RecordTick(stats_.get(), FILES_MARKED_TRASH);
|
2018-04-26 22:51:39 +02:00
|
|
|
queue_.emplace(trash_file, dir_to_sync);
|
2015-08-05 05:45:27 +02:00
|
|
|
pending_files_++;
|
|
|
|
if (pending_files_ == 1) {
|
|
|
|
cv_.SignalAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-01-29 03:35:01 +01:00
|
|
|
std::map<std::string, Status> DeleteScheduler::GetBackgroundErrors() {
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2015-08-05 05:45:27 +02:00
|
|
|
return bg_errors_;
|
|
|
|
}
|
|
|
|
|
2017-10-27 22:25:54 +02:00
|
|
|
const std::string DeleteScheduler::kTrashExtension = ".trash";
|
|
|
|
bool DeleteScheduler::IsTrashFile(const std::string& file_path) {
|
|
|
|
return (file_path.size() >= kTrashExtension.size() &&
|
|
|
|
file_path.rfind(kTrashExtension) ==
|
|
|
|
file_path.size() - kTrashExtension.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DeleteScheduler::CleanupDirectory(Env* env, SstFileManagerImpl* sfm,
|
|
|
|
const std::string& path) {
|
2015-08-05 05:45:27 +02:00
|
|
|
Status s;
|
2017-10-27 22:25:54 +02:00
|
|
|
// Check if there are any files marked as trash in this path
|
|
|
|
std::vector<std::string> files_in_path;
|
|
|
|
s = env->GetChildren(path, &files_in_path);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
for (const std::string& current_file : files_in_path) {
|
|
|
|
if (!DeleteScheduler::IsTrashFile(current_file)) {
|
|
|
|
// not a trash file, skip
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status file_delete;
|
|
|
|
std::string trash_file = path + "/" + current_file;
|
|
|
|
if (sfm) {
|
|
|
|
// We have an SstFileManager that will schedule the file delete
|
2020-08-21 04:16:56 +02:00
|
|
|
s = sfm->OnAddFile(trash_file);
|
2018-04-26 22:51:39 +02:00
|
|
|
file_delete = sfm->ScheduleFileDeletion(trash_file, path);
|
2017-10-27 22:25:54 +02:00
|
|
|
} else {
|
|
|
|
// Delete the file immediately
|
|
|
|
file_delete = env->DeleteFile(trash_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok() && !file_delete.ok()) {
|
|
|
|
s = file_delete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DeleteScheduler::MarkAsTrash(const std::string& file_path,
|
|
|
|
std::string* trash_file) {
|
|
|
|
// Sanity check of the path
|
2015-08-05 05:45:27 +02:00
|
|
|
size_t idx = file_path.rfind("/");
|
|
|
|
if (idx == std::string::npos || idx == file_path.size() - 1) {
|
|
|
|
return Status::InvalidArgument("file_path is corrupted");
|
|
|
|
}
|
|
|
|
|
2017-10-27 22:25:54 +02:00
|
|
|
if (DeleteScheduler::IsTrashFile(file_path)) {
|
|
|
|
// This is already a trash file
|
2017-12-13 03:15:15 +01:00
|
|
|
*trash_file = file_path;
|
2020-12-23 08:44:44 +01:00
|
|
|
return Status::OK();
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:25:54 +02:00
|
|
|
*trash_file = file_path + kTrashExtension;
|
2015-08-05 05:45:27 +02:00
|
|
|
// TODO(tec) : Implement Env::RenameFileIfNotExist and remove
|
|
|
|
// file_move_mu mutex.
|
2017-10-27 22:25:54 +02:00
|
|
|
int cnt = 0;
|
2020-12-23 08:44:44 +01:00
|
|
|
Status s;
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&file_move_mu_);
|
2015-08-05 05:45:27 +02:00
|
|
|
while (true) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = fs_->FileExists(*trash_file, IOOptions(), nullptr);
|
2015-08-05 05:45:27 +02:00
|
|
|
if (s.IsNotFound()) {
|
|
|
|
// We found a path for our file in trash
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = fs_->RenameFile(file_path, *trash_file, IOOptions(), nullptr);
|
2015-08-05 05:45:27 +02:00
|
|
|
break;
|
|
|
|
} else if (s.ok()) {
|
|
|
|
// Name conflict, generate new random suffix
|
2017-10-27 22:25:54 +02:00
|
|
|
*trash_file = file_path + std::to_string(cnt) + kTrashExtension;
|
2015-08-05 05:45:27 +02:00
|
|
|
} else {
|
|
|
|
// Error during FileExists call, we cannot continue
|
|
|
|
break;
|
|
|
|
}
|
2017-10-27 22:25:54 +02:00
|
|
|
cnt++;
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
2017-06-13 01:51:37 +02:00
|
|
|
if (s.ok()) {
|
2021-01-06 23:14:01 +01:00
|
|
|
s = sst_file_manager_->OnMoveFile(file_path, *trash_file);
|
2016-01-29 03:35:01 +01:00
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-01-29 03:35:01 +01:00
|
|
|
void DeleteScheduler::BackgroundEmptyTrash() {
|
|
|
|
TEST_SYNC_POINT("DeleteScheduler::BackgroundEmptyTrash");
|
2015-08-05 05:45:27 +02:00
|
|
|
|
|
|
|
while (true) {
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2015-08-05 05:45:27 +02:00
|
|
|
while (queue_.empty() && !closing_) {
|
|
|
|
cv_.Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closing_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all files in queue_
|
2021-01-26 07:07:26 +01:00
|
|
|
uint64_t start_time = clock_->NowMicros();
|
2015-08-05 05:45:27 +02:00
|
|
|
uint64_t total_deleted_bytes = 0;
|
2017-03-16 20:06:04 +01:00
|
|
|
int64_t current_delete_rate = rate_bytes_per_sec_.load();
|
2015-08-05 05:45:27 +02:00
|
|
|
while (!queue_.empty() && !closing_) {
|
2017-03-16 20:06:04 +01:00
|
|
|
if (current_delete_rate != rate_bytes_per_sec_.load()) {
|
|
|
|
// User changed the delete rate
|
|
|
|
current_delete_rate = rate_bytes_per_sec_.load();
|
2021-01-26 07:07:26 +01:00
|
|
|
start_time = clock_->NowMicros();
|
2017-03-16 20:06:04 +01:00
|
|
|
total_deleted_bytes = 0;
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_, "rate_bytes_per_sec is changed to %" PRIi64,
|
|
|
|
current_delete_rate);
|
2017-03-16 20:06:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get new file to delete
|
2018-04-26 22:51:39 +02:00
|
|
|
const FileAndDir& fad = queue_.front();
|
|
|
|
std::string path_in_trash = fad.fname;
|
2015-08-05 05:45:27 +02:00
|
|
|
|
2020-02-28 23:10:51 +01:00
|
|
|
// We don't need to hold the lock while deleting the file
|
2015-08-05 05:45:27 +02:00
|
|
|
mu_.Unlock();
|
|
|
|
uint64_t deleted_bytes = 0;
|
2018-03-22 23:42:44 +01:00
|
|
|
bool is_complete = true;
|
2015-08-05 05:45:27 +02:00
|
|
|
// Delete file from trash and update total_penlty value
|
2018-04-26 22:51:39 +02:00
|
|
|
Status s =
|
|
|
|
DeleteTrashFile(path_in_trash, fad.dir, &deleted_bytes, &is_complete);
|
2015-08-05 05:45:27 +02:00
|
|
|
total_deleted_bytes += deleted_bytes;
|
|
|
|
mu_.Lock();
|
2018-03-22 23:42:44 +01:00
|
|
|
if (is_complete) {
|
|
|
|
queue_.pop();
|
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
bg_errors_[path_in_trash] = s;
|
|
|
|
}
|
|
|
|
|
2020-06-05 18:41:03 +02:00
|
|
|
// Apply penalty if necessary
|
|
|
|
uint64_t total_penalty;
|
2017-03-16 20:06:04 +01:00
|
|
|
if (current_delete_rate > 0) {
|
|
|
|
// rate limiting is enabled
|
2020-06-05 18:41:03 +02:00
|
|
|
total_penalty =
|
2017-03-16 20:06:04 +01:00
|
|
|
((total_deleted_bytes * kMicrosInSecond) / current_delete_rate);
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_,
|
|
|
|
"Rate limiting is enabled with penalty %" PRIu64
|
2020-08-20 10:58:54 +02:00
|
|
|
" after deleting file %s",
|
2020-06-05 18:41:03 +02:00
|
|
|
total_penalty, path_in_trash.c_str());
|
|
|
|
while (!closing_ && !cv_.TimedWait(start_time + total_penalty)) {
|
|
|
|
}
|
2017-03-16 20:06:04 +01:00
|
|
|
} else {
|
|
|
|
// rate limiting is disabled
|
2020-06-05 18:41:03 +02:00
|
|
|
total_penalty = 0;
|
|
|
|
ROCKS_LOG_INFO(info_log_,
|
|
|
|
"Rate limiting is disabled after deleting file %s",
|
|
|
|
path_in_trash.c_str());
|
2017-03-16 20:06:04 +01:00
|
|
|
}
|
2016-01-29 03:35:01 +01:00
|
|
|
TEST_SYNC_POINT_CALLBACK("DeleteScheduler::BackgroundEmptyTrash:Wait",
|
2020-06-05 18:41:03 +02:00
|
|
|
&total_penalty);
|
2015-08-05 05:45:27 +02:00
|
|
|
|
2018-03-22 23:42:44 +01:00
|
|
|
if (is_complete) {
|
|
|
|
pending_files_--;
|
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
if (pending_files_ == 0) {
|
2015-08-20 00:02:17 +02:00
|
|
|
// Unblock WaitForEmptyTrash since there are no more files waiting
|
2015-08-05 05:45:27 +02:00
|
|
|
// to be deleted
|
|
|
|
cv_.SignalAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 03:35:01 +01:00
|
|
|
Status DeleteScheduler::DeleteTrashFile(const std::string& path_in_trash,
|
2018-04-26 22:51:39 +02:00
|
|
|
const std::string& dir_to_sync,
|
2018-03-22 23:42:44 +01:00
|
|
|
uint64_t* deleted_bytes,
|
|
|
|
bool* is_complete) {
|
2015-08-05 05:45:27 +02:00
|
|
|
uint64_t file_size;
|
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
2019-12-13 23:47:08 +01:00
|
|
|
Status s = fs_->GetFileSize(path_in_trash, IOOptions(), &file_size, nullptr);
|
2018-03-22 23:42:44 +01:00
|
|
|
*is_complete = true;
|
|
|
|
TEST_SYNC_POINT("DeleteScheduler::DeleteTrashFile:DeleteFile");
|
2015-08-05 05:45:27 +02:00
|
|
|
if (s.ok()) {
|
2018-03-22 23:42:44 +01:00
|
|
|
bool need_full_delete = true;
|
|
|
|
if (bytes_max_delete_chunk_ != 0 && file_size > bytes_max_delete_chunk_) {
|
2018-07-10 00:17:38 +02:00
|
|
|
uint64_t num_hard_links = 2;
|
|
|
|
// We don't have to worry aobut data race between linking a new
|
|
|
|
// 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.
|
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
2019-12-13 23:47:08 +01:00
|
|
|
Status my_status = fs_->NumFileLinks(path_in_trash, IOOptions(),
|
|
|
|
&num_hard_links, nullptr);
|
2018-03-22 23:42:44 +01:00
|
|
|
if (my_status.ok()) {
|
2018-07-10 00:17:38 +02:00
|
|
|
if (num_hard_links == 1) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
std::unique_ptr<FSWritableFile> wf;
|
|
|
|
my_status = fs_->ReopenWritableFile(path_in_trash, FileOptions(),
|
|
|
|
&wf, nullptr);
|
2018-07-10 00:17:38 +02:00
|
|
|
if (my_status.ok()) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
my_status = wf->Truncate(file_size - bytes_max_delete_chunk_,
|
|
|
|
IOOptions(), nullptr);
|
2018-07-10 00:17:38 +02:00
|
|
|
if (my_status.ok()) {
|
|
|
|
TEST_SYNC_POINT("DeleteScheduler::DeleteTrashFile:Fsync");
|
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
2019-12-13 23:47:08 +01:00
|
|
|
my_status = wf->Fsync(IOOptions(), nullptr);
|
2018-07-10 00:17:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (my_status.ok()) {
|
|
|
|
*deleted_bytes = bytes_max_delete_chunk_;
|
|
|
|
need_full_delete = false;
|
|
|
|
*is_complete = false;
|
|
|
|
} else {
|
|
|
|
ROCKS_LOG_WARN(info_log_,
|
|
|
|
"Failed to partially delete %s from trash -- %s",
|
|
|
|
path_in_trash.c_str(), my_status.ToString().c_str());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ROCKS_LOG_INFO(info_log_,
|
|
|
|
"Cannot delete %s slowly through ftruncate from trash "
|
|
|
|
"as it has other links",
|
|
|
|
path_in_trash.c_str());
|
2018-03-22 23:42:44 +01:00
|
|
|
}
|
2018-07-10 00:17:38 +02:00
|
|
|
} else if (!num_link_error_printed_) {
|
|
|
|
ROCKS_LOG_INFO(
|
|
|
|
info_log_,
|
|
|
|
"Cannot delete files slowly through ftruncate from trash "
|
|
|
|
"as Env::NumFileLinks() returns error: %s",
|
|
|
|
my_status.ToString().c_str());
|
|
|
|
num_link_error_printed_ = true;
|
2018-03-22 23:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
|
2018-03-22 23:42:44 +01:00
|
|
|
if (need_full_delete) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = fs_->DeleteFile(path_in_trash, IOOptions(), nullptr);
|
2018-04-26 22:51:39 +02:00
|
|
|
if (!dir_to_sync.empty()) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
std::unique_ptr<FSDirectory> dir_obj;
|
2018-04-26 22:51:39 +02:00
|
|
|
if (s.ok()) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = fs_->NewDirectory(dir_to_sync, IOOptions(), &dir_obj, nullptr);
|
2018-04-26 22:51:39 +02:00
|
|
|
}
|
|
|
|
if (s.ok()) {
|
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
2019-12-13 23:47:08 +01:00
|
|
|
s = dir_obj->Fsync(IOOptions(), nullptr);
|
2018-04-26 22:51:39 +02:00
|
|
|
TEST_SYNC_POINT_CALLBACK(
|
|
|
|
"DeleteScheduler::DeleteTrashFile::AfterSyncDir",
|
|
|
|
reinterpret_cast<void*>(const_cast<std::string*>(&dir_to_sync)));
|
|
|
|
}
|
|
|
|
}
|
2020-08-21 04:16:56 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
*deleted_bytes = file_size;
|
|
|
|
s = sst_file_manager_->OnDeleteFile(path_in_trash);
|
|
|
|
}
|
2018-03-22 23:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
2015-08-05 05:45:27 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
// Error while getting file size or while deleting
|
2017-03-16 03:22:52 +01:00
|
|
|
ROCKS_LOG_ERROR(info_log_, "Failed to delete %s from trash -- %s",
|
|
|
|
path_in_trash.c_str(), s.ToString().c_str());
|
2015-08-05 05:45:27 +02:00
|
|
|
*deleted_bytes = 0;
|
|
|
|
} else {
|
2018-03-22 23:42:44 +01:00
|
|
|
total_trash_size_.fetch_sub(*deleted_bytes);
|
2015-08-05 05:45:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-01-29 03:35:01 +01:00
|
|
|
void DeleteScheduler::WaitForEmptyTrash() {
|
2016-10-18 07:22:48 +02:00
|
|
|
InstrumentedMutexLock l(&mu_);
|
2015-08-05 05:45:27 +02:00
|
|
|
while (pending_files_ > 0 && !closing_) {
|
|
|
|
cv_.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 19:24:53 +01:00
|
|
|
void DeleteScheduler::MaybeCreateBackgroundThread() {
|
2020-06-05 18:41:03 +02:00
|
|
|
if (bg_thread_ == nullptr && rate_bytes_per_sec_.load() > 0) {
|
2020-03-24 19:24:53 +01:00
|
|
|
bg_thread_.reset(
|
|
|
|
new port::Thread(&DeleteScheduler::BackgroundEmptyTrash, this));
|
2020-06-05 18:41:03 +02:00
|
|
|
ROCKS_LOG_INFO(info_log_,
|
|
|
|
"Created background thread for deletion scheduler with "
|
|
|
|
"rate_bytes_per_sec: %" PRIi64,
|
|
|
|
rate_bytes_per_sec_.load());
|
2020-03-24 19:24:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2016-12-22 02:35:00 +01:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|