Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix insert of duplicate key into event_json #10719

Closed

Conversation

JanZerebecki
Copy link

@JanZerebecki JanZerebecki commented Aug 30, 2021

When an incoming event id is present in event_json but not in events
synapse fails trying to insert it with "psycopg2.errors.UniqueViolation:
duplicate key value violates unique constraints", because it is only
filtered based on those that are in events.

I don't know why those become out of sync, but this happening was
reported by others before.

Fix this by using an upsert (which inserts or updates existing records)
instead of a normal insert.

Please verify that this is the safe and correct thing to do before
merging this. Verify e.g. that it doesn't allow breaking history
integrity or something like it. As I don't know enough to understand
what this change entails.

Fixes: #10718
Signed-off-by: Jan Zerebecki [email protected]

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

@JanZerebecki JanZerebecki force-pushed the fix-dup-key-event_json branch 2 times, most recently from 031ebf0 to 3f4001c Compare September 1, 2021 13:09
When an incoming event id is present in event_json but not in events
synapse fails trying to insert it with "psycopg2.errors.UniqueViolation:
duplicate key value violates unique constraints", because it is only
filtered based on those that are in events.

I don't know why those become out of sync, but this happening was
reported by others before.

Fix this by using an upsert (which inserts or updates existing records)
instead of a normal insert.

Please verify that this is the safe and correct thing to do before
merging this. Verify e.g. that it doesn't allow breaking history
integrity or something like it. As I don't know enough to understand
what this change entails.

Fixes: matrix-org#10718
Signed-off-by: Jan Zerebecki <[email protected]>
@JanZerebecki JanZerebecki force-pushed the fix-dup-key-event_json branch from 3f4001c to d891766 Compare September 1, 2021 20:21
@richvdh richvdh changed the title Fix instert of duplicate key into event_json Fix insert of duplicate key into event_json Sep 1, 2021
@anoadragon453 anoadragon453 requested a review from a team September 9, 2021 13:49
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

per the discussion on #10718, we're not (yet) convince that this is a change that we should be making.

@erikjohnston erikjohnston added the z-blocked (Deprecated Label) label Sep 22, 2021
@richvdh
Copy link
Member

richvdh commented Feb 21, 2022

I think we agreed this was not a change that made sense. If your database is corrupt, then hacking around it isn't going to improve things.

@richvdh richvdh closed this Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-blocked (Deprecated Label)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deal with an event that is in event_json but not events
3 participants