Fix memory leak in secondary, cleanup code.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"hash/crc64"
|
||||
@@ -25,8 +24,6 @@ type Collection[T any] struct {
|
||||
uniqueIndices []*Index[T]
|
||||
|
||||
ByID *Index[T]
|
||||
|
||||
buf *bytes.Buffer
|
||||
}
|
||||
|
||||
type CollectionConfig[T any] struct {
|
||||
@@ -67,7 +64,6 @@ func NewCollection[T any](db *Database, name string, conf *CollectionConfig[T])
|
||||
validate: conf.Validate,
|
||||
indices: []*Index[T]{},
|
||||
uniqueIndices: []*Index[T]{},
|
||||
buf: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
db.addCollection(c.collectionID, c, &collectionState[T]{
|
||||
|
||||
@@ -99,6 +99,7 @@ func (db *Database) repApply(rec wal.Record) (err error) {
|
||||
}
|
||||
tx.seqNum = rec.SeqNum
|
||||
tx.timestampMS = rec.TimestampMS
|
||||
tx.setReadOnly()
|
||||
db.snapshot.Store(tx)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func testRunner_testCase(t *testing.T, testCase DBTestCase) {
|
||||
}
|
||||
|
||||
// TODO: Why is this necessary?
|
||||
time.Sleep(time.Second)
|
||||
//time.Sleep(time.Second)
|
||||
finalStep := testCase.Steps[len(testCase.Steps)-1]
|
||||
|
||||
secondarySnapshot := db2.Snapshot()
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package mdb
|
||||
|
||||
/*
|
||||
type txAggregator struct {
|
||||
Stop chan struct{}
|
||||
Done *sync.WaitGroup
|
||||
ModChan chan txMod
|
||||
W *cswal.Writer
|
||||
Index *pagefile.Index
|
||||
Snapshot *atomic.Pointer[Snapshot]
|
||||
}
|
||||
|
||||
func (p txAggregator) Run() {
|
||||
defer p.Done.Done()
|
||||
defer p.W.Close()
|
||||
|
||||
var (
|
||||
tx *Snapshot
|
||||
mod txMod
|
||||
rec cswal.Record
|
||||
err error
|
||||
toNotify = make([]chan error, 0, 1024)
|
||||
)
|
||||
|
||||
READ_FIRST:
|
||||
|
||||
toNotify = toNotify[:0]
|
||||
|
||||
select {
|
||||
case mod = <-p.ModChan:
|
||||
goto BEGIN
|
||||
case <-p.Stop:
|
||||
goto END
|
||||
}
|
||||
|
||||
BEGIN:
|
||||
|
||||
tx = p.Snapshot.Load().begin()
|
||||
goto APPLY_MOD
|
||||
|
||||
CLONE:
|
||||
|
||||
tx = tx.clone()
|
||||
goto APPLY_MOD
|
||||
|
||||
APPLY_MOD:
|
||||
|
||||
if err = mod.Update(tx); err != nil {
|
||||
mod.Resp <- err
|
||||
goto ROLLBACK
|
||||
}
|
||||
|
||||
toNotify = append(toNotify, mod.Resp)
|
||||
goto NEXT
|
||||
|
||||
ROLLBACK:
|
||||
|
||||
if len(toNotify) == 0 {
|
||||
goto READ_FIRST
|
||||
}
|
||||
|
||||
tx = tx.rollback()
|
||||
goto NEXT
|
||||
|
||||
NEXT:
|
||||
|
||||
select {
|
||||
case mod = <-p.ModChan:
|
||||
goto CLONE
|
||||
default:
|
||||
goto WRITE
|
||||
}
|
||||
|
||||
WRITE:
|
||||
|
||||
rec, err = writeChangesToWAL(tx.changes, p.Index, p.W)
|
||||
if err == nil {
|
||||
tx.seqNum = rec.SeqNum
|
||||
tx.updatedAt = rec.CreatedAt
|
||||
tx.setReadOnly()
|
||||
p.Snapshot.Store(tx)
|
||||
}
|
||||
|
||||
for i := range toNotify {
|
||||
toNotify[i] <- err
|
||||
}
|
||||
|
||||
goto READ_FIRST
|
||||
|
||||
END:
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user