mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Fix query
This commit is contained in:
parent
8a5cd945b3
commit
0b9b5021a1
|
|
@ -220,7 +220,6 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
index := stateSnapshotData{snapshot.StateSnapshotNID, snapshot.RoomNID}
|
index := stateSnapshotData{snapshot.StateSnapshotNID, snapshot.RoomNID}
|
||||||
newsnapshots[index] = append(newsnapshots[index], blocknid)
|
newsnapshots[index] = append(newsnapshots[index], blocknid)
|
||||||
}
|
}
|
||||||
|
|
||||||
for snapshotdata, newblocks := range newsnapshots {
|
for snapshotdata, newblocks := range newsnapshots {
|
||||||
var newblocksarray pq.Int64Array
|
var newblocksarray pq.Int64Array
|
||||||
for _, b := range newblocks {
|
for _, b := range newblocks {
|
||||||
|
|
@ -252,6 +251,7 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
// If we do, this is a problem if Dendrite tries to load the snapshot as it will not exist
|
// If we do, this is a problem if Dendrite tries to load the snapshot as it will not exist
|
||||||
// in roomserver_state_snapshots
|
// in roomserver_state_snapshots
|
||||||
var count int64
|
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 {
|
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)
|
return fmt.Errorf("assertion query failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -259,15 +259,19 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
var debugEventID, debugRoomID string
|
var debugEventID, debugRoomID string
|
||||||
var debugEventTypeNID, debugStateKeyNID, debugSnapNID, debugDepth int64
|
var debugEventTypeNID, debugStateKeyNID, debugSnapNID, debugDepth int64
|
||||||
err = tx.QueryRow(
|
err = tx.QueryRow(
|
||||||
`SELECT event_id, event_type_nid, event_state_key_nid, state_snapshot_nid, depth, room_id FROM roomserver_events
|
`SELECT event_id, event_type_nid, event_state_key_nid, roomserver_events.state_snapshot_nid, depth, room_id FROM roomserver_events
|
||||||
JOIN roomserver_rooms ON roomserver_rooms.room_nid = roomserver_events.room_nid WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid,
|
JOIN roomserver_rooms ON roomserver_rooms.room_nid = roomserver_events.room_nid WHERE roomserver_events.state_snapshot_nid < $1 AND roomserver_events.state_snapshot_nid != 0`, maxsnapshotid,
|
||||||
).Scan(&debugEventID, &debugEventTypeNID, &debugStateKeyNID, &debugSnapNID, &debugDepth, &debugRoomID)
|
).Scan(&debugEventID, &debugEventTypeNID, &debugStateKeyNID, &debugSnapNID, &debugDepth, &debugRoomID)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("cannot extract debug info: %v", err)
|
||||||
|
} else {
|
||||||
logrus.Errorf(
|
logrus.Errorf(
|
||||||
"Affected row: event_id=%v room_id=%v type=%v state_key=%v snapshot=%v depth=%v",
|
"Affected row: event_id=%v room_id=%v type=%v state_key=%v snapshot=%v depth=%v",
|
||||||
debugEventID, debugRoomID, debugEventTypeNID, debugStateKeyNID, debugSnapNID, debugDepth,
|
debugEventID, debugRoomID, debugEventTypeNID, debugStateKeyNID, debugSnapNID, debugDepth,
|
||||||
)
|
)
|
||||||
logrus.Errorf("To fix this manually, run this query first then retry the migration: "+
|
logrus.Errorf("To fix this manually, run this query first then retry the migration: "+
|
||||||
"UPDATE roomserver_events SET state_snapshot_nid=0 WHERE event_id='%v'", debugEventID)
|
"UPDATE roomserver_events SET state_snapshot_nid=0 WHERE event_id='%v'", debugEventID)
|
||||||
|
}
|
||||||
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)
|
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 {
|
if err = tx.QueryRow(`SELECT COUNT(*) FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid).Scan(&count); err != nil {
|
||||||
|
|
@ -279,6 +283,9 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
err = tx.QueryRow(
|
err = tx.QueryRow(
|
||||||
`SELECT room_id, state_snapshot_nid, last_event_sent_nid FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid,
|
`SELECT room_id, state_snapshot_nid, last_event_sent_nid FROM roomserver_rooms WHERE state_snapshot_nid < $1 AND state_snapshot_nid != 0`, maxsnapshotid,
|
||||||
).Scan(&debugRoomID, &debugSnapNID, &debugLastEventNID)
|
).Scan(&debugRoomID, &debugSnapNID, &debugLastEventNID)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("cannot extract debug info: %v", err)
|
||||||
|
} else {
|
||||||
logrus.Errorf(
|
logrus.Errorf(
|
||||||
"Affected row: room_id=%v snapshot=%v last_sent=%v",
|
"Affected row: room_id=%v snapshot=%v last_sent=%v",
|
||||||
debugRoomID, debugSnapNID, debugLastEventNID,
|
debugRoomID, debugSnapNID, debugLastEventNID,
|
||||||
|
|
@ -286,6 +293,7 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
|
||||||
logrus.Errorf("To fix this manually, run this query first then retry the migration: "+
|
logrus.Errorf("To fix this manually, run this query first then retry the migration: "+
|
||||||
"UPDATE roomserver_rooms SET state_snapshot_nid=0 WHERE room_id='%v'", debugRoomID)
|
"UPDATE roomserver_rooms SET state_snapshot_nid=0 WHERE room_id='%v'", debugRoomID)
|
||||||
logrus.Errorf("Running this UPDATE will cause the room in question to become unavailable on this server. Leave and re-join the room afterwards.")
|
logrus.Errorf("Running this UPDATE will cause the room in question to become unavailable on this server. Leave and re-join the room afterwards.")
|
||||||
|
}
|
||||||
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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue