You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can make app development cleaner by removing the need for the client to track persistence. This information is needed to avoid panics that occure running tree.Save on a non-persistent tree.
Another, maybe simpler, solution is simple to modify IAVLTree.Save() so it is safe to call for all trees. Save() not only saves the tree to the db, but also recalculates the hash if needed, so we cannot make it a no-op. Something like this:
func (t *IAVLTree) Save() []byte {
if t.root == nil {
return nil
}
if t.ndb == nil {
// this line comes from IAVLNode.save
if t.root.hash == nil {
t.root.hash, _ = t.root.hashWithCount(t)
}
} else {
t.root.save(t)
t.ndb.Commit()
}
return t.root.hash
}
This lets us do the right thing without making the caller do checks (which may be forgotten in some implementation)
@zramsay commented on Wed Aug 16 2017
@rigelrozanski commented on Wed Jan 11 2017
This can make app development cleaner by removing the need for the client to track persistence. This information is needed to avoid panics that occure running tree.Save on a non-persistent tree.
@ethanfrey commented on Thu Jan 12 2017
Another, maybe simpler, solution is simple to modify
IAVLTree.Save()
so it is safe to call for all trees.Save()
not only saves the tree to the db, but also recalculates the hash if needed, so we cannot make it a no-op. Something like this:This lets us do the right thing without making the caller do checks (which may be forgotten in some implementation)
@ebuchman commented on Thu Jan 12 2017
Yeh that sounds better, let's let Save do the work even if there's no backing so callers don't have to worry :)
The text was updated successfully, but these errors were encountered: