feat(deletions): Make event deletion task self-chaining idempotent - #122777
Open
shashjar wants to merge 2 commits into
Open
feat(deletions): Make event deletion task self-chaining idempotent#122777shashjar wants to merge 2 commits into
shashjar wants to merge 2 commits into
Conversation
shashjar
marked this pull request as ready for review
August 26, 2026 20:31
cvxluo
approved these changes
Aug 26, 2026
markstory
reviewed
Aug 26, 2026
| from sentry.testutils.helpers import override_options | ||
| from sentry.utils.snuba import UnqualifiedQueryError | ||
|
|
||
| _TASK_KEY = "delete_events_from_nodestore_and_eventstore" |
Member
There was a problem hiding this comment.
Shouldn't this import the constant from the task module instead of duplicating it?
Comment on lines
+151
to
+172
| @patch("sentry.deletions.tasks.nodestore.mark_spawned") | ||
| @patch("sentry.deletions.tasks.nodestore.current_task", return_value=None) | ||
| def test_selfchain_is_inert_without_activation( | ||
| self, mock_current_task: MagicMock, mock_mark_spawned: MagicMock | ||
| ) -> None: | ||
| events = [SimpleNamespace(event_id="event-id", timestamp="2025-01-01T00:00:00")] | ||
|
|
||
| with ( | ||
| patch( | ||
| "sentry.deletions.tasks.nodestore.fetch_events_from_eventstore", | ||
| return_value=events, | ||
| ), | ||
| patch("sentry.deletions.tasks.nodestore.delete_events_from_nodestore"), | ||
| patch("sentry.deletions.tasks.nodestore.delete_dangling_attachments_and_user_reports"), | ||
| patch.object( | ||
| delete_events_for_groups_from_nodestore_and_eventstore, "apply_async" | ||
| ) as mock_apply_async, | ||
| ): | ||
| self.run_deletion_task() | ||
|
|
||
| assert mock_apply_async.call_count == 1 | ||
| mock_mark_spawned.assert_not_called() |
Member
There was a problem hiding this comment.
Six mocks is a lot of mocks 😬
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For INC-2476.
Modeled after #118966.
The nodestore deletion task (
delete_events_for_groups_from_nodestore_and_eventstore) self-chains while paging through events. Because taskbroker provides at-least-once delivery, a re-pended activation could previously enqueue another continuation and fork the chain, amplifying deletion and Snuba traffic.This PR reuses the merge/unmerge self-chain guard: each activation checks a Redis marker keyed by its taskbroker activation ID and records the marker immediately after dispatching its continuation.
The project-level killswitch added in #122770 remains active.