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

Refactor merge_samples() to safely cleanup in case of errors #2135

Merged
merged 4 commits into from
Oct 20, 2022

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Oct 3, 2022

Refactors the implementation of merge_samples() so that, if something goes wrong in the $merge aggregations, the temporary indexes and frame fields that are created in order to facilitate the merge will be automatically cleaned up.

Prior to this change, if a $merge failed on a video dataset, the datasets involved would be in broken states until the following operations were manually performed on them:

# Cleanup after failed merge
dataset._frame_collection.drop_index("_merge_key_1_frame_number_1")
dataset._frame_collection.update_many({}, {"$unset": {"_merge_key": ""}})

The fatal error was the unexpected _merge_key values, but leaving extra indexes laying around is also a party foul.

Update: adds some additional try-finally blocks in various places throughout the codebase

@brimoor brimoor added the bug Bug fixes label Oct 3, 2022
@brimoor brimoor requested a review from a team October 3, 2022 16:47
@brimoor brimoor self-assigned this Oct 3, 2022
Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

LGTM. This is where transactions are valuable. So next time we have to consider database state and errors, I'd recommend we look into #1791 before we start adding more code like this.

@brimoor brimoor merged commit 6bedae3 into develop Oct 20, 2022
@brimoor brimoor deleted the safe-merge branch October 20, 2022 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants