Skip to content

Commit

Permalink
Revert "refactor: Alternative way to set the initialversion root node"
Browse files Browse the repository at this point in the history
This reverts commit 6365e4e.

Adding this just so we have reference of the other option
  • Loading branch information
drklee3 committed Aug 16, 2024
1 parent a6d56f9 commit 0e0bd3e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,23 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
if err := tree.ndb.SaveRoot(version, tree.root.nodeKey); err != nil {
return nil, 0, err
}

// Delete the root node to be replaced below with new key. Need to
// delete this otherwise there will be two keys (version, 1) and
// (version, 0) below pointing at the same node.
if err := tree.ndb.deleteFromPruning(tree.ndb.nodeKey(tree.root.nodeKey.GetKey())); err != nil {
return nil, 0, err
}

// Use a nonce of 0 to match pruning behavior that hides it from
// the version list.
// Mark the root node as hidden, same as how pruning handles.
// Even if with the reference node via SaveRoot() above points at
// (version, 1), LoadVersion still checks (version, 0) if it exists.
tree.root.nodeKey.nonce = 0
if err := tree.ndb.SaveNode(tree.root); err != nil {
return nil, 0, err
}
}
}

Expand Down Expand Up @@ -1051,9 +1068,6 @@ func (tree *MutableTree) balance(node *Node) (newSelf *Node, err error) {
func (tree *MutableTree) saveNewNodes() error {
nonce := uint32(0)
newNodes := make([]*Node, 0)

isInitialVersion := tree.ndb.opts.InitialVersion > 1 && tree.WorkingVersion() == int64(tree.ndb.opts.InitialVersion)

var recursiveAssignKey func(*Node) ([]byte, error)
recursiveAssignKey = func(node *Node) ([]byte, error) {
if node.nodeKey != nil {
Expand All @@ -1067,12 +1081,6 @@ func (tree *MutableTree) saveNewNodes() error {
nonce: nonce,
}

// Save the root node at InitialVersion to nonce of 0 to hide it from
// the version list.
if isInitialVersion && nonce == 1 {
node.nodeKey.nonce = 0
}

var err error
// the inner nodes should have two children.
if node.subtreeHeight > 0 {
Expand Down

0 comments on commit 0e0bd3e

Please sign in to comment.