Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background job to clear unreferenced state groups #18150

Open
erikjohnston opened this issue Feb 10, 2025 · 6 comments · May be fixed by #18154
Open

Add background job to clear unreferenced state groups #18150

erikjohnston opened this issue Feb 10, 2025 · 6 comments · May be fixed by #18154

Comments

@erikjohnston
Copy link
Member

After fixing #9406 and #17937, we still have a bunch of unreferenced state groups in the DB which point to the full state, causing lots of unnecessary DB usage. We should add a background job to go and delete unreferenced state groups.

Note that we can still have new unreferenced state groups, just that when we purge history we won't de-delta the state group entries and instead delete them.

A one-off background job to delete unreferenced state groups would:

  1. Record the current max state group
  2. Each run would look at the next N state groups (in ascending order) via state_groups table, and check if there are any unreferenced ones. Note that we need to check both event_to_state_groups and state_group_edges tables.
  3. Call _find_unreferenced_groups on any unreferenced state groups to get others that can be deleted if the given state group is deleted.
  4. Call mark_state_groups_as_pending_deletion to schedule them for deletion

I'm also wondering if instead of having this as a one off job we do this periodically to catch new unreferenced state groups.

@devonh
Copy link
Member

devonh commented Feb 12, 2025

While implementing this I noticed that when the deletion task runs, it doesn't clean up the state_groups_pending_deletion table. It leaves the entries in there.

We'll need to address that as well, otherwise that table will grow endlessly.

@devonh
Copy link
Member

devonh commented Feb 12, 2025

Also - should we be cleaning up any state_group_edges that are dangling after the deletion as well?

@devonh
Copy link
Member

devonh commented Feb 12, 2025

@erikjohnston thoughts on cleaning up state_groups_pending_deletion & state_group_edges tables? ^

@pmaier1
Copy link

pmaier1 commented Feb 13, 2025

Any idea which Synapse release we would be targeting for this? (re https://github.com/element-hq/backend-internal/issues/75#issuecomment-2653987772)

@erikjohnston
Copy link
Member Author

@erikjohnston thoughts on cleaning up state_groups_pending_deletion & state_group_edges tables? ^

Err, yes they should be cleaned up too

@devonh
Copy link
Member

devonh commented Feb 14, 2025

State Group table cleanup PR: #18165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants