Reset invalid state snapshots for events during state storage refactor migration (#2209)

This should help with #2204. We can't do this for rooms, only events.
This commit is contained in:
Neil Alexander 2022-02-21 15:25:54 +00:00 committed by GitHub
parent a386fbed2c
commit a02dd7721d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

View file

@ -179,7 +179,17 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
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)
var res sql.Result
var c int64
res, err = tx.Exec(`UPDATE roomserver_events SET state_snapshot_nid = 0 WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID)
if err != nil && err != sql.ErrNoRows {
return fmt.Errorf("failed to reset invalid state snapshots: %w", err)
}
if c, err = res.RowsAffected(); err != nil {
return fmt.Errorf("failed to get row count for invalid state snapshots updated: %w", err)
} else if c != count {
return fmt.Errorf("expected to reset %d event(s) but only updated %d event(s)", count, c)
}
}
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, oldMaxSnapshotID).Scan(&count); err != nil {
return fmt.Errorf("assertion query failed: %s", err)