Duplicated records in `issue_metrics` and `merge_request_metrics` tables.
Summary
Duplicated records in issue_metrics
and merge_request_metrics
tables.
Steps to reproduce
The cause is likely to be some kind of race condition. It's hard to reproduce it but happens constantly on gitlab.com (checked the DB).
What is the current bug behavior?
When creating/updating merge request or issue records, we should have always one associated metrics
record.
Example query to check duplicates:
select merge_request_id from merge_request_metrics group by merge_request_id having count(*) > 1 order by merge_request_id desc limit 10;
What is the expected correct behavior?
The example query above should return 0 items.
Possible fixes
Ensure that we're not creating duplicated records (unique index). Migrate/dedup existing records