-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Skip deleting files that we just deleted #2185
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
233a6c9
Skip deleting files that we just deleted
hsmade 76b3947
return, as this is a func. Add debug log and comment
hsmade a493eb8
fixing build: wrong parameter name
hsmade f3d25fd
fix lint
hsmade bda73cd
Refactor deleteDir into deleteDirRec and add a parameter for a functi…
hsmade 5c786ec
Fix lint
hsmade e4f43a9
implementing suggested fixes
hsmade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -145,16 +145,23 @@ func Delete(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid | |||||
level.Debug(logger).Log("msg", "deleted file", "file", metaFile, "bucket", bkt.Name()) | ||||||
} | ||||||
|
||||||
return deleteDir(ctx, logger, bkt, id.String()) | ||||||
// Delete the bucket, but skip the metaFile, if found. As we just deleted that. | ||||||
return deleteDirRec(ctx, logger, bkt, id.String(), func(name string) bool { | ||||||
return name == metaFile | ||||||
}) | ||||||
} | ||||||
|
||||||
// deleteDir removes all objects prefixed with dir from the bucket. | ||||||
// deleteDirRec removes all objects prefixed with dir from the bucket. It skips objects that return true for the passed keep func | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// NOTE: For objects removal use `block.Delete` strictly. | ||||||
func deleteDir(ctx context.Context, logger log.Logger, bkt objstore.Bucket, dir string) error { | ||||||
func deleteDirRec(ctx context.Context, logger log.Logger, bkt objstore.Bucket, dir string, keep func(name string) bool) error { | ||||||
return bkt.Iter(ctx, dir, func(name string) error { | ||||||
// If we hit a directory, call DeleteDir recursively. | ||||||
if strings.HasSuffix(name, objstore.DirDelim) { | ||||||
return deleteDir(ctx, logger, bkt, name) | ||||||
return deleteDirRec(ctx, logger, bkt, name, keep) | ||||||
} | ||||||
if keep(name) { | ||||||
level.Debug(logger).Log("msg", "skipping deletion of object, as requested by keep()", "file", name, "bucket", bkt.Name()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works as intended so I would prefer no log line even. |
||||||
return nil | ||||||
} | ||||||
if err := bkt.Delete(ctx, name); err != nil { | ||||||
return err | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.