Skip to content

Commit

Permalink
write DAG XOR tree consistency fixes to disk (#3363)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Sep 13, 2024
1 parent ae0631d commit 405474a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions network/dag/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (f *xorTreeRepair) checkPage() {
if err != nil {
return err
}
err = f.state.xorTree.writeWithoutLock(txn)
if err != nil {
return err
}
log.Logger().Warnf("detected XOR tree mismatch for page %d, fixed using recalculated values", f.currentPage)
}

Expand Down
10 changes: 8 additions & 2 deletions network/dag/treestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ func (store *treeStore) write(tx stoabs.WriteTx, transaction Transaction) error
store.mutex.Lock()
defer store.mutex.Unlock()

writer := tx.GetShelfWriter(store.bucketName)

store.tree.Insert(transaction.Ref(), transaction.Clock())
return store.writeWithoutLock(tx)
}

// writeWithoutLock writes all current changes in the treeStore to disk.
// It is the callers responsibility to prevent race conditions on treeStore. Use treeStore.mutex if needed.
func (store *treeStore) writeWithoutLock(tx stoabs.WriteTx) error {
dirties, orphaned := store.tree.Updates()
store.tree.ResetUpdates() // failure after this point results in rollback anyway

writer := tx.GetShelfWriter(store.bucketName)

// delete orphaned leaves
for _, orphan := range orphaned { // always zero
err := writer.Delete(clockToKey(orphan))
Expand Down

0 comments on commit 405474a

Please sign in to comment.