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 forgotten parts in cleanup thread #37014

Merged
merged 10 commits into from
May 10, 2022
Merged

Conversation

alesapin
Copy link
Member

@alesapin alesapin commented May 7, 2022

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix bug which can lead to forgotten outdated parts in MergeTree table engines family in case of filesystem failures during parts removal. Before fix they will be removed only after first server restart.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-improvement Pull request with some product improvements label May 7, 2022
}


void MergeTreeData::clearPartsFromFilesystemImpl(const DataPartsVector & parts_to_remove, bool throw_on_error, NameSet * part_names_successed)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more elegant to pass std::vector<char> was_part_removed or something ...
You may avoid adding mutex (but it is also ok).

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't want to do it at this moment.

finally_remove_parts = parts_to_delete_only_from_filesystem;
}

removePartsFinally(finally_remove_parts);
Copy link
Member

Choose a reason for hiding this comment

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

Right now, the whole code of clearOldPartsAndRemoveFromZK looks over-complicated and not very solid to me.
Generally, after grabOldParts we can get a set of parts with Deleting which we must delete or roll back to Outdated. But it is not clear if what we do in between is exception safe. Like, here we assume that rollbackDeletingParts and removePartsFinally don't throw (which is optimistic cause e.g. the last one writes to part log).

Maybe we can always keep a parts vector (as a result of grabOldParts), and also has a vector with statuses (Deleting, DeletedFromZk, DeletedFromFS, Outdated, something else) so that in the final try/catch we can (more or less) reliably roll back statuses?

BTW, grabOldParts is complicated as well, and it is not (very) clear if we can get exception inside and get half-state where some parts were if fact marked as deleting. However, at least a loop with modifyPartState is the last one:

for (const auto & it_to_delete : parts_to_delete)
{
res.emplace_back(*it_to_delete);
modifyPartState(it_to_delete, DataPartState::Deleting);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed in TG and decide to current version. After that we can apply refactoring.

Copy link
Member

@KochetovNicolai KochetovNicolai left a comment

Choose a reason for hiding this comment

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

This code is better then it was. Also it fixes an issue, so I think we can merge it as is, and probably improve later.
@tavplubix could you please double-check?

@alesapin
Copy link
Member Author

No more packets available: #37068

@alesapin
Copy link
Member Author

Keeper failed to start -- will investigate separately.

@alesapin alesapin merged commit 41737d6 into master May 10, 2022
@alesapin alesapin deleted the better_delete_outdated_parts branch May 10, 2022 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants