Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a thread in DeleteScheduler only when rate limit enabled (#6564) #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions file/delete_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ DeleteScheduler::DeleteScheduler(Env* env, int64_t rate_bytes_per_sec,
bytes_max_delete_chunk_(bytes_max_delete_chunk),
closing_(false),
cv_(&mu_),
bg_thread_(nullptr),
info_log_(info_log),
sst_file_manager_(sst_file_manager),
max_trash_db_ratio_(max_trash_db_ratio) {
assert(sst_file_manager != nullptr);
assert(max_trash_db_ratio >= 0);
bg_thread_.reset(
new port::Thread(&DeleteScheduler::BackgroundEmptyTrash, this));
MaybeCreateBackgroundThread();
}

DeleteScheduler::~DeleteScheduler() {
Expand Down Expand Up @@ -349,6 +349,13 @@ void DeleteScheduler::WaitForEmptyTrash() {
}
}

void DeleteScheduler::MaybeCreateBackgroundThread() {
if(bg_thread_ == nullptr && rate_bytes_per_sec_.load() > 0) {
bg_thread_.reset(
new port::Thread(&DeleteScheduler::BackgroundEmptyTrash, this));
}
}

} // namespace rocksdb

#endif // ROCKSDB_LITE
3 changes: 3 additions & 0 deletions file/delete_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DeleteScheduler {
// Set delete rate limit in bytes per second
void SetRateBytesPerSecond(int64_t bytes_per_sec) {
rate_bytes_per_sec_.store(bytes_per_sec);
MaybeCreateBackgroundThread();
}

// Mark file as trash directory and schedule it's deletion. If force_bg is
Expand Down Expand Up @@ -90,6 +91,8 @@ class DeleteScheduler {

void BackgroundEmptyTrash();

void MaybeCreateBackgroundThread();

Env* env_;
// total size of trash files
std::atomic<uint64_t> total_trash_size_;
Expand Down