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

Generate IsPersistent method #44

Open
zramsay opened this issue Aug 16, 2017 · 0 comments
Open

Generate IsPersistent method #44

zramsay opened this issue Aug 16, 2017 · 0 comments

Comments

@zramsay
Copy link

zramsay commented Aug 16, 2017

@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:

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)


@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant