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

Basic repo cleanup #43

Open
wants to merge 19 commits into
base: dev/iavl_data_locality
Choose a base branch
from
Open

Conversation

ValarDragon
Copy link
Member

@ValarDragon ValarDragon commented Aug 20, 2022

This commit does some repository cleanup, at the moment it does:

  • Moves key format logic to its own package
  • Moves key format instantiation to its own file
  • Makes methods for getting key bytes no longer defined off nodeDB, and put it into their own file
  • Move various utils functions to a utils package
  • Deletes repair.go
  • Deletes useless ndb.roots() method, that is only used in a test to avoid checking an error lmao
  • Make an encoding package
  • Move tree-methods off of the node, to instead be defined on the tree
  • Move fast node to its own package
  • Rename node.height -> node.subtreeHeight
  • move ndb.SaveBranch to instead be tree.saveBranch which just calls a nodeDB.saveNode function.
  • Make an interface for DRY'ing the node save function with fast node save

If you want to review this, it should be reviewed commit by commit

@ValarDragon ValarDragon changed the title Some minimal repo cleanup Basic repo cleanup Aug 20, 2022
Copy link

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Could we get changelog entries for things

@@ -14,7 +14,7 @@ type ImmutableTree struct {

Using the root and the nodeDB, the ImmutableTree can retrieve any node that is a part of the IAVL tree at this version.

Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and height by querying the root node's size and height.
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and depth by querying the root node's size and depth.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Height()` which will return the tree's size and depth by querying the root node's size and depth.
Users can get information about the IAVL tree by calling getter functions such as `Size()` and `Depth()` which will return the tree's size and depth by querying the root node's size and depth.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it actually be depth though? It seems to be returning "subtree height"

@@ -29,13 +30,13 @@ func NewFastNode(key []byte, value []byte, version int64) *FastNode {

// DeserializeFastNode constructs an *FastNode from an encoded byte slice.
func DeserializeFastNode(key []byte, buf []byte) (*FastNode, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the regular Node to this package as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really feels like they belong together / grouped into the same package

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they should, just takes more refactors to get there

import dbm "github.com/tendermint/tm-db"

// Traverse all keys with a certain prefix. Return error if any, nil otherwise
func IterateThroughAllSubtreeKeys(db dbm.DB, prefix []byte, fn func(k, v []byte) error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test for this?

return nil
}

func GatherSubtreeKVPairs(db dbm.DB, prefix []byte) (keys [][]byte, values [][]byte, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

if err != nil {
return err
}
_, err = w.Write(bz)
return err
}

// encodeBytesSlice length-prefixes the byte slice and returns it.
func encodeBytesSlice(bz []byte) ([]byte, error) {
// utils.EncodeBytesSlice length-prefixes the byte slice and returns it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// utils.EncodeBytesSlice length-prefixes the byte slice and returns it.
// EncodeBytesSlice length-prefixes the byte slice and returns it.

if u == 0 {
return 1
}
return (bits.Len64(u) + 6) / 7
}

// encodeVarint writes a varint-encoded integer to an io.Writer.
func encodeVarint(w io.Writer, i int64) error {
// utils.EncodeVarint writes a varint-encoded integer to an io.Writer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// utils.EncodeVarint writes a varint-encoded integer to an io.Writer.
// EncodeVarint writes a varint-encoded integer to an io.Writer.

@@ -144,8 +144,8 @@ func encodeVarint(w io.Writer, i int64) error {
return err
}

// encodeVarintSize returns the byte size of the given integer as a varint.
func encodeVarintSize(i int64) int {
// utils.EncodeVarintSize returns the byte size of the given integer as a varint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// utils.EncodeVarintSize returns the byte size of the given integer as a varint.
// EncodeVarintSize returns the byte size of the given integer as a varint.

// TODO: Make better static guarantee in tree,
// for what nodes exist in deserialized memory, and just not getting extra nodes
// and a clear decision criteria between "no branch node", "new branch with as of yet unknown hash"
func (tree *MutableTree) saveBranch(node *Node) []byte {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this was moved but would be great to eventually cover this with a test

if node.version <= genesisVersion {
tree.ndb.resetBatch()
}
// TODO: This should be deletable? Is it just here for garbage collection purposes?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. We should probably run benchmarks before removing them. Wdyt?

tree.ndb.SaveNode(node)

// resetBatch only working on generate a genesis block
// TODO: What is this? It should almost certainly be deleted / moved elsewhere.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -109,12 +109,12 @@ func (t *ImmutableTree) Version() int64 {
return t.version
}

// Height returns the height of the tree.
// Height returns the depth of the tree.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to SubtreeHeight() and update the docs? The docs seem to say that this returns depth

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

Successfully merging this pull request may close these issues.

3 participants