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

cloud_storage: cleanup empty directories on startup #6533

Merged
merged 8 commits into from
Oct 4, 2022

Conversation

jcsp
Copy link
Contributor

@jcsp jcsp commented Sep 26, 2022

Cover letter

This is to cover us against upgraded systems from earlier versions that didn't properly remove empty directories, and also to cover the case where redpanda stops in between removing a file and checking for an empty directory to delete.

Backport Required

  • not a bug fix
  • issue does not exist in previous branches
  • papercut/not impactful enough to backport
  • v22.2.x
  • v22.1.x
  • v21.11.x

UX changes

None

Release notes

Improvements

  • Redpanda now cleans up empty directories in the tiered storage cache directory on startup, as well as after removing segments.

@jcsp jcsp force-pushed the cloud-storage-cleanup-empty branch from b07a874 to 3f02d5f Compare September 26, 2022 20:20
@jcsp jcsp marked this pull request as ready for review September 27, 2022 10:09
@jcsp
Copy link
Contributor Author

jcsp commented Sep 27, 2022

This passed tests here:
https://buildkite.com/redpanda/redpanda/builds/15765#01837b75-942d-4432-bd95-b20c58205ff2

(the release-clang-amd64 github step looks hung because the job name changed in buildkite)


auto entry_path = std::filesystem::path(target)
/ std::filesystem::path(entry.name);
files_in_dir++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think files_in_dir could just be a bool, and toggled with if unlikely(!files_in_dir), although admittedly the memory and cpu savings would be tiny.

Copy link
Contributor

@VladLazar VladLazar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine to me, but I'm not familiar with how the system reacts to these things being removed, so I'll defer approval to someone who does. :)

Comment on lines 29 to 32
struct walk_result {
uint64_t cache_size{0};
std::vector<file_list_item> deletion_candidates;
std::vector<ss::sstring> empty_dirs;
Copy link
Contributor

@VladLazar VladLazar Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I was a bit confused by the naming initially as empty_dirs are also "candidates for deletion", but I guess the file_list_item type indicates the fact that deletion_candidates are files, which justifies the different treatment.

Comment on lines 29 to 33
struct walk_result {
uint64_t cache_size{0};
std::vector<file_list_item> deletion_candidates;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

src/v/cloud_storage/recursive_directory_walker.cc Outdated Show resolved Hide resolved
@mmedenjak mmedenjak added kind/enhance New feature or request area/cloud-storage Shadow indexing subsystem labels Sep 28, 2022
@mmedenjak
Copy link
Contributor

Related to this follow-up - https://github.com/redpanda-data/core-internal/issues/114

@mmedenjak
Copy link
Contributor

Also, maybe slightly related to this one - https://github.com/redpanda-data/core-internal/issues/111

@mmedenjak
Copy link
Contributor

Structs with named members are preferred to pairs.
...including the new empty dir deletion.
No need to actually count files, when we are only
interested in whether a directory is empty.
The "candidates for deletion" are only such if the
caller uses them that way.  From the point of view of
the walker, it's just a list of all regular files.
Walking a tree doesn't imply sorting by atime: that sort
belongs in the LRU cache trimming function.
@jcsp jcsp force-pushed the cloud-storage-cleanup-empty branch from 976a6d4 to 8ab8bf1 Compare October 3, 2022 11:58
This is a defensive measure.

Use of a bare lambda is currently safe because of how list_directory
is implemented: the lambda gets moved into a stream object internally,
which keeps the lambda and its captures alive as long as it will
be used.

However, we generally avoid passing reference captures into lambdas
without some mitigation, and it isn't strictly guaranteed that this
directory listing function will behave this way, so we add a
ss::coroutine::lambda wrapper to make it more obviously correct.
@jcsp jcsp force-pushed the cloud-storage-cleanup-empty branch from 8ab8bf1 to 68c16ee Compare October 3, 2022 12:06
@jcsp
Copy link
Contributor Author

jcsp commented Oct 3, 2022

Added a commit to make the coroutine lambda in walk() a bit more obviously correct.

There are also commits to address style notes from the earlier version, taking the opportunity to clean this up a bit while touching it.

@jcsp jcsp requested review from abhijat and dotnwat October 3, 2022 12:09
Comment on lines +35 to +36
std::set<std::string> result_paths(cloud_storage::walk_result& r) {
std::set<std::string> paths;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this be unordered_set ?

Copy link
Contributor

@abhijat abhijat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jcsp jcsp merged commit 1e9b757 into redpanda-data:dev Oct 4, 2022
@jcsp jcsp deleted the cloud-storage-cleanup-empty branch October 4, 2022 10:23
@jcsp
Copy link
Contributor Author

jcsp commented Oct 4, 2022

/backport v22.2.x

@jcsp
Copy link
Contributor Author

jcsp commented Oct 4, 2022

On reflection this seems worth backporting so that we have a simple option for systems in the field pre-22.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cloud-storage Shadow indexing subsystem area/redpanda kind/enhance New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants