-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make the event txnId
mapping rely on the device_id
instead of the access_token_id
.
#13083
Make the event txnId
mapping rely on the device_id
instead of the access_token_id
.
#13083
Conversation
Some brief thoughts.
I think there's some fiddling of Otherwise:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general theme: please make sure you include clear comments about what is going on. People shouldn't have to have an extensive knowledge of the entire Synapse codebase to understand what individual bits of code are for.
device_id: DictProperty[str] = DictProperty("device_id") | ||
token_id: DictProperty[Optional[int]] = DefaultDictProperty("token_id", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments please. What do these fields mean? What does it mean for them to be absent, or None?
device_id: DictProperty[str] = DictProperty("device_id") | ||
token_id: DictProperty[Optional[int]] = DefaultDictProperty("token_id", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we use a DefaultDictProperty
for token_id
when we do not do so for any of the other properties (all of which are optional)
if config.device_id is not None and config.device_id == getattr( | ||
e.internal_metadata, "device_id", None | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments here would be helpful. Why do we need to getattr
rather than just read e.internal_metadata.device_id
directly?
(just because the code was under-commented before doesn't mean you need to maintain that! What is this block actually doing?)
|
||
DROP INDEX event_txn_id_txn_id; | ||
CREATE UNIQUE INDEX event_txn_id_txn_id ON event_txn_id (room_id, user_id, device_id, txn_id); | ||
-- Keep this (non-unique) index in case we're rolling back |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, what does "in case we're rolling back" mean?
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more comments please. What is this delta doing? why?
(see
-- We're going to stop populating event_edges.room_id and event_edges.is_state, |
--
comments rather than a /*
one.
-- Keep this (non-unique) index in case we're rolling back | ||
CREATE INDEX event_txn_id_txn_id_token_id ON event_txn_id (room_id, user_id, token_id, txn_id); | ||
|
||
-- Make the device_id NOT NULL and remove the NOT NULL constraint from the token_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have a foreign key constraint on devices
?
DROP INDEX event_txn_id_event_id; | ||
DROP INDEX event_txn_id_txn_id; | ||
DROP INDEX event_txn_id_ts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will happen automatically when you drop the table?
CREATE UNIQUE INDEX event_txn_id_event_id ON event_txn_id2(event_id); | ||
CREATE UNIQUE INDEX event_txn_id_txn_id ON event_txn_id2(room_id, user_id, device_id, txn_id); | ||
-- Keep this index in case we're rolling back | ||
CREATE INDEX event_txn_id_txn_id_token_id ON event_txn_id2(room_id, user_id, token_id, txn_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's normally quicker to create the index once all the inserts are done.
* limitations under the License. | ||
*/ | ||
|
||
CREATE TABLE event_txn_id2 ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we seem to be missing the foreign key constraints here?
@sandhose Is this still needed? Looks like there's some outstanding feedback. |
This adds two tests, which check the current spec behaviour of transaction IDs, which are that they are scoped to a series of access tokens, and not the device ID. The first test highlight this behaviour, by logging in with refresh token enabled, sending an event, using the refresh token and syncing with the new access token. On the sync, the transaction ID should be there, but currently in Synapse it is not. The second test highlight that the transaction ID is not scoped to the device ID, by logging in twice with the same device ID, sending an event with the first access token, and syncing with the second access token. In that case, the sync should not contain the transaction ID, but I think it's the case in HS implementations which use the device ID to scope the transaction IDs, like Conduit. Related: matrix-org/matrix-spec#1133, matrix-org/matrix-spec#1236, matrix-org/synapse#13064 and matrix-org/synapse#13083
This adds two tests, which check the current spec behaviour of transaction IDs, which are that they are scoped to a series of access tokens, and not the device ID. The first test highlight this behaviour, by logging in with refresh token enabled, sending an event, using the refresh token and syncing with the new access token. On the sync, the transaction ID should be there, but currently in Synapse it is not. The second test highlight that the transaction ID is not scoped to the device ID, by logging in twice with the same device ID, sending an event with the first access token, and syncing with the second access token. In that case, the sync should not contain the transaction ID, but I think it's the case in HS implementations which use the device ID to scope the transaction IDs, like Conduit. Related: matrix-org/matrix-spec#1133, matrix-org/matrix-spec#1236, matrix-org/synapse#13064 and matrix-org/synapse#13083
This adds two tests, which check the current spec behaviour of transaction IDs, which are that they are scoped to a series of access tokens, and not the device ID. The first test highlight this behaviour, by logging in with refresh token enabled, sending an event, using the refresh token and syncing with the new access token. On the sync, the transaction ID should be there, but currently in Synapse it is not. The second test highlight that the transaction ID is not scoped to the device ID, by logging in twice with the same device ID, sending an event with the first access token, and syncing with the second access token. In that case, the sync should not contain the transaction ID, but I think it's the case in HS implementations which use the device ID to scope the transaction IDs, like Conduit. Related: matrix-org/matrix-spec#1133, matrix-org/matrix-spec#1236, matrix-org/synapse#13064 and matrix-org/synapse#13083
This adds two tests, which check the current spec behaviour of transaction IDs, which are that they are scoped to a series of access tokens, and not the device ID. The first test highlight this behaviour, by logging in with refresh token enabled, sending an event, using the refresh token and syncing with the new access token. On the sync, the transaction ID should be there, but currently in Synapse it is not. The second test highlight that the transaction ID is not scoped to the device ID, by logging in twice with the same device ID, sending an event with the first access token, and syncing with the second access token. In that case, the sync should not contain the transaction ID, but I think it's the case in HS implementations which use the device ID to scope the transaction IDs, like Conduit. Related: matrix-org/matrix-spec#1133, matrix-org/matrix-spec#1236, matrix-org/synapse#13064 and matrix-org/synapse#13083
… `access_token_id`. Signed-off-by: Quentin Gliech <quenting@element.io>
Replaced by #15318 |
This adds two tests, which check the current spec behaviour of transaction IDs, which are that they are scoped to a series of access tokens, and not the device ID. The first test highlight this behaviour, by logging in with refresh token enabled, sending an event, using the refresh token and syncing with the new access token. On the sync, the transaction ID should be there, but currently in Synapse it is not. The second test highlight that the transaction ID is not scoped to the device ID, by logging in twice with the same device ID, sending an event with the first access token, and syncing with the second access token. In that case, the sync should not contain the transaction ID, but I think it's the case in HS implementations which use the device ID to scope the transaction IDs, like Conduit. Related: matrix-org/matrix-spec#1133, matrix-org/matrix-spec#1236, matrix-org/synapse#13064 and matrix-org/synapse#13083
Fixes #13064
This changes the event
txnId
mapping to rely on thedevice_id
instead of theaccess_token_id
.Note that there are access tokens created via the admin API which don't have a
device_id
. Those tokens would loose:txnId
echo in/sync
when they are sending an event to a roomNote that I decided to keep the
token_id
(and still writing to it) in theevent_txn_id
table to allow rolling back, but I'm not reading on it.Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)