Fix registering of background updates for split main/state db (#18509)
The background updates are being registered on an object that is for the _state_ database, but the actual tables are on the _main_ database. This just moves them to a different store that can access the right stuff. I noticed this when trying to do a full schema dump cause I was curious what has changed since the last one. Fixes #16054 ### 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))
This commit is contained in:
1
changelog.d/18509.bugfix
Normal file
1
changelog.d/18509.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Fix `KeyError` on background updates when using split main/state databases.
|
||||
@@ -27,7 +27,7 @@ pub enum IdentifierError {
|
||||
|
||||
impl fmt::Display for IdentifierError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,27 @@ class EventsBackgroundUpdatesStore(StreamWorkerStore, StateDeltasStore, SQLBaseS
|
||||
where_clause="NOT outlier",
|
||||
)
|
||||
|
||||
# These indices are needed to validate the foreign key constraint
|
||||
# when events are deleted.
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
_BackgroundUpdates.CURRENT_STATE_EVENTS_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="current_state_events_stream_ordering_idx",
|
||||
table="current_state_events",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
_BackgroundUpdates.ROOM_MEMBERSHIPS_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="room_memberships_stream_ordering_idx",
|
||||
table="room_memberships",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
_BackgroundUpdates.LOCAL_CURRENT_MEMBERSHIP_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="local_current_membership_stream_ordering_idx",
|
||||
table="local_current_membership",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
|
||||
# Handle background updates for Sliding Sync tables
|
||||
#
|
||||
self.db_pool.updates.register_background_update_handler(
|
||||
|
||||
@@ -290,16 +290,6 @@ class StateBackgroundUpdateStore(StateGroupBackgroundUpdateStore):
|
||||
STATE_GROUPS_ROOM_INDEX_UPDATE_NAME = "state_groups_room_id_idx"
|
||||
STATE_GROUP_EDGES_UNIQUE_INDEX_UPDATE_NAME = "state_group_edges_unique_idx"
|
||||
|
||||
CURRENT_STATE_EVENTS_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"current_state_events_stream_ordering_idx"
|
||||
)
|
||||
ROOM_MEMBERSHIPS_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"room_memberships_stream_ordering_idx"
|
||||
)
|
||||
LOCAL_CURRENT_MEMBERSHIP_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"local_current_membership_stream_ordering_idx"
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
database: DatabasePool,
|
||||
@@ -336,27 +326,6 @@ class StateBackgroundUpdateStore(StateGroupBackgroundUpdateStore):
|
||||
replaces_index="state_group_edges_idx",
|
||||
)
|
||||
|
||||
# These indices are needed to validate the foreign key constraint
|
||||
# when events are deleted.
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
self.CURRENT_STATE_EVENTS_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="current_state_events_stream_ordering_idx",
|
||||
table="current_state_events",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
self.ROOM_MEMBERSHIPS_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="room_memberships_stream_ordering_idx",
|
||||
table="room_memberships",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
self.db_pool.updates.register_background_index_update(
|
||||
self.LOCAL_CURRENT_MEMBERSHIP_STREAM_ORDERING_INDEX_UPDATE_NAME,
|
||||
index_name="local_current_membership_stream_ordering_idx",
|
||||
table="local_current_membership",
|
||||
columns=["event_stream_ordering"],
|
||||
)
|
||||
|
||||
async def _background_deduplicate_state(
|
||||
self, progress: dict, batch_size: int
|
||||
) -> int:
|
||||
|
||||
@@ -38,6 +38,16 @@ class _BackgroundUpdates:
|
||||
|
||||
EVENTS_JUMP_TO_DATE_INDEX = "events_jump_to_date_index"
|
||||
|
||||
CURRENT_STATE_EVENTS_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"current_state_events_stream_ordering_idx"
|
||||
)
|
||||
ROOM_MEMBERSHIPS_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"room_memberships_stream_ordering_idx"
|
||||
)
|
||||
LOCAL_CURRENT_MEMBERSHIP_STREAM_ORDERING_INDEX_UPDATE_NAME = (
|
||||
"local_current_membership_stream_ordering_idx"
|
||||
)
|
||||
|
||||
SLIDING_SYNC_PREFILL_JOINED_ROOMS_TO_RECALCULATE_TABLE_BG_UPDATE = (
|
||||
"sliding_sync_prefill_joined_rooms_to_recalculate_table_bg_update"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user