diff options
author | Eric Eastwood <erice@element.io> | 2022-09-02 14:05:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 14:05:39 -0500 |
commit | 877bdfa889fa07d09f385df297a9282d51d50dae (patch) | |
tree | 2bfe6a364ac9d0b681d7879f08be25b68b00125e | |
parent | Update docs to make enabling metrics more clear (#13678) (diff) | |
download | synapse-877bdfa889fa07d09f385df297a9282d51d50dae.tar.xz |
Clarify `(room_id, event_id)` global uniqueness (#13701)
Summarized from @richvdh's reply at https://github.com/matrix-org/synapse/pull/13589#discussion_r961116999
-rw-r--r-- | changelog.d/13701.doc | 1 | ||||
-rw-r--r-- | docs/development/database_schema.md | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/changelog.d/13701.doc b/changelog.d/13701.doc new file mode 100644 index 0000000000..b438e066d8 --- /dev/null +++ b/changelog.d/13701.doc @@ -0,0 +1 @@ +Clarify `(room_id, event_id)` global uniqueness and how we should scope our database schemas. diff --git a/docs/development/database_schema.md b/docs/development/database_schema.md index d996a7caa2..e9b925ddd8 100644 --- a/docs/development/database_schema.md +++ b/docs/development/database_schema.md @@ -191,3 +191,27 @@ There are three separate aspects to this: flavour will be accepted by SQLite 3.22, but will give a column whose default value is the **string** `"FALSE"` - which, when cast back to a boolean in Python, evaluates to `True`. + + +## `event_id` global uniqueness + +In room versions `1` and `2` it's possible to end up with two events with the +same `event_id` (in the same or different rooms). After room version `3`, that +can only happen with a hash collision, which we basically hope will never +happen. + +There are several places in Synapse and even Matrix APIs like [`GET +/_matrix/federation/v1/event/{eventId}`](https://spec.matrix.org/v1.1/server-server-api/#get_matrixfederationv1eventeventid) +where we assume that event IDs are globally unique. + +But hash collisions are still possible, and by treating event IDs as room +scoped, we can reduce the possibility of a hash collision. When scoping +`event_id` in the database schema, it should be also accompanied by `room_id` +(`PRIMARY KEY (room_id, event_id)`) and lookups should be done through the pair +`(room_id, event_id)`. + +There has been a lot of debate on this in places like +https://github.com/matrix-org/matrix-spec-proposals/issues/2779 and +[MSC2848](https://github.com/matrix-org/matrix-spec-proposals/pull/2848) which +has no resolution yet (as of 2022-09-01). + |