Skip to content

Commit

Permalink
Migration to clean up bogus rooms
Browse files Browse the repository at this point in the history
These rooms have invalid state snapshots, leading to correctness
problems. The existence of such snapshots leaves us open to performance
problems due to gappy state updates.

We have prevented invalid state snapshots from being formed (#255, #266)
in the future. The remaining hole is to discard existing invalid
snapshots.

Closes #256.
David Robertson committed Aug 22, 2023
1 parent 6f26495 commit 7a70d47
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions state/migrations/20230822174049_bogus_snapshot_cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- +goose Up
-- This migration runs a one-time cleanup job to delete rooms with dodgy state snapshots.
-- A room is dodgy if its current snapshot lacks a create event.
BEGIN;

CREATE TEMPORARY TABLE bogus_rooms AS (
SELECT room_id, current_snapshot_id
FROM syncv3_rooms
WHERE room_id NOT IN (
SELECT room_id
FROM syncv3_events
WHERE event_type = 'm.room.create'
AND state_key = ''
)
);

DELETE
FROM syncv3_events
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

DELETE
FROM syncv3_snapshots
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

DELETE
FROM syncv3_rooms
WHERE room_id IN (SELECT room_id FROM bogus_rooms);

COMMIT;

-- +goose Down
-- downgrading is a no-op.

0 comments on commit 7a70d47

Please sign in to comment.