Skip to content

Commit

Permalink
Dev to Main (#37)
Browse files Browse the repository at this point in the history
* try fixing race

* Revert "try fixing race"

This reverts commit 02ff901.

* using lock for set child and get child

* using locks only for set child and get child

* fix nil mu

* fix delete

* using locks to set attribute of node

* fix memdb tests

* tracking channel of child changes

* removed process lazy redundant

* fix nil check

* Fix get watch bug

* go fmt
  • Loading branch information
absolutelightning authored May 28, 2024
1 parent db38a35 commit 2e481d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ func (t *Txn[T]) removeChild4(n Node[T], c byte) Node[T] {
// Remove nodes with only a single child
if n.getNumChildren() == 1 {
// Is not leaf
newChildZero := n.getChildren()[0].clone(true, false)
t.trackChannel(n)
newChildZero := n.getChild(0).clone(true, false)
if !n.getChildren()[0].isLeaf() {
// Concatenate the prefixes
prefix := int(n.getPartialLen())
Expand Down Expand Up @@ -403,9 +404,7 @@ func (t *Txn[T]) removeChild16(n Node[T], c byte) Node[T] {

if n.getNumChildren() == 3 {
n.incrementLazyRefCount(-1)
if t.trackMutate {
t.trackChannel(n)
}
t.trackChannel(n)
newNode := t.allocNode(node4)
n4 := newNode.(*Node4[T])
t.copyHeader(newNode, n)
Expand All @@ -429,9 +428,7 @@ func (t *Txn[T]) removeChild48(n Node[T], c uint8) Node[T] {

if n.getNumChildren() == 12 {
n.incrementLazyRefCount(-1)
if t.trackMutate {
t.trackChannel(n)
}
t.trackChannel(n)
newNode := t.allocNode(node16)
t.copyHeader(newNode, n)
child := 0
Expand All @@ -457,9 +454,7 @@ func (t *Txn[T]) removeChild256(n Node[T], c uint8) Node[T] {
// trashing if we sit on the 48/49 boundary
if n.getNumChildren() == 37 {
n.incrementLazyRefCount(-1)
if t.trackMutate {
t.trackChannel(n)
}
t.trackChannel(n)
newNode := t.allocNode(node48)
t.copyHeader(newNode, n)

Expand Down
2 changes: 1 addition & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (t *RadixTree[T]) iterativeSearch(key []byte) (T, bool, <-chan struct{}) {
n = child
depth++
}
return zero, false, nil
return zero, false, watch
}

func (t *RadixTree[T]) DeletePrefix(key []byte) (*RadixTree[T], bool) {
Expand Down
2 changes: 1 addition & 1 deletion txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (t *Txn[T]) recursiveDelete(node Node[T], key []byte, depth int) (Node[T],
t.trackChannel(oldRef)
}

t.trackChannel(child)
t.trackChannel(child)

if doClone {
node = t.writeNode(node)
Expand Down

0 comments on commit 2e481d4

Please sign in to comment.