Add an API to list changes to quarantine state of media#19558
Add an API to list changes to quarantine state of media#19558
Conversation
Sticky events was used as reference for creating this.
e76dc83 to
6328e78
Compare
258768e to
f1a35fa
Compare
Just something I noticed while working on #19558 We start the function by setting `total_media_quarantined` to zero, then we do work on the `media_ids`, add the number affected, zero it out (**bug**), do work on `hashes`, add the number of affected rows, then return `total_media_quarantined`. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). 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. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
| HTTPStatus.INTERNAL_SERVER_ERROR, | ||
| "Timed out while waiting for stream position", | ||
| errcode=Codes.UNKNOWN, | ||
| ) |
There was a problem hiding this comment.
Ideally, we'd also validate from_id before waiting and throw M_INVALID_PARAM. This way people see a more sane error instead of 500 {'errcode': 'M_UNKNOWN', 'error': 'Internal server error'} from the assertion in wait_for_quarantined_media_stream_id(...).
This kind of thing is mentioned in #19644 "tokens should be validated before it reaches this point."
There isn't a helper for this so it would be a similar if from_id < max_persisted_position: error check.
Since this is an admin endpoint we could forgo this but it would be nice to have a good example in the codebase.
There was a problem hiding this comment.
Should be covered in 51f9f0e - let me know if changes are needed
There was a problem hiding this comment.
(will follow up in a subsequent PR if required)
There was a problem hiding this comment.
The if to_id < from_id: error check that was added in 51f9f0e is a bit flawed since to_id is the current token of the current worker (which could be behind the other workers). (and it's okay for to_id == from_id as that would mean no activity has happened)
I think we want to compare to get_max_allocated_token() which actually looks at the database source of truth across all of the workers.
There was a problem hiding this comment.
We'd then need to wait for that token too, I believe?
There was a problem hiding this comment.
I guess we don't - if we're caught up on from then we might return fewer results, but that's fine.
Co-authored-by: Eric Eastwood <erice@element.io>
Co-authored-by: Eric Eastwood <erice@element.io>
…portdb` (#19675) Part of #19671 Spawning from [discussion in `#synapse-dev:matrix.org`](https://matrix.to/#/!i5D5LLct_DYG-4hQprLzrxdbZ580U9UB6AEgFnk6rZQ/$Z3nqbH0Qy21FWC3qJOim6LSRCRpJ3pxV5DLXm98IA6I?via=element.io&via=matrix.org&via=beeper.com) with roots in #19558 (comment). As trialed/discovered by @turt2live alongside @reivilibre and @clokep ❤️ ### Why is this necessary? If you forget to add `_setup_sequence(...)`, you can run into the following error if there is 1 row in SQLite and then you use the `portdb` script to try to migrate to Postgres (as [explained](https://matrix.to/#/!i5D5LLct_DYG-4hQprLzrxdbZ580U9UB6AEgFnk6rZQ/$mHU6dcTNL7NMfKBCJUekCh7vDj1lr1GDjriZQl7oeeU?via=element.io&via=matrix.org&via=beeper.com) by @reivilibre) ``` Postgres sequence 'quarantined_media_id_seq' is inconsistent with associated stream position of 'quarantined_media' in the 'stream_positions' table. ```
|
Thanks for working with me on this :) |
|
Thanks for pushing through all of the hard stuff @turt2live 🦏 |
…#19677) Following up on #19558 (comment) Changelog for this PR is intended to overlap with the above PR. `get_current_quarantined_media_stream_id` wasn't being used anywhere else, so we can replace it like we do in this PR. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). 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. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Eric Eastwood <erice@element.io> Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
Fixes #19352
(See issue for history of this feature and previous PRs)
This PR re-introduces the API building on the previous feedback:
We track both quarantine and unquarantine actions in the stream to allow downstream consumers to process the records appropriately. Namely, to allow our Synapse exchange in HMA to remove hashes for unquarantined media (use case further explained in the issue).
Note: This knowingly does not capture all cases of media being quarantined. Other call sites are lower priority for T&S, and can be addressed in a future PR.
An issue will be created after this PR is merged to track those sites.#19672Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.