-
Notifications
You must be signed in to change notification settings - Fork 385
Cache _get_e2e_cross_signing_signatures_for_devices
#18899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This needs a small change. I had missed that functions decorated with |
7ba742b
to
8811a86
Compare
This test started to fail after implementing element-hq/synapse#18899. The failure appeared to be due to the test not waiting for signatures to propagate over federation. The loop would exit as soon as it saw a 'signatures' key. But the value was an empty dict. A few moments later, the dict would be populated with the key we were waiting for. But while that was being sent over federation, the test would fail and exit abruptly. This commit changes the loop to actually check for the signature we're waiting for, instead of exiting upon seeing the 'signatures' key. This seems like it would be less flaky in general, and prevents the test from failing in this case.
This test started to fail after implementing element-hq/synapse#18899. The failure appeared to be due to the test not waiting for signatures to propagate over federation. The loop would exit as soon as it saw a 'signatures' key. But the value was an empty dict. A few moments later, the dict would be populated with the key we were waiting for. But while that was being sent over federation, the test would fail and exit abruptly. This commit changes the loop to actually check for the signature we're waiting for, instead of exiting upon seeing the 'signatures' key. This seems like it would be less flaky in general, and prevents the test from failing in this case.
This test started to fail after implementing element-hq/synapse#18899. The failure appeared to be due to the test not waiting for signatures to propagate over federation. The loop would exit as soon as it saw a 'signatures' key. But the value was an empty dict. A few moments later, the dict would be populated with the key we were waiting for. But while that was being sent over federation, the test would fail and exit abruptly. This commit changes the loop to actually check for the signature we're waiting for, instead of exiting upon seeing the 'signatures' key. This seems like it would be less flaky in general, and prevents the test from failing in this case.
This test started to fail after implementing element-hq/synapse#18899. The failure appeared to be due to the test not waiting for signatures to propagate over federation. The loop would exit as soon as it saw a 'signatures' key. But the value was an empty dict. A few moments later, the dict would be populated with the key we were waiting for. But while that was being sent over federation, the test would fail and exit abruptly. This commit changes the loop to actually check for the signature we're waiting for, instead of exiting upon seeing the 'signatures' key. This seems like it would be less flaky in general, and prevents the test from failing in this case.
2df4e22
to
834662d
Compare
The use of `@cachedList` requires having a cached, equivalent "single item" method that represents the key and cached value. Calls to methods with @cachedList are then processed and items that are already cached are removed before the @cachedList-decorated method is called. The single item method should not be directly used. The return type needed to be changed to a "Mapping" containing a "Sequence" to satisfy the requirement that cached results must be immutable (lest you risk mutating the cache). `@cachedList` also requires returning an dict where the keys matches that of the items in the cached input list. Our keys are tuples (and you'll later see why this is a pain).
The return type has changed, and we now need to handle a map of user_id/device_id tuples to lists of key signatures.
This is needed to then call `_invalidate_cache_and_stream_bulk with the `txn` object in the next commit.
Invalidate and stream whenever we update `e2e_cross_signing_signatures`.
As the "keys" in an incoming cache invalidation stream object appear to always be a string, we have to do some special case handling to convert the string into a tuple of (user_id, device_id). This works, but is awful.
834662d
to
983f850
Compare
983f850
to
a096967
Compare
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.
Seems overall OK though; are there any tests we should add (I guess cache invalidation would be on my mind)?
Instead of encoding them using a brittle, custom scheme. Avoids errors where the device ID or user ID contains a comma.
Required defining a three-column overload for the method to pass mypy. Additionally the type-ignore was no longer required according to mypy.
Since `_get_e2e_cross_signing_signatures_for_devices` always return a key for every entry in `device_query`, there will never be a case where the function can return `None`, even when decorated with `@cacheList`.
b037d41
to
e7ca69d
Compare
(json.dumps([user_id, item.target_device_id]),) | ||
for item in signatures |
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.
not possible to json.dumps the entries of to_invalidate
?
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.
You can; it looks like this:
to_send = [
(json.dumps(item[0]),)
for item in to_invalidate
]
which seemed less clear as to what we're actually sending than what's there now.
Ah, I missed this. Sytest does fail (specifically |
This PR adds a cache to
_get_e2e_cross_signing_signatures_for_devices
to put less pressure on the database.Recommended to review commit-by-commit.
Requires matrix-org/sytest#1409 for Sytest CI to pass.
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.