This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Handle non-strings in the event_search
table in synapse_port_db
#12037
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b9d806
Handle non-strings in the `event_search` table in `synapse_port_db`
5889d87
Add test for message received over federation with non-string body
c6d0534
Reword newsfile
c7b6710
Revert fix to `scripts/synapse_port_db` in favour of a background update
b6aff6e
Add a background update to clear out bad rows from `event_search` whe…
76d88af
Merge branch 'develop' into squah/no_integers_in_event_search
f045019
Use `.get_datastores().main` instead of `.get_datastore()` in tests
a895049
Run test on both sqlite and postgres
37c1798
Make schema delta sqlite only
02d8fe4
Reword changelog, again
4b5ec98
Sprinkle some type hints around
b7ad0a9
Fix test for postgres schema
75bc1bf
Remove redundant sqlite guard
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Properly fix a long-standing bug where wrong data could be inserted in the `event_search` table when using sqlite. This could block running `synapse_port_db` with an "argument of type 'int' is not iterable" error. This bug was partially fixed by a change in Synapse 1.44.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
synapse/storage/schema/main/delta/68/05_delete_non_strings_from_event_search.sql.sqlite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright 2022 The Matrix.org Foundation C.I.C | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
-- Delete rows with non-string `value`s from `event_search` if using sqlite. | ||
-- | ||
-- Prior to Synapse 1.44.0, malformed events received over federation could | ||
-- cause integers to be inserted into the `event_search` table. | ||
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES | ||
(6805, 'event_search_sqlite_delete_non_strings', '{}'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to limit this in any way? (Will this cause any locks on the table?)
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.
Good question! It crossed my mind at some point and I forgot to make a note of it on the PR.
event_search
is defined as a full text search virtual table with no explicit indexes:CREATE VIRTUAL TABLE event_search USING fts4 (event_id, room_id, sender, key, value);
so it looked like doing the processing in batches would be slower, since DELETEing by specific event_ids would have to scan the whole table anyway.
I think this will lock the table for the duration of the DELETE. The sqlite docs suggest that locks are done on the file level, so it's actually the entire database that gets locked, which is unfortunate.
We could add an index first, then delete in batches, but if we're going to ask sqlite to scan the whole table to build an index, we might as well just do the delete.