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

Store Fix: Removed dir on loadmeta failure #1807

Closed
wants to merge 3 commits into from

Conversation

thorfour
Copy link
Contributor

@thorfour thorfour commented Nov 27, 2019

If loadmeta fails during SyncBlocks, the block directory is left behind,
resulting in subsequent failures to read the meta file since loadmeta just looks for the directory to exist.

FailureToLoadMeta unit test

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

Changes

Calls os.RemoveAll on the blockdir when returning error from load meta

Verification

Added unit test that checks if a sync against a block that's missing a meta.json gets removed.

@thorfour thorfour force-pushed the fix/sync-blocks-cleanup branch from 0f26871 to c53c6e3 Compare November 27, 2019 18:20
Thor added 2 commits November 27, 2019 12:23
If loadmeta fails during SyncBlocks, the block directory is left behind,
resulting in subsequent failures to read the meta file.

FailureToLoadMeta unit test

Signed-off-by: Thor <[email protected]>
Signed-off-by: Thor <[email protected]>
@thorfour thorfour force-pushed the fix/sync-blocks-cleanup branch from c53c6e3 to dc20411 Compare November 27, 2019 18:24
@@ -343,7 +343,7 @@ func (s *BucketStore) SyncBlocks(ctx context.Context) error {
bdir := path.Join(s.dir, id.String())
meta, err := loadMeta(ctx, s.logger, s.bucket, bdir, id)
if err != nil {
return errors.Wrap(err, "load meta")
return errors.Wrap(os.RemoveAll(bdir), "load meta")
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I don’t think this is quite right. This change will suppress the load meta error if the directory cleanup is successful. If we get an error loading metas, we want to return that error, not the error concerning cleanup. Cleanup should be a defer that logs any error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to return the error? Wouldn't that cause the Iter function to immediately abort the iteration?

Copy link
Member

@squat squat Nov 27, 2019

Choose a reason for hiding this comment

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

Returning the error is the current logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.. but it would be aborting an Iter function due to a transient error (block is still being written), when it could continue on syncing the remaining blocks.

This change would bring this more in-line with the functions below it which also log the error and clean up the directory.

Copy link
Member

Choose a reason for hiding this comment

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

I’m not necessarily against changing the logic, it simply isn’t what is done today and was not mentioned in your PR. Nevertheless, this change still suppresses the cause of the error without logging it. It also mixes up the causes of the errors. It would wrap a directory deletion error with load meta as though the deletion were the cause of failing to load the meta.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand what you're saying. I've updated it to be more in-line with the functions below it. Log the error, and return the os.RemoveAll error.

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 for this contribution!

resulting in subsequent failures to read the metafile since loadmeta just looks for the directory to exist.

That is not true as we check for file: if _, err := os.Stat(path.Join(dir, block.MetaFilename)); os.IsNotExist(err) { So what exactly are we fixing here?

I think this might work what you have, although blocking whole flow only if we cannot remove return os.RemoveAll(bdir) dir sounds wrong. We should handle leftover/partial directories well.

TBH I would love to work on so something mentioned here: #1335 so have a common library for fetching and maintaining metadata in both memory and disk. Probably something to do in the near future... still we can consider this PR.

@thorfour
Copy link
Contributor Author

@bwplotka you're right, just realized I had an older version of that file, that my IDE was presenting which had this instead of the line checking for the meta file.

if _, err := os.Stat(dir); os.IsNotExist(err) {

Egg on my face. Closing

@thorfour thorfour closed this Nov 28, 2019
@thorfour thorfour deleted the fix/sync-blocks-cleanup branch November 28, 2019 18:15
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.

3 participants