-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
state_groups
(& state_groups_state
& state_group_edges
) are not fully purged alongside the rooms
#12821
Comments
state_groups
(& _state
) does not appear to be purged alongside the roomsstate_groups
(& state_groups_state
) does not appear to be purged alongside the rooms
Context: Related question: Can I just delete these rows (that reference rooms that my homeserver isnt a part of, and have been purged long ago) with no effect? Am I supposed to? |
Andrew noticed that there's a note about this in the code... synapse/tests/rest/admin/test_room.py Line 2490 in 02d7085
|
After clearing the tables with non-referenced room names, it seems to have cleared up 4GB of disk space (from 44GB to 40GB, that specific table 12GB -> 8GB) |
We do seem to delete it now though: synapse/synapse/storage/databases/state/store.py Lines 667 to 676 in 19d79b6
I wonder if the test would now pass if you check if those are gone? (Maybe we need a background update or something to clean-up?) |
possibly related to #3364 (comment) |
I re-ran the tests with the following line uncommented: synapse/tests/rest/admin/test_room.py Line 2490 in 02d7085
and a bunch of them failed with
So it looks like we're still missing something. |
It appears that deleting and purging a room can create an orphaned state group when a Consider the following: a room is created. Three events are sent into the graph TD;
A[m.room.create] --> B[m.room.member]
B --> C[m.room.power_levels]
After this, several events are created and then batched up to be persisted. In the current scenario, these are graph TD;
A[m.room.create] --> B[m.room.member]
B --> C[m.room.power_levels]
C -->D[m.room.join_rules]
C -->E[m.room_history_visibility]
At this point, the state_groups_state table looks like this:
Each event has a separate state group, which makes sense as each event is a state event. Next the delete room code path begins. As part of the shutdown room code, a leave event is created, with two previous events, the current forward graph TD;
A[m.room.create] --> B[m.room.member]
B --> C[m.room.power_levels]
C -->D[m.room.join_rules]
C -->E[m.room_history_visibility]
E -->F[m.room.member]
D -->F[m.room.member]
And the state_groups_state table looks like this:
You can see that now the same history visibility group event is recorded in two different state groups.
results in |
Any opinions on whether this is safe and not corrupting the database even more? |
I think this is basically a duplicate of #3364 for the record.
provided you're sure that all other references to the room have been purged from the database, yes it should be safe to remove the unreferenced rows from |
@richvdh the query you provide in that issue for checking if you are affected or not doesn't give me a count in the thousands (it's around 500). |
How would I determine if all references have been purged? Asking because there are many tables with a column named room_id: $ sed -n '/CREATE TABLE/{:start /;/!{N;b start};/room_id/p}' synapse-schema.sql | grep "CREATE TABLE" | cut -c 21- | tr -d \( | grep -v -e state_groups_state -e state_groups
appservice_room_list
batch_events
blocked_rooms
current_state_delta_stream
current_state_events
destination_rooms
device_lists_changes_in_room
e2e_room_keys
event_auth
event_auth_chain_to_calculate
event_backward_extremities
event_edges
event_forward_extremities
event_json
event_labels
event_push_actions
event_push_summary
event_reports
event_search
event_txn_id
events
federation_inbound_events_staging
insertion_event_edges
insertion_event_extremities
insertion_events
local_current_membership
partial_state_events
partial_state_rooms
partial_state_rooms_servers
pusher_throttle
receipts_graph
receipts_linearized
room_account_data
room_aliases
room_depth
room_memberships
room_retention
room_stats_current
room_stats_earliest_token
room_stats_state
room_tags
room_tags_revisions
rooms
state_events
stream_ordering_to_exterm
user_directory
users_in_public_rooms
users_who_share_private_rooms Would I need to check every single table? |
@rettichschnidi check the |
@richvdh Thanks for the answer. Just did so, reduced the database from 75 to below 35 GB. Follow up question: When deleting a room, not just |
So, two months later, still with retention enabled, the DB grew again to 76 GB. The room In order to shrink my DB once gain, I did the following:
I joined using
As a result of this, my DB shrunk to 16 GB (on the file system).
Open question: Some other tables also return small to big numbers, an I am wondering if it is save to delete the found entries?
The other tables being:
|
@rettichschnidi |
I have not experienced any myself and also have not gotten any complains yet. Will update here if this changes. |
Thank you for testing this. We did that too and so far so good. We even went from about 115 GB down to 13 GB. |
Very nice @rettichschnidi! |
state_groups
(& state_groups_state
) does not appear to be purged alongside the roomsstate_groups
(& state_groups_state
) are not fully purged alongside the rooms
state_groups
(& state_groups_state
) are not fully purged alongside the roomsstate_groups
(& state_groups_state
& state_group_edges
) are not fully purged alongside the rooms
There are also references of
In addition to @rettichschnidi i made the following draft: DELETE FROM
cache_invalidation_stream_by_instance as inv
INNER JOIN current_state_delta_stream as stream ON inv.stream_id = stream.stream_id
WHERE room_id IN (
SELECT
DISTINCT(state_groups.room_id) AS room_id_gone
FROM
state_groups
LEFT JOIN events USING(room_id)
WHERE
events.room_id IS NULL
GROUP BY
room_id_gone
)
AND cache_func = 'have_seen_event'; |
I am far from convinced those columns are referring to the same "stream", though I haven't actually checked. Both of those tables can be periodically cleaned out anyway; see #5888 and #13456. |
@richvdh I didn't really find the comprehensive documentation how synapse stores data and why, but i've give some thoughts. Events (joining, leaving, messages etc) are stored in the tables IMO every entry in the following tables, that doesn't have a related event_id in
|
While investigating my database size, I found that
state_groups_state
andstate_groups
hold many stale entries that reference old rooms that have long since been removed fromrooms
and all related events tables.It appears these are not purged alongside other tables, particularly via the
DELETE _synapse/admin/v1/rooms/{room_id}
API (withpurge: true
)Version information
Version: Synapse 1.57.1
Install method: Docker image
Platform: Linux (Debian)
The text was updated successfully, but these errors were encountered: