Skip to content

Commit 6feb629

Browse files
committed
remove hierarchical code from _save_aggregate_new
1 parent 16e1582 commit 6feb629

File tree

1 file changed

+5
-66
lines changed

1 file changed

+5
-66
lines changed

src/sentry/event_manager.py

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ def _save_aggregate_new(
16021602
) -> GroupInfo | None:
16031603
project = event.project
16041604

1605-
primary_hashes, secondary_hashes, hashes = get_hash_values(project, job, metric_tags)
1605+
hashes = get_hash_values(project, job, metric_tags)[2]
16061606

16071607
# Now that we've used the current and possibly secondary grouping config(s) to calculate the
16081608
# hashes, we're free to perform a config update if needed. Future events will use the new
@@ -1615,43 +1615,11 @@ def _save_aggregate_new(
16151615

16161616
group_creation_kwargs = _get_group_creation_kwargs(job)
16171617

1618-
# Because this logic is not complex enough we want to special case the situation where we
1619-
# migrate from a hierarchical hash to a non hierarchical hash. The reason being that
1620-
# there needs to be special logic to not create orphaned hashes in migration cases
1621-
# but it wants a different logic to implement splitting of hierarchical hashes.
1622-
migrate_off_hierarchical = bool(
1623-
secondary_hashes
1624-
and secondary_hashes.hierarchical_hashes
1625-
and not primary_hashes.hierarchical_hashes
1626-
)
1627-
16281618
flat_grouphashes = [
16291619
GroupHash.objects.get_or_create(project=project, hash=hash)[0] for hash in hashes.hashes
16301620
]
16311621

1632-
# The root_hierarchical_hash is the least specific hash within the tree, so
1633-
# typically hierarchical_hashes[0], unless a hash `n` has been split in
1634-
# which case `root_hierarchical_hash = hierarchical_hashes[n + 1]`. Chosing
1635-
# this for select_for_update mostly provides sufficient synchronization
1636-
# when groups are created and also relieves contention by locking a more
1637-
# specific hash than `hierarchical_hashes[0]`.
1638-
existing_grouphash, root_hierarchical_hash = find_existing_grouphash_new(flat_grouphashes)
1639-
1640-
if root_hierarchical_hash is not None:
1641-
root_hierarchical_grouphash = GroupHash.objects.get_or_create(
1642-
project=project, hash=root_hierarchical_hash
1643-
)[0]
1644-
1645-
metadata.update(
1646-
hashes.group_metadata_from_hash(
1647-
existing_grouphash.hash
1648-
if existing_grouphash is not None
1649-
else root_hierarchical_hash
1650-
)
1651-
)
1652-
1653-
else:
1654-
root_hierarchical_grouphash = None
1622+
existing_grouphash, _ = find_existing_grouphash_new(flat_grouphashes)
16551623

16561624
# In principle the group gets the same metadata as the event, so common
16571625
# attributes can be defined in eventtypes.
@@ -1686,25 +1654,14 @@ def _save_aggregate_new(
16861654
metric_tags["create_group_transaction.outcome"] = "no_group"
16871655

16881656
all_grouphash_ids = [h.id for h in flat_grouphashes]
1689-
if root_hierarchical_grouphash is not None:
1690-
all_grouphash_ids.append(root_hierarchical_grouphash.id)
16911657

16921658
all_grouphashes = list(
16931659
GroupHash.objects.filter(id__in=all_grouphash_ids).select_for_update()
16941660
)
16951661

16961662
flat_grouphashes = [gh for gh in all_grouphashes if gh.hash in hashes.hashes]
16971663

1698-
existing_grouphash, root_hierarchical_hash = find_existing_grouphash_new(
1699-
flat_grouphashes
1700-
)
1701-
1702-
if root_hierarchical_hash is not None:
1703-
root_hierarchical_grouphash = GroupHash.objects.get_or_create(
1704-
project=project, hash=root_hierarchical_hash
1705-
)[0]
1706-
else:
1707-
root_hierarchical_grouphash = None
1664+
existing_grouphash, _ = find_existing_grouphash_new(flat_grouphashes)
17081665

17091666
if existing_grouphash is None:
17101667
group = _create_group(project, event, **group_creation_kwargs)
@@ -1721,10 +1678,7 @@ def _save_aggregate_new(
17211678
},
17221679
)
17231680

1724-
if root_hierarchical_grouphash is not None:
1725-
new_hashes = [root_hierarchical_grouphash]
1726-
else:
1727-
new_hashes = list(flat_grouphashes)
1681+
new_hashes = list(flat_grouphashes)
17281682

17291683
GroupHash.objects.filter(id__in=[h.id for h in new_hashes]).exclude(
17301684
state=GroupHash.State.LOCKED_IN_MIGRATION
@@ -1773,22 +1727,7 @@ def _save_aggregate_new(
17731727

17741728
is_new = False
17751729

1776-
# For the migration from hierarchical to non hierarchical we want to associate
1777-
# all group hashes
1778-
if migrate_off_hierarchical:
1779-
new_hashes = [h for h in flat_grouphashes if h.group_id is None]
1780-
if root_hierarchical_grouphash and root_hierarchical_grouphash.group_id is None:
1781-
new_hashes.append(root_hierarchical_grouphash)
1782-
elif root_hierarchical_grouphash is None:
1783-
# No hierarchical grouping was run, only consider flat hashes
1784-
new_hashes = [h for h in flat_grouphashes if h.group_id is None]
1785-
elif root_hierarchical_grouphash.group_id is None:
1786-
# The root hash is not assigned to a group.
1787-
# We ran multiple grouping algorithms
1788-
# (see secondary grouping), and the hierarchical hash is new
1789-
new_hashes = [root_hierarchical_grouphash]
1790-
else:
1791-
new_hashes = []
1730+
new_hashes = [h for h in flat_grouphashes if h.group_id is None]
17921731

17931732
if new_hashes:
17941733
# There may still be secondary hashes that we did not use to find an

0 commit comments

Comments
 (0)