mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
* db migration: fix #1844 and add additional assertions - Migration scripts will now check to see if there are any unconverted snapshot IDs and fail the migration if there are any. This should prevent people from getting a corrupt database in the event the root cause is still unknown. - Add an ORDER BY clause when doing batch queries in the postgres migration. LIMIT and OFFSET without ORDER BY are undefined and must not be relied upon to produce a deterministic ordering (e.g row order). See https://www.postgresql.org/docs/current/queries-limit.html * Linting Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
parent
e2b6a90d90
commit
c849e74dfc
2 changed files with 45 additions and 3 deletions
|
@ -119,11 +119,15 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
|||
_roomserver_state_snapshots
|
||||
JOIN _roomserver_state_block ON _roomserver_state_block.state_block_nid = ANY (_roomserver_state_snapshots.state_block_nids)
|
||||
WHERE
|
||||
_roomserver_state_snapshots.state_snapshot_nid = ANY ( SELECT DISTINCT
|
||||
_roomserver_state_snapshots.state_snapshot_nid = ANY (
|
||||
SELECT
|
||||
_roomserver_state_snapshots.state_snapshot_nid
|
||||
FROM
|
||||
_roomserver_state_snapshots
|
||||
LIMIT $1 OFFSET $2)) AS _roomserver_state_block
|
||||
ORDER BY _roomserver_state_snapshots.state_snapshot_nid ASC
|
||||
LIMIT $1 OFFSET $2
|
||||
)
|
||||
) AS _roomserver_state_block
|
||||
GROUP BY
|
||||
state_snapshot_nid,
|
||||
room_nid,
|
||||
|
@ -202,6 +206,23 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
|||
}
|
||||
}
|
||||
|
||||
// By this point we should have no more state_snapshot_nids below maxsnapshotid in either roomserver_rooms or roomserver_events
|
||||
// If we do, this is a problem if Dendrite tries to load the snapshot as it will not exist
|
||||
// in roomserver_state_snapshots
|
||||
var count int64
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_events WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
return fmt.Errorf("%d events exist in roomserver_events which have not been converted to a new state_snapshot_nid; this is a bug, please report", count)
|
||||
}
|
||||
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||
return fmt.Errorf("assertion query failed: %s", err)
|
||||
}
|
||||
if count > 0 {
|
||||
return fmt.Errorf("%d rooms exist in roomserver_rooms which have not been converted to a new state_snapshot_nid; this is a bug, please report", count)
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(`
|
||||
DROP TABLE _roomserver_state_snapshots;
|
||||
DROP SEQUENCE roomserver_state_snapshot_nid_seq;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue