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

Add locking to more safely delete state groups: Part 1 #18107

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

erikjohnston
Copy link
Member

@erikjohnston erikjohnston commented Jan 24, 2025

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.

@erikjohnston erikjohnston force-pushed the erikj/state_epochs2 branch 3 times, most recently from 19c8e98 to 53a7438 Compare January 24, 2025 16:27
@erikjohnston erikjohnston changed the title Add locking to more safely delete state groups Add locking to more safely delete state groups: Part 1 Jan 29, 2025
@erikjohnston erikjohnston force-pushed the erikj/state_epochs2 branch 2 times, most recently from 4938211 to 379c0f7 Compare January 29, 2025 11:18
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.
@erikjohnston erikjohnston marked this pull request as ready for review January 29, 2025 12:37
@erikjohnston erikjohnston requested a review from a team as a code owner January 29, 2025 12:37
Copy link
Member

@devonh devonh left a 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
Copy link
Member

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"

Comment on lines +97 to +98
# TODO: Clear from `state_groups_persisting` any holdovers from previous
# running instance.
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 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
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
we ensure that the state groups still exist and mark in the
we ensure that the state group still exists and mark in the

Comment on lines +31 to +32
-- The `id` column *must* be updated whenever a state group may have become
-- referenced.
Copy link
Member

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.

Comment on lines +121 to +122
if state_groups - existing_state_groups:
return state_groups - existing_state_groups
Copy link
Member

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.

Suggested change
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,
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
# 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
Copy link
Member

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
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
"""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
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
"""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
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
# 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

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.

2 participants