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

Purge Room API fails to remove all rows from state_groups_state #6566

Closed

Description

@Ralith

Description

Invoking the /_synapse/admin/v1/purge_room endpoint on a room removes many, but not all, rows from state_groups_state (other tables not investigated).

Steps to reproduce

  • select count(*) as num_rows from state_groups_state where room_id = '!PcCidzjUKXHKImhTrB:matrix.org'; => 159049493
  • curl -XPOST "https://example.com/_synapse/admin/v1/purge_room?access_token=$ACCESS_TOKEN" -d "{ \"room_id\": \"!PcCidzjUKXHKImhTrB:matrix.org\" }" => {}
  • select count(*) as num_rows from state_groups_state where room_id = '!PcCidzjUKXHKImhTrB:matrix.org'; => 997223

Version information

  • Homeserver: ralith.com

If not matrix.org:

  • Version: 1.6.1

  • Install method: NixOS module

  • Platform: NixOS on dedicated atom server

Activity

  1. Ralith commented on Dec 18, 2019

    @Ralith
    ContributorAuthor

    Furthermore, multiple attempts to purge !QtykxKocfZaZOUrTwp:matrix.org fail to remove any rows, even as each attempt indicates success. There are more than 4 million!

  2. richvdh commented on Dec 24, 2019

    @richvdh
    Member

    I assume it has managed to remove all the rows from state_groups?

    The problem is that state_groups_state lacks an index on room_id so we can't just delete the rows from state_groups_state; instead we look up the state groups to delete from state_groups and then delete the relevant groups.

    So that explains why it still doesn't do anything on a second attempt. What it doesn't explain is why it fails on the first attempt. There are two possibilities:

    • the relevant state groups lack entries in state_groups for some reason, so we don't know that we have to purge the rows from state_groups_state
    • the purge transaction got as far as deleting the rows from state_groups, but then failed to remove the rows from state_groups_state.

    Logs from the first purge attempt would be useful in determining which of these is the problem.

  3. richvdh commented on Mar 17, 2020

    @richvdh
    Member

    closing this pending the information needed to investigate.

  4. Ralith commented on Mar 17, 2020

    @Ralith
    ContributorAuthor

    What recourse is available for cleaning up the millions of orphaned rows?

  5. richvdh commented on Jul 9, 2020

    @richvdh
    Member

    @Ralith : are the orphaned rows in question in (a) state_groups or (b) state_groups_state ?

    For case (a), https://github.com/erikjohnston/synapse-find-unreferenced-state-groups is a thing that helps find unreferenced state groups and clear them out.

    For case (b) (the rows have gone from state_groups but there are still orphaned rows in state_groups_state), you might be able to build a list of such rows with a SELECT query and then run a series of DELETEs.

  6. Ralith commented on Jul 9, 2020

    @Ralith
    ContributorAuthor

    I have rows for both ostensibly-purged rooms in state_groups, but a comparatively trivial number: only 365 for !PcCidzjUKXHKImhTrB:matrix.org, and 1531 for '!QtykxKocfZaZOUrTwp:matrix.org'. I'll try Erik's tool, thanks! From the warning, I gather it's safe to run deletes for orphaned rooms, or when synapse is shut down, but generally not for live rooms when synapse is running?

  7. richvdh commented on Jul 9, 2020

    @richvdh
    Member

    yes.

  8. rettichschnidi commented on Jun 29, 2021

    @rettichschnidi
    Contributor

    For all victims of the spam wave in «Matrix HQ»: Using synapse-find-unreferenced-state-groups (still) works!

    After closing down Matrix HQ (!OGEhHVWSdvArJzumhm:matrix.org) using Synapse Admin on my homeserver, I was left with 2.5M rows for this room in the state_groups_state stable. Using synapse-find-unreferenced-state-groups deleted all of those. Did not shut down Synapse while doing so, as the room got deleted before already.

  9. lnicola commented on May 20, 2022

    @lnicola

    I'm seeing about 700K rows in current_state_delta_stream and more than 40M rows in state_groups_state for rooms that should have been purged (ref. #12730). At some point purging failed because of a serialization error.

    Unfortunately, synapse-find-unreferenced-state-groups doesn't seem to work. I can delete the rows manually, but I don't know exactly what tables I should be looking at.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions