-
Notifications
You must be signed in to change notification settings - Fork 236
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
Add locking to more safely delete state groups: Part 1 #18107
base: develop
Are you sure you want to change the base?
Conversation
19c8e98
to
53a7438
Compare
4938211
to
379c0f7
Compare
Currently we don't really have anything that stops us from deleting state groups when an in-flight event references it. This is a fairly rare race currently, but we want to be able to more aggresively delete state groups so it is important to address this to ensure that the database remains valid. See the class docstring of the new data store for an explanation for how this works.
379c0f7
to
4495545
Compare
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.
The new tables & logic all makes sense to me. Just a couple of tidying up tasks to do.
transaction we recheck `state_groups_pending_deletion` table again and see | ||
that it exists and so continue with the deletion. To prevent this from | ||
happening we add a `sequence_number` column to | ||
`state_groups_pending_deletion`, and during ensure that for a state group |
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.
this should be "and during deletion"
# TODO: Clear from `state_groups_persisting` any holdovers from previous | ||
# running instance. |
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.
I'm assuming this will be in Part 2 of the state groups deletion PR series?
groups that we want to delete. | ||
|
||
To handle this, we take two approaches. First, before we persist any event | ||
we ensure that the state groups still exist and mark in the |
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.
we ensure that the state groups still exist and mark in the | |
we ensure that the state group still exists and mark in the |
-- The `id` column *must* be updated whenever a state group may have become | ||
-- referenced. |
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.
Not sure what this is referring to.
Maybe it should just be removed.
if state_groups - existing_state_groups: | ||
return state_groups - existing_state_groups |
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.
Would be better to only do this set manipulation once.
if state_groups - existing_state_groups: | |
return state_groups - existing_state_groups | |
missing_state_groups = state_groups - existing_state_groups | |
if missing_state_groups: | |
return missing_state_groups |
|
||
can_be_deleted = ready_to_be_deleted - not_ready_to_be_deleted | ||
if not_ready_to_be_deleted: | ||
# If there are any state groups that aren't ready to be persisted, |
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.
# If there are any state groups that aren't ready to be persisted, | |
# If there are any state groups that aren't ready to be deleted, |
@@ -19,7 +19,7 @@ | |||
# | |||
# | |||
|
|||
SCHEMA_VERSION = 88 # remember to update the list below when updating | |||
SCHEMA_VERSION = 89 # remember to update the list below when updating |
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.
Update the list below with an entry about adding tables for state group deletion.
self.assertFalse(can_be_deleted) | ||
|
||
def test_deletion_error_during_persistence(self) -> None: | ||
"""Test that state groups remain marked as for deletion if persisting |
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.
"""Test that state groups remain marked as for deletion if persisting | |
"""Test that state groups remain marked as pending deletion if persisting |
self.assertTrue(can_be_deleted) | ||
|
||
def test_race_between_check_and_insert(self) -> None: | ||
"""Check that we correctly handle the race where we got to delete a |
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.
"""Check that we correctly handle the race where we got to delete a | |
"""Check that we correctly handle the race where we go to delete a |
) | ||
) | ||
|
||
# We shouldn't be able to delete the state group as not enough time as passed |
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.
# We shouldn't be able to delete the state group as not enough time as passed | |
# We shouldn't be able to delete the state group as not enough time has passed |
Currently we don't really have anything that stops us from deleting state groups when an in-flight event references it. This is a fairly rare race currently, but we want to be able to more aggressively delete state groups so it is important to address this to ensure that the database remains valid.
This implements the locking, but doesn't actually use it.
See the class docstring of the new data store for an explanation for how this works.