Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/18509.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `KeyError` on background updates when using split main/state databases.
2 changes: 1 addition & 1 deletion rust/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")
}
}

Expand Down
21 changes: 21 additions & 0 deletions synapse/storage/databases/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,27 @@ def __init__(
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(
Expand Down
31 changes: 0 additions & 31 deletions synapse/storage/databases/state/bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -336,27 +326,6 @@ def __init__(
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:
Expand Down
10 changes: 10 additions & 0 deletions synapse/types/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Loading