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

Make iavl.Tree unexported #87

Closed
liamsi opened this issue Jul 12, 2018 · 6 comments
Closed

Make iavl.Tree unexported #87

liamsi opened this issue Jul 12, 2018 · 6 comments
Assignees

Comments

@liamsi
Copy link
Contributor

liamsi commented Jul 12, 2018

The VersionedTree should be sufficient for people to work with. We currently use the Tree only in the cosmos-sdk iavlstore. It would be nice if we could change this there. It would further simplify the exposed API.

There are some test-cases showing even our devs are confused by how to use the tree vs. the versioned tree: #50

cc @jlandrews

also related #62

@silasdavis
Copy link
Contributor

This would break my usage, see where we need access to the tree to store a read tree: https://github.com/hyperledger/burrow/blob/develop/execution/state.go#L202-L218

Also I think IAVL could do with more not fewer things exported. It is a low-level building block and there are various things I have not be able to do because the policy around exporting is in my opinion overly conservative. For example, the nodedb. The Tree itself can be used standalone, and it seem odd to me that VersionedTree does not provide a straightforward way to get previous versions of the Tree. See also my other issue: #68. I do understand the desire to limit the public API for a project, but I think for a building block like IAVL supporting extension and composability (in ways that you may not have in mind when writing the code) is a higher ideal in the case of a library like this.

I think a small amount of additional documentation is sufficient to clear up any confusion.

@ebuchman
Copy link
Member

I think we probably need to package up the different pieces ala #62 and expose solid APIs from each package

@UnitylChaos
Copy link
Contributor

@silasdavis So it seems to me like the most straightforward solution here would be to build a well structured way to get immutable snapshots of the tree at specific stored versions, in such a way that they can be loaded on demand and not leak memory. Then we would make Tree just an internal interface for updating the VersionedTree and we could make a separate read only interface which had all the same features of Tree, like iterators and proofs.

I agree on the motivation of wanting to simplify the exposed API, and also can see the downside of doing that in situations where the exposed API is not enough for a particular use case. My view of the current intended API is that VersionedTree provides a mutable map primitive, with the ability to persist particular configurations to disk with incremented version numbers. It's entirely linear though, we can't load an old version, make new changes and save that as a different version n+1. In that frame, it shouldn't be possible to gain a mutable reference to an old version, it should only be possible to load the current mutable version, or to load immutable snapshots of old versions.

@silasdavis
Copy link
Contributor

@jlandrews immutable snapshots would satisfy my current use case yes, but still Tree is a useful type and I I think it's better to have it available - perhaps you can restructure VersionedTree to make sure its internal Tree fields are suitably hidden.

I do agree with you on:

it shouldn't be possible to gain a mutable reference to an old version, it should only be possible to load the current mutable version, or to load immutable snapshots of old versions

Having VersionedTree work as an append-only thing with no rewriting history is a nice feature for VersionedTree

@silasdavis
Copy link
Contributor

I think this is resolved.

@liamsi
Copy link
Contributor Author

liamsi commented Aug 29, 2018

Agreed

@liamsi liamsi closed this as completed Aug 29, 2018
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

4 participants