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

Avoid brand new rooms in delete_old_current_state_events #7854

Merged
merged 3 commits into from
Jul 15, 2020

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jul 15, 2020

When considering rooms to clean up in delete_old_current_state_events, skip rooms which we are creating, which otherwise look a bit like rooms we have left.

Fixes #7834.

When considering rooms to clean up in `delete_old_current_state_events`, skip
rooms which we are creating, which otherwise look a bit like rooms we have
left.

Fixes #7834.
@richvdh richvdh requested a review from a team July 15, 2020 11:29
Comment on lines 367 to 377
# exclude rooms where we have active members
sql = """
SELECT room_id
FROM current_state_events
FROM local_current_membership
WHERE
room_id > ? AND room_id <= ?
AND type = 'm.room.member'
AND membership = 'join'
AND state_key LIKE ?
GROUP BY room_id
"""

txn.execute(sql, (last_room_id, room_ids[-1], "%:" + self.server_name))

txn.execute(sql, (last_room_id, room_ids[-1]))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are unrelated, but I thought I may as well simplify it while I was here.

synapse/storage/data_stores/main/state.py Outdated Show resolved Hide resolved
Comment on lines 401 to 406
creating_rooms = to_delete.difference(row[0] for row in txn)
logger.info("skipping rooms which are being deleted: %s", creating_rooms)

left_rooms = set(room_ids) - joined_room_ids
to_delete.difference_update(creating_rooms)

logger.info("Deleting current state left rooms: %r", left_rooms)
logger.info("Deleting current state left rooms: %r", to_delete)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to walk through the logic here:

  1. The returned rooms are ones that have forward extremities that are not the create event (i.e. they are rooms that are not being created currently).
  2. to_delete is modified to remove the above, meaning we're left with the rooms that are being created (saved as creating_rooms).
  3. to_delete is modified to remove creating_rooms, leaving only the rooms which are not being currently created. (I think this is equivalent to the intersection of the result of step 1 and to_delete at the time of step 1, but that doesn't give you something nice to log, unfortunately.)

Not sure if it matters much, but I find the set operations easier to read using operators, e.g. to_delete -= creating_rooms (although this only works if they're both sets, I think).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, your logic is correct.

I'll add some comments to clarify.

Not sure if it matters much, but I find the set operations easier to read using operators, e.g. to_delete -= creating_rooms (although this only works if they're both sets, I think).

agreed, and the fact that some of these aren't sets is the reason I had to use the wordy version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added comments look great! 👍

@richvdh richvdh merged commit a57df9b into develop Jul 15, 2020
@richvdh richvdh deleted the rav/fix_remove_left_rooms_race branch July 15, 2020 17:33
babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit 'a973bcb8a':
  Add some tiny type annotations (#7870)
  Remove obsolete comment.
  Ensure that calls to `json.dumps` are compatible with the standard library json. (#7836)
  Avoid brand new rooms in `delete_old_current_state_events` (#7854)
  Allow accounts to be re-activated from the admin APIs. (#7847)
  Fix tests
  Fix typo
  Newsfile
  Use get_users_in_room rather than state handler in typing for speed
  Fix client reader sharding tests (#7853)
  Convert E2E key and room key handlers to async/await. (#7851)
  Return the proper 403 Forbidden error during errors with JWT logins. (#7844)
  remove `retry_on_integrity_error` wrapper for persist_events (#7848)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants