Skip to content
Closed
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
15 changes: 13 additions & 2 deletions src/sentry/tagstore/legacy/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def setup(self):
default_manager.register(EventTag, BulkModelDeletionTask)

default_manager.add_dependencies(Group, [
lambda instance: ModelRelation(EventTag, {'group_id': instance.id}),
lambda instance: ModelRelation(EventTag, {
'group_id': instance.id,
'project_id': instance.project_id,
}),
lambda instance: ModelRelation(GroupTagKey, {'group_id': instance.id}),
lambda instance: ModelRelation(GroupTagValue, {'group_id': instance.id}),
])
Expand All @@ -56,7 +59,13 @@ def setup(self):
])
default_manager.add_bulk_dependencies(Event, [
lambda instance_list: ModelRelation(EventTag,
{'event_id__in': [i.id for i in instance_list]},
{
'event_id__in': [i.id for i in instance_list],
'project_id__in': {
Copy link
Contributor Author

@bretthoerner bretthoerner Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master_1    | ERROR:  cannot run DELETE command which targets multiple shards
master_1    | HINT:  Consider using an equality filter on partition column "project_id" to target a single shard. If you'd like to run a multi-shard operation, use master_modify_multiple_shards().
master_1    | STATEMENT:  DELETE FROM "sentry_eventtag" WHERE "id" IN (2)

Can't do IN across shards either. Deletion code will have to be refactored to allow for one query per project_id. Which sucks, because I think when we delete groups we're just iterating by date? So the project constantly varies. Will be a large refactor I think to get that correct/fast.

Other option: https://docs.citusdata.com/en/v7.0/reference/user_defined_functions.html#master-modify-multiple-shards

instance.project_id
for instance in instance_list
},
},
ModelDeletionTask),
])

Expand Down Expand Up @@ -331,6 +340,7 @@ def get_group_event_ids(self, project_id, group_id, tags):
EventTag.objects.filter(
key_id=k,
value_id=v,
project_id=project_id,
group_id=group_id,
).values_list('event_id', flat=True)[:1000]
)
Expand All @@ -343,6 +353,7 @@ def get_group_event_ids(self, project_id, group_id, tags):
key_id=k,
value_id=v,
event_id__in=matches,
project_id=project_id,
group_id=group_id,
).values_list('event_id', flat=True)[:1000]
)
Expand Down