mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
MDBX bindings: remove finalizers (write tx require to be closed from same thread) (#1579)
This commit is contained in:
parent
6a6f5469a1
commit
f7c122417c
@ -7,7 +7,6 @@ package mdbx
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@ -106,7 +105,6 @@ func (c *Cursor) close() bool {
|
||||
// See mdb_cursor_close.
|
||||
func (c *Cursor) Close() {
|
||||
if c.close() {
|
||||
runtime.SetFinalizer(c, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -540,19 +540,12 @@ func (env *Env) SetMaxDBs(size int) error {
|
||||
// methods, which assist in management of Txn objects and provide OS thread
|
||||
// locking required for write transactions.
|
||||
//
|
||||
// A finalizer detects unreachable, live transactions and logs thems to
|
||||
// standard error. The transactions are aborted, but their presence should be
|
||||
// interpreted as an application error which should be patched so transactions
|
||||
// are terminated explicitly. Unterminated transactions can adversly effect
|
||||
// Unterminated transactions can adversly effect
|
||||
// database performance and cause the database to grow until the map is full.
|
||||
//
|
||||
// See mdbx_txn_begin.
|
||||
func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) {
|
||||
txn, err := beginTxn(env, parent, flags)
|
||||
if txn != nil {
|
||||
runtime.SetFinalizer(txn, func(v interface{}) { v.(*Txn).finalize() })
|
||||
}
|
||||
return txn, err
|
||||
return beginTxn(env, parent, flags)
|
||||
}
|
||||
|
||||
// RunTxn creates a new Txn and calls fn with it as an argument. Run commits
|
||||
|
@ -9,7 +9,6 @@ import "C"
|
||||
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
@ -196,7 +195,6 @@ func (txn *Txn) Commit() (CommitLatency, error) {
|
||||
panic("managed transaction cannot be committed directly")
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(txn, nil)
|
||||
return txn.commit()
|
||||
}
|
||||
|
||||
@ -242,7 +240,6 @@ func (txn *Txn) Abort() {
|
||||
panic("managed transaction cannot be aborted directly")
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(txn, nil)
|
||||
txn.abort()
|
||||
}
|
||||
|
||||
@ -615,7 +612,6 @@ func (txn *Txn) Del(dbi DBI, key, val []byte) error {
|
||||
func (txn *Txn) OpenCursor(dbi DBI) (*Cursor, error) {
|
||||
cur, err := openCursor(txn, dbi)
|
||||
if cur != nil && txn.readonly {
|
||||
runtime.SetFinalizer(cur, (*Cursor).close)
|
||||
}
|
||||
return cur, err
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTxn_ID(t *testing.T) {
|
||||
@ -100,7 +99,6 @@ func TestTxn_ID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTxn_errLogf(t *testing.T) {
|
||||
t.Skip("to investigate")
|
||||
env := setup(t)
|
||||
defer clean(env, t)
|
||||
|
||||
@ -116,37 +114,6 @@ func TestTxn_errLogf(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTxn_finalizer(t *testing.T) {
|
||||
env := setup(t)
|
||||
defer clean(env, t)
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
called := make(chan struct{})
|
||||
func() {
|
||||
txn, err := env.BeginTxn(nil, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
txn.errLogf = func(string, ...interface{}) {
|
||||
close(called)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// make sure that finalizer has a chance to get called. it seems like this
|
||||
// may not be consistent across versions of go.
|
||||
runtime.GC()
|
||||
runtime.Gosched()
|
||||
|
||||
select {
|
||||
case <-called:
|
||||
case <-time.After(time.Second):
|
||||
t.Errorf("error logging function was not called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTxn_Drop(t *testing.T) {
|
||||
env := setup(t)
|
||||
defer clean(env, t)
|
||||
|
Loading…
Reference in New Issue
Block a user