From db38a354a0933bc8154375fe0635bb2ba7449cc8 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Tue, 28 May 2024 19:41:13 +0530 Subject: [PATCH] Dev to Maiin (#36) * fix mod * try fixing race * Revert "try fixing race" This reverts commit 02ff901eaa1f51d4c484e1377f4487c779fdc346. * using lock for set child and get child * using locks only for set child and get child * fix nil mu * fix delete * fix delete * using locks to set attribute of node * fix memdb tests * tracking channel of child changes * removed process lazy redundant * fix nil check --- txn.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/txn.go b/txn.go index 72b2e2d..42c36b1 100644 --- a/txn.go +++ b/txn.go @@ -121,7 +121,6 @@ func (t *Txn[T]) recursiveInsert(node Node[T], key []byte, value T, depth int, o // This means node is nil if node.getKeyLen() == 0 { nl := t.makeLeaf(key, value) - node.processLazyRef() nl.processLazyRef() if t.trackMutate { t.trackChannel(node) @@ -355,6 +354,9 @@ func (t *Txn[T]) recursiveDelete(node Node[T], key []byte, depth int) (Node[T], if t.trackMutate { t.trackChannel(oldRef) } + + t.trackChannel(child) + if doClone { node = t.writeNode(node) } else { @@ -409,6 +411,12 @@ func (t *Txn[T]) Commit() *RadixTree[T] { // CommitOnly is used to finalize the transaction and return a new tree, but // does not issue any notifications until Notify is called. func (t *Txn[T]) CommitOnly() *RadixTree[T] { + if t.tree.root == nil { + var zero T + t.tree.root = t.makeLeaf(nil, zero) + t.tree.root.setId(0) + t.tree.root.setMutateCh(make(chan struct{})) + } t.tree.root.incrementLazyRefCount(-1) t.tree.root.processLazyRef() nt := &RadixTree[T]{t.tree.root,