From dc8702ea3e8df040184dd919c74d6995b3dad4c7 Mon Sep 17 00:00:00 2001 From: Seebs Date: Wed, 13 Oct 2021 12:38:54 -0500 Subject: [PATCH] use testhook auditor to track Qcx open/close This also requires doing something to keep the TxGroup in each Qcx from holding its Tx references after the Qcx closes, because otherwise the list of Qcxs that we keep to verify that they all got closed ends up keeping every shared/read-only Tx open forever, resulting in many gigabytes of memory usage when running with the race detector. To avoid having to reason about whether anything would ever access a nil TxGroup, or run through iteratively zeroing maps, we just make a new empty group at that point. --- txfactory.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/txfactory.go b/txfactory.go index 93e9449df..7c0d06add 100644 --- a/txfactory.go +++ b/txfactory.go @@ -31,6 +31,7 @@ import ( "github.com/molecula/featurebase/v2/roaring" txkey "github.com/molecula/featurebase/v2/short_txkey" "github.com/molecula/featurebase/v2/storage" + "github.com/molecula/featurebase/v2/testhook" . "github.com/molecula/featurebase/v2/vprint" // nolint:staticcheck "github.com/pkg/errors" "github.com/zeebo/blake3" @@ -147,6 +148,11 @@ func (q *Qcx) Finish() (err error) { } } err2 := q.Grp.FinishGroup() + // drop the old group so we aren't holding references to all those Tx + q.Grp = q.Txf.NewTxGroup() + if !q.done { + _ = testhook.Closed(q.Txf.holder.Auditor, q, nil) + } q.done = true if err != nil { @@ -164,7 +170,11 @@ func (q *Qcx) Abort() { (*q.RequiredForAtomicWriteTx).Rollback() } q.Grp.AbortGroup() - + // drop the old group so we aren't holding references to all those Tx + q.Grp = q.Txf.NewTxGroup() + if !q.done { + _ = testhook.Closed(q.Txf.holder.Auditor, q, nil) + } q.done = true } @@ -197,6 +207,7 @@ func (f *TxFactory) NewQcx() (qcx *Qcx) { if f.typeOfTx == "roaring" { qcx.isRoaring = true } + _ = testhook.Opened(f.holder.Auditor, qcx, nil) return }