Skip to content

Commit

Permalink
Don't be strict on serials when rebuilding snapshot
Browse files Browse the repository at this point in the history
It seems that we have at least one board where the stored history is
missing exactly one event (between two item.front events) and in this
case it's better to try to patch it up than to give up. The root cause
should of course be fixed as well.
  • Loading branch information
raimohanska committed Feb 15, 2024
1 parent dba1707 commit 6ac3e76
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backend/src/board-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ export async function fetchBoard(id: Id): Promise<BoardAndAccessTokens | null> {
let board = snapshot

let i = 0
let rebuildingSnapshot = false
function updateBoardWithEventChunk(chunk: BoardHistoryEntry[]) {
board = chunk.reduce((b, e) => {
i++
if (e.action === "board.setAccessPolicy") {
// Don't process access policy event when fetching board
// Access policy may have been changed in the database after the event
// And the database status is considered the master
// And the board table status is considered the master
return b
}
return boardReducer(b, e, { inplace: true, strictOnSerials: true })[0]
return boardReducer(b, e, { inplace: true, strictOnSerials: !rebuildingSnapshot })[0]
}, board)
historyEventCount += chunk.length
lastSerial = chunk[chunk.length - 1].serial ?? snapshot.serial
Expand All @@ -68,10 +69,11 @@ export async function fetchBoard(id: Id): Promise<BoardAndAccessTokens | null> {
await getBoardHistory(id, snapshot.serial, updateBoardWithEventChunk).catch(async (error) => {
console.error(error.message)
console.error(
`Error applying board history for snapshot update for board ${id}. Loop index ${i}. Rebooting snapshot...`,
`Error applying board history for snapshot update for board ${id}. Loop index ${i}. Rebooting snapshot. This may be a lossy operation.`,
)
i = 0
board = { ...snapshot, items: {}, connections: [] }
rebuildingSnapshot = true
try {
await getFullBoardHistory(id, client, updateBoardWithEventChunk)
} catch (e) {
Expand Down

0 comments on commit 6ac3e76

Please sign in to comment.