Skip to content

Commit

Permalink
Merge pull request #5635 from oasisprotocol/kostko/fix/pathbadger-ear…
Browse files Browse the repository at this point in the history
…ly-seqno-commit

go/storage/mkvs/db/pathbadger: Record sequence number early
  • Loading branch information
kostko authored Apr 10, 2024
2 parents 32a2111 + 0b8a1d4 commit 98bd192
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Empty file added .changelog/5635.trivial.md
Empty file.
6 changes: 4 additions & 2 deletions go/storage/mkvs/db/pathbadger/pathbadger.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,13 @@ func (ba *badgerBatch) Commit(root node.Root) error {
}
}

// Record sequence number for the pending (non-finalized) root.
// Record sequence number for the pending (non-finalized) root. We need to commit this before
// storing the root to make sure we can retry in case of a crash as otherwise the root can exist
// but its sequence number is not known.
if err := ba.db.meta.setPendingRootSeqNo(root.Version, rootHash, ba.seqNo); err != nil {
return fmt.Errorf("mkvs/pathbadger: failed to set pending root seqno: %w", err)
}
ba.db.meta.commit(tx)

if !ba.chunk {
// Store updated nodes (only needed until the version is finalized).
Expand All @@ -923,7 +926,6 @@ func (ba *badgerBatch) Commit(root node.Root) error {
if err := ba.bat.Flush(); err != nil {
return fmt.Errorf("mkvs/pathbadger: failed to flush batch: %w", err)
}
ba.db.meta.commit(tx)

ba.Reset()
return ba.BaseBatch.Commit(root)
Expand Down

0 comments on commit 98bd192

Please sign in to comment.