erigon-pulse/kv/memdb/memory_database.go
Andrew Ashikhmin 55fa5d7006
Various fixes and improvements of MemoryMutation (#573)
* Remove duplicate function

* Close cursor in ForAmount

* Correct ForEach & ForPrefix

* Switch GetOne implementation to cursor

* Switch Has implementation to cursor

* Small fixes

* statelessCursors should be cleared in UpdateTxn

* cursorentry -> cursorEntry

* Fix memoryMutationCursor.NextNoDup

* Don't swallow errors

* Fix memoryMutationCursor.First for DupSort tables

* TestFirstAfterClearBucket

* Add TestAutoDupSort

* WithTablessCfg -> WithTablesCfg

* WithTablesCfg -> WithTableCfg

* Add TestAutoDupSort

* Remove memoryMutationCursor.currentPair

* Merge duplicated cursors

* goForward -> resolveCursorPriority

* Extend TestAutoDupSort

* Amend skipIntersection

* Restore currentPair

* Revert "Merge duplicated cursors"

This reverts commit 13ba28f2fd4c63d6ef17254aa93ac05172e37429.

* Revert WithTablessCfg -> WithTableCfg

* Small fix to AppendDup

* Revert "Revert "Merge duplicated cursors""

This reverts commit b94b7612617750d26eebe8b149e5a8d7f219a4db.

* Pay more attention to isTableCleared

* Remove convertAutoDupsort

* Fix DeleteCurrentDuplicates

* Small simplification of memoryMutationCursor.SeekBothRange

* Revert BaseCase -> baseCase

* Revert parameter renaming

* Restore an assertion

* Add TestAutoConversionSeekBothRange

* CursorDupSort doesn't do AutoDupSortKeysConversion
2022-08-11 09:55:28 +02:00

108 lines
2.5 KiB
Go

/*
Copyright 2021 Erigon contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package memdb
import (
"context"
"testing"
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
)
func New() kv.RwDB {
return mdbx.NewMDBX(log.New()).InMem().MustOpen()
}
func NewPoolDB() kv.RwDB {
return mdbx.NewMDBX(log.New()).InMem().Label(kv.TxPoolDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.TxpoolTablesCfg }).MustOpen()
}
func NewDownloaderDB() kv.RwDB {
return mdbx.NewMDBX(log.New()).InMem().Label(kv.DownloaderDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.DownloaderTablesCfg }).MustOpen()
}
func NewSentryDB() kv.RwDB {
return mdbx.NewMDBX(log.New()).InMem().Label(kv.SentryDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.SentryTablesCfg }).MustOpen()
}
func NewTestDB(tb testing.TB) kv.RwDB {
tb.Helper()
db := New()
tb.Cleanup(db.Close)
return db
}
func NewTestPoolDB(tb testing.TB) kv.RwDB {
tb.Helper()
db := NewPoolDB()
tb.Cleanup(db.Close)
return db
}
func NewTestDownloaderDB(tb testing.TB) kv.RwDB {
tb.Helper()
db := NewDownloaderDB()
tb.Cleanup(db.Close)
return db
}
func NewTestSentrylDB(tb testing.TB) kv.RwDB {
tb.Helper()
db := NewPoolDB()
tb.Cleanup(db.Close)
return db
}
func NewTestTx(tb testing.TB) (kv.RwDB, kv.RwTx) {
tb.Helper()
db := New()
tb.Cleanup(db.Close)
tx, err := db.BeginRw(context.Background())
if err != nil {
tb.Fatal(err)
}
tb.Cleanup(tx.Rollback)
return db, tx
}
func NewTestPoolTx(tb testing.TB) (kv.RwDB, kv.RwTx) {
tb.Helper()
db := NewTestPoolDB(tb)
tx, err := db.BeginRw(context.Background()) //nolint
if err != nil {
tb.Fatal(err)
}
if tb != nil {
tb.Cleanup(tx.Rollback)
}
return db, tx
}
func NewTestSentryTx(tb testing.TB) (kv.RwDB, kv.RwTx) {
tb.Helper()
db := NewTestSentrylDB(tb)
tx, err := db.BeginRw(context.Background()) //nolint
if err != nil {
tb.Fatal(err)
}
if tb != nil {
tb.Cleanup(tx.Rollback)
}
return db, tx
}