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

Fix DeleteAll() on non-existing directory #3974

Merged
merged 2 commits into from
Apr 1, 2021

Conversation

pracucci
Copy link
Contributor

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

We're upgrading Thanos in Cortex and we noticed the compactor logs "failed deleting non-compaction group directories/files, some disk space usage might have leaked". The reason is that, under some conditions, the directory doesn't exist at all. I suggest to consider that case as a non-error.

Verification

N/A

pstibrany
pstibrany previously approved these changes Mar 25, 2021
@GiedriusS
Copy link
Member

There was an identical attempt here: #3869 (comment). Under what circumstances and what directory might not exist when calling this? (:

@pracucci
Copy link
Contributor Author

There was an identical attempt here: #3869 (comment). Under what circumstances and what directory might not exist when calling this? (:

In Cortex the directory passed to Compactor is not pre-created so the first time you run it you would get the error. In other news, DeleteAll() is a generic function and I believe returning no error if the directory doesn't exist looks safer from its side.

@GiedriusS
Copy link
Member

There was an identical attempt here: #3869 (comment). Under what circumstances and what directory might not exist when calling this? (:

In Cortex the directory passed to Compactor is not pre-created so the first time you run it you would get the error. In other news, DeleteAll() is a generic function and I believe returning no error if the directory doesn't exist looks safer from its side.

Playing devil's advocate: what stops from checking whether this directory exists before calling this function there? Tbf I don't mind this change at all, but let's see what @bwplotka thinks.

@pracucci
Copy link
Contributor Author

what stops from checking whether this directory exists before calling this function there?

We can check if the directory exists in the Thanos compactor before calling DeleteAll() but I can't understand why we should do it there instead of fixing it at the root.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks.

This is similar to object storage deletion and the idea to make it idempotent or not. I don't feel idempotency is good in those cases, as you want to know usually why you unnecessary spent cycles, especially if some code will change in the future.

However given we are a library for Cortex, we have to behave better on this.
I would be not opposed to merging this UNLESS #3869 (comment) is not solving your problem, we can port those changes to master anytime (happy to do this today evening).

@bwplotka
Copy link
Member

We merged the leak causing the log line: Wonder if this helps #3978

If not, let's merge this for easy of use

pracucci added 2 commits April 1, 2021 10:28
Signed-off-by: Marco Pracucci <[email protected]>
@pracucci pracucci force-pushed the fix-deleteall-on-non-existing-directory branch from 24da258 to 8c2793a Compare April 1, 2021 08:30
@pracucci
Copy link
Contributor Author

pracucci commented Apr 1, 2021

We merged the leak causing the log line: Wonder if this helps #3978

I just tried. The issue we have is still there.

This is similar to object storage deletion and the idea to make it idempotent or not. I don't feel idempotency is good in those cases, as you want to know usually why you unnecessary spent cycles, especially if some code will change in the future.

I see DeleteAll() similar to os.RemoveAll(), with the additional support for ignoreDirs. os.RemoveAll() is idempotent (returns no error if the provided dir doesn't exist), reason why I thought making DeleteAll() idempotent was not a terrible idea.

That being said, we need to move on in Cortex, so I would appreciate if we take a final decision here. I'm OK if this PR gets rejected (I will do a workaround in Cortex), but a decision is better than no decision 😉

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

You convinced me with std lib example (:

LGTM!

@bwplotka bwplotka merged commit d7dff0c into main Apr 1, 2021
@pracucci pracucci deleted the fix-deleteall-on-non-existing-directory branch April 1, 2021 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants