Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix broken background updates when using sqlite with enable_search off #12215

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix broken background updates when using sqlite with enable_search off
Signed-off-by: Sean Quah <seanq@element.io>
  • Loading branch information
Sean Quah committed Mar 14, 2022
commit e03908f1bbd6a9c4935daf11a924c01fe8798458
1 change: 1 addition & 0 deletions changelog.d/12215.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in 1.54.0 that broke background updates on sqlite homeservers while search was disabled.
13 changes: 7 additions & 6 deletions synapse/storage/databases/main/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ def __init__(
):
super().__init__(database, db_conn, hs)

if not hs.config.server.enable_search:
return
Comment on lines -128 to -129
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't really clear to me what the ramifications of this are, does it mean that we'll now run all these updates when search is disabled? Or just that they're now registered and the code "exists" to handle those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The older updates will now run when upgrading from very old Synapse versions, instead of raising endless errors when search is disabled. Up-to-date Synapse installs will only try to run the delete_non_strings update.

I'm reasoning that if search is disabled, event_search is probably empty (unless search was enabled in the past) and the updates will complete quickly.


self.db_pool.updates.register_background_update_handler(
self.EVENT_SEARCH_UPDATE_NAME, self._background_reindex_search
)
Expand Down Expand Up @@ -243,9 +240,13 @@ def reindex_search_txn(txn):

return len(event_search_rows)

result = await self.db_pool.runInteraction(
self.EVENT_SEARCH_UPDATE_NAME, reindex_search_txn
)
if self.hs.config.server.enable_search:
result = await self.db_pool.runInteraction(
self.EVENT_SEARCH_UPDATE_NAME, reindex_search_txn
)
else:
# Don't index anything if search is not enabled.
result = 0

if not result:
await self.db_pool.updates._end_background_update(
Expand Down