Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2 nodedb: batch updates as in E3 #13218

Open
wants to merge 1 commit into
base: release/2.61
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions p2p/enode/nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"github.com/c2h5oh/datasize"
"github.com/erigontech/erigon-lib/log/v3"
mdbx1 "github.com/erigontech/mdbx-go/mdbx"

"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/mdbx"
Expand Down Expand Up @@ -73,8 +72,8 @@ var zeroIP = make(net.IP, 16)
// DB is the node database, storing previously seen nodes and any collected metadata about
// them for QoS purposes.
type DB struct {
kv kv.RwDB // Interface to the database itself
runner sync.Once // Ensures we can start at most one expirer
kv *mdbx.MdbxKV // Interface to the database itself
runner sync.Once // Ensures we can start at most one expirer

ctx context.Context
ctxCancel func()
Expand Down Expand Up @@ -108,7 +107,7 @@ func newMemoryDB(ctx context.Context, logger log.Logger, tmpDir string) (*DB, er
return nil, err
}

nodeDB := &DB{kv: db}
nodeDB := &DB{kv: db.(*mdbx.MdbxKV)}
nodeDB.ctx, nodeDB.ctxCancel = context.WithCancel(ctx)

return nodeDB, nil
Expand All @@ -123,9 +122,7 @@ func newPersistentDB(ctx context.Context, logger log.Logger, path string) (*DB,
WithTableCfg(bucketsConfig).
MapSize(8 * datasize.GB).
GrowthStep(16 * datasize.MB).
DirtySpace(uint64(128 * datasize.MB)).
Flags(func(f uint) uint { return f ^ mdbx1.Durable | mdbx1.SafeNoSync }).
SyncPeriod(2 * time.Second).
DirtySpace(uint64(64 * datasize.MB)).
Open(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -165,7 +162,7 @@ func newPersistentDB(ctx context.Context, logger log.Logger, path string) (*DB,
return newPersistentDB(ctx, logger, path)
}

nodeDB := &DB{kv: db}
nodeDB := &DB{kv: db.(*mdbx.MdbxKV)}
nodeDB.ctx, nodeDB.ctxCancel = context.WithCancel(ctx)

return nodeDB, nil
Expand Down Expand Up @@ -260,7 +257,7 @@ func (db *DB) fetchInt64(key []byte) int64 {
func (db *DB) storeInt64(key []byte, n int64) error {
blob := make([]byte, binary.MaxVarintLen64)
blob = blob[:binary.PutVarint(blob, n)]
return db.kv.Update(db.ctx, func(tx kv.RwTx) error {
return db.kv.Batch(func(tx kv.RwTx) error {
return tx.Put(kv.Inodes, key, blob)
})
}
Expand All @@ -285,7 +282,7 @@ func (db *DB) fetchUint64(key []byte) uint64 {

// storeUint64 stores an integer in the given key.
func (db *DB) storeUint64(key []byte, n uint64) error {
return db.kv.Update(db.ctx, func(tx kv.RwTx) error {
return db.kv.Batch(func(tx kv.RwTx) error {
return db._storeUint64(tx, key, n)
})
}
Expand Down Expand Up @@ -336,7 +333,7 @@ func (db *DB) UpdateNode(node *Node) error {
if err != nil {
return err
}
return db.kv.Update(db.ctx, func(tx kv.RwTx) error {
return db.kv.Batch(func(tx kv.RwTx) error {
err = tx.Put(kv.NodeRecords, nodeKey(node.ID()), blob)
if err != nil {
return err
Expand Down Expand Up @@ -365,7 +362,7 @@ func (db *DB) DeleteNode(id ID) {
}

func (db *DB) deleteRange(prefix []byte) {
if err := db.kv.Update(db.ctx, func(tx kv.RwTx) error {
if err := db.kv.Batch(func(tx kv.RwTx) error {
for bucket := range bucketsConfig(nil) {
if err := deleteRangeInBucket(tx, prefix, bucket); err != nil {
return err
Expand Down
Loading