Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport - write DAG XOR tree consistency fixes to disk #3363

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading