Skip to content

Commit

Permalink
part: Fix returned old value for non-leaf nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Maki <[email protected]>
  • Loading branch information
joamaki committed Apr 29, 2024
1 parent 3c55b11 commit bab8a70
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions part/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ func (txn *Txn[T]) insert(root *header[T], key []byte, value T) (oldValue T, had
if bytes.HasPrefix(key, this.prefix) {
key = key[len(this.prefix):]
if len(key) == 0 {
leaf := this.getLeaf()
if leaf != nil {
oldValue = leaf.value
hadOld = true
}
if this.isLeaf() {
// This is a leaf node and we just cloned it. Update the value.
leaf := this.getLeaf()
oldValue = leaf.value
leaf.value = value
hadOld = true
} else {
// This is a non-leaf node, create/replace the existing leaf.
this.setLeaf(newLeaf(txn.opts, key, fullKey, value))
Expand Down

0 comments on commit bab8a70

Please sign in to comment.