Skip to content

Commit

Permalink
IsTrashFile() needs to also check queue_ if rename of file disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvon committed Jul 15, 2024
1 parent b8678c4 commit fd65ce1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 13 additions & 6 deletions file/delete_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ std::map<std::string, Status> DeleteScheduler::GetBackgroundErrors() {
}

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());
bool DeleteScheduler::IsTrashFile(const std::string& file_path, DeleteScheduler* ds) {
if ((file_path.size() >= kTrashExtension.size() &&
file_path.rfind(kTrashExtension) ==
file_path.size() - kTrashExtension.size())) {
return true;
} else if (nullptr != ds) {
InstrumentedMutexLock l(&ds->mu_);
return ds->queue_.find(file_path) != ds->queue_.end();
}

return false;
}

Status DeleteScheduler::CleanupDirectory(Env* env, SstFileManagerImpl* sfm,
Expand All @@ -153,7 +160,7 @@ Status DeleteScheduler::CleanupDirectory(Env* env, SstFileManagerImpl* sfm,
return s;
}
for (const std::string& current_file : files_in_path) {
if (!DeleteScheduler::IsTrashFile(current_file)) {
if (!IsTrashFile(current_file, sfm ? sfm->delete_scheduler() : nullptr)) {
// not a trash file, skip
continue;
}
Expand Down Expand Up @@ -210,7 +217,7 @@ Status DeleteScheduler::MarkAsTrash(const std::string& file_path,
return Status::InvalidArgument("file_path is corrupted");
}

if (DeleteScheduler::IsTrashFile(file_path)) {
if (IsTrashFile(file_path, this)) {
// This is already a trash file
*trash_file = file_path;
return Status::OK();
Expand Down
7 changes: 4 additions & 3 deletions file/delete_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ class DeleteScheduler {
}

static const std::string kTrashExtension;
static bool IsTrashFile(const std::string& file_path);
static bool IsTrashFile(const std::string& file_path, DeleteScheduler* ds = nullptr);

// Check if there are any .trash files in path, and schedule their deletion
// Or delete immediately if sst_file_manager is nullptr
static Status CleanupDirectory(Env* env, SstFileManagerImpl* sfm,
const std::string& path);
Status CleanupDirectory(Env* env, const std::string& path) {
return CleanupDirectory(env, sst_file_manager_, path);}
static Status CleanupDirectory(Env* env, SstFileManagerImpl* sfm, const std::string& path);

void SetStatisticsPtr(const std::shared_ptr<Statistics>& stats) {
InstrumentedMutexLock l(&mu_);
Expand Down

0 comments on commit fd65ce1

Please sign in to comment.