From 0b8a1d4b3596be571de7fcc832eeee44fc54b2c1 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 10 Apr 2024 18:07:56 +0200 Subject: [PATCH] go/storage/mkvs/db/pathbadger: Record sequence number early We need to commit the sequence number for the pending (non-finalized) root early on. Otherwise a crash could result in the root being committed but its sequence number is not known so finalization would fail. The issue was discovered by our long-term E2E tests. --- .changelog/5635.trivial.md | 0 go/storage/mkvs/db/pathbadger/pathbadger.go | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .changelog/5635.trivial.md diff --git a/.changelog/5635.trivial.md b/.changelog/5635.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/go/storage/mkvs/db/pathbadger/pathbadger.go b/go/storage/mkvs/db/pathbadger/pathbadger.go index af3907b25cd..afcedcadc13 100644 --- a/go/storage/mkvs/db/pathbadger/pathbadger.go +++ b/go/storage/mkvs/db/pathbadger/pathbadger.go @@ -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). @@ -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)