Skip to content

Commit

Permalink
fix: Prevent nil panic on reading tree.root.nodeKey on empty tree
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Aug 15, 2024
1 parent 882046b commit 2d28d39
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,18 +771,18 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
return nil, 0, err
}
}
}

// Addition to node version patch for backwards compatibility:
// This is to resolve queries at InitialVersion, loading the tree at
// InitialVersion when the root node has version 1.
// Note: version != nodekey.Version due to patch.
if tree.ndb.opts.InitialVersion > 0 && version == int64(tree.ndb.opts.InitialVersion) {
// SaveRoot is meant for saving a tree when there are no updates, which
// simply creates a reference node to the root node. We reuse this to
// create a reference node from InitialVersion -> 1 (root node).
if err := tree.ndb.SaveRoot(version, tree.root.nodeKey); err != nil {
return nil, 0, err
// Addition to node version patch for backwards compatibility:
// This is to resolve queries at InitialVersion, loading the tree at
// InitialVersion when the root node has version 1.
// Note: version != nodekey.Version due to patch.
if tree.ndb.opts.InitialVersion > 0 && version == int64(tree.ndb.opts.InitialVersion) {
// SaveRoot is meant for saving a tree when there are no updates, which
// simply creates a reference node to the root node. We reuse this to
// create a reference node from InitialVersion -> 1 (root node).
if err := tree.ndb.SaveRoot(version, tree.root.nodeKey); err != nil {
return nil, 0, err
}
}
}

Expand Down

0 comments on commit 2d28d39

Please sign in to comment.