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

Skip deleting files that we just deleted #2185

Merged
merged 7 commits into from
Mar 2, 2020
Merged
Changes from 6 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
15 changes: 11 additions & 4 deletions pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Delete the bucket, but skip the metaFile, if found. As we just deleted that.
// Delete the bucket, but skip the metaFile as we just deleted that. This is required for eventual object storages (list after write).

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// deleteDirRec removes all objects prefixed with dir from the bucket. It skips objects that return true for the passed keep func
// deleteDirRec removes all objects prefixed with dir from the bucket. It skips objects that return true for the passed keep function.

// 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())
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down