Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions src/sentry/deletions/defaults/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,21 @@ def delete_group_hashes(
logger.warning("Error scheduling task to delete hashes from seer")
finally:
hash_ids = [gh[0] for gh in hashes_chunk]
if options.get("deletions.group.delete_group_hashes_metadata_first"):
metrics.incr("deletions.group.delete_group_hashes_metadata_first", sample_rate=1.0)
# If we delete the grouphash metadata rows first we will not need to update the references to the other grouphashes.
# If we try to delete the group hashes first, then it will require the updating of the columns first.
#
# To understand this, let's say we have the following relationships:
# gh A -> ghm A -> no reference to another grouphash
# gh B -> ghm B -> gh C
# gh C -> ghm C -> gh A
#
# Deleting group hashes A, B & C (since they all point to the same group) will require:
# * Updating columns ghmB & ghmC to point to None
# * Deleting the group hash metadata rows
# * Deleting the group hashes
#
# If we delete the metadata first, we will not need to update the columns before deleting them.
try:
GroupHashMetadata.objects.filter(grouphash_id__in=hash_ids).delete()
except Exception:
# XXX: Let's make sure that no issues are caused by this and then remove it
logger.exception("Error deleting group hash metadata")

# If we delete the grouphash metadata rows first we will not need to update the references to the other grouphashes.
# If we try to delete the group hashes first, then it will require the updating of the columns first.
#
# To understand this, let's say we have the following relationships:
# gh A -> ghm A -> no reference to another grouphash
# gh B -> ghm B -> gh C
# gh C -> ghm C -> gh A
#
# Deleting group hashes A, B & C (since they all point to the same group) will require:
# * Updating columns ghmB & ghmC to point to None
# * Deleting the group hash metadata rows
# * Deleting the group hashes
#
# If we delete the metadata first, we will not need to update the columns before deleting them.
GroupHashMetadata.objects.filter(grouphash_id__in=hash_ids).delete()
GroupHash.objects.filter(id__in=hash_ids).delete()

iterations += 1
Expand Down
6 changes: 0 additions & 6 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,6 @@
type=Int,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)
register(
"deletions.group.delete_group_hashes_metadata_first",
default=False,
type=Bool,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

# Filestore (default)
register("filestore.backend", default="filesystem", flags=FLAG_NOSTORE)
Expand Down
7 changes: 0 additions & 7 deletions tests/sentry/deletions/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,6 @@ def test_delete_grouphashes_and_metadata(self) -> None:
assert not GroupHash.objects.filter(id=grouphash_b.id).exists()
assert not GroupHashMetadata.objects.filter(id=metadata_b_id).exists()

def test_delete_grouphashes_and_metadata_and_metadata_but_delete_metadata_first(self) -> None:
"""
Test that when deleting group hashes, the group hash metadata is deleted first (which will not update the references to the other group hashes)
"""
with self.options({"deletions.group.delete_group_hashes_metadata_first": True}):
self.test_delete_grouphashes_and_metadata()


class DeleteIssuePlatformTest(TestCase, SnubaTestCase, OccurrenceTestMixin):
referrer = Referrer.TESTING_TEST.value
Expand Down
Loading