Skip to content

Commit

Permalink
added var inside WriteMap for chain-like interface (#11241)
Browse files Browse the repository at this point in the history
closes #11202

---------

Co-authored-by: JkLondon <[email protected]>
  • Loading branch information
JkLondon and JkLondon authored Jul 20, 2024
1 parent af2a4a0 commit a0e328b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 35 deletions.
19 changes: 5 additions & 14 deletions cmd/integration/commands/refetence_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,8 @@ func init() {

func doWarmup(ctx context.Context, chaindata string, bucket string, logger log.Logger) error {
const ThreadsLimit = 5_000
dbOpts := mdbx2.NewMDBX(log.New()).Path(chaindata).Accede().RoTxsLimiter(semaphore.NewWeighted(ThreadsLimit))

if dbWriteMap {
dbOpts = dbOpts.WriteMap()
}
dbOpts := mdbx2.NewMDBX(log.New()).Path(chaindata).Accede().RoTxsLimiter(semaphore.NewWeighted(ThreadsLimit)).
WriteMap(dbWriteMap)

db := dbOpts.MustOpen()
defer db.Close()
Expand Down Expand Up @@ -258,11 +255,8 @@ func doWarmup(ctx context.Context, chaindata string, bucket string, logger log.L

func mdbxTopDup(ctx context.Context, chaindata string, bucket string, logger log.Logger) error {
const ThreadsLimit = 5_000
dbOpts := mdbx2.NewMDBX(log.New()).Path(chaindata).Accede().RoTxsLimiter(semaphore.NewWeighted(ThreadsLimit))

if dbWriteMap {
dbOpts = dbOpts.WriteMap()
}
dbOpts := mdbx2.NewMDBX(log.New()).Path(chaindata).Accede().RoTxsLimiter(semaphore.NewWeighted(ThreadsLimit)).
WriteMap(dbWriteMap)

db := dbOpts.MustOpen()
defer db.Close()
Expand Down Expand Up @@ -427,10 +421,7 @@ func fToMdbx(ctx context.Context, logger log.Logger, to string) error {
}
defer file.Close()

dstOpts := mdbx2.NewMDBX(logger).Path(to)
if dbWriteMap {
dstOpts = dstOpts.WriteMap()
}
dstOpts := mdbx2.NewMDBX(logger).Path(to).WriteMap(dbWriteMap)
dst := dstOpts.MustOpen()
dstTx, err1 := dst.BeginRw(ctx)
if err1 != nil {
Expand Down
6 changes: 1 addition & 5 deletions cmd/integration/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func RootCommand() *cobra.Command {
func dbCfg(label kv.Label, path string) kv2.MdbxOpts {
const ThreadsLimit = 9_000
limiterB := semaphore.NewWeighted(ThreadsLimit)
opts := kv2.NewMDBX(log.New()).Path(path).Label(label).RoTxsLimiter(limiterB)

if dbWriteMap {
opts = opts.WriteMap()
}
opts := kv2.NewMDBX(log.New()).Path(path).Label(label).RoTxsLimiter(limiterB).WriteMap(dbWriteMap)

// integration tool don't intent to create db, then easiest way to open db - it's pass mdbx.Accede flag, which allow
// to read all options from DB, instead of overriding them
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var readDomains = &cobra.Command{
}
defer chainDb.Close()

stateDb, err := kv2.NewMDBX(log.New()).Path(filepath.Join(dirs.DataDir, "statedb")).WriteMap().Open(ctx)
stateDb, err := kv2.NewMDBX(log.New()).Path(filepath.Join(dirs.DataDir, "statedb")).WriteMap(true).Open(ctx)
if err != nil {
return
}
Expand Down
7 changes: 2 additions & 5 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2753,11 +2753,8 @@ func openClient(ctx context.Context, dbDir, snapDir string, cfg *torrent.ClientC
MapSize(16 * datasize.GB).
PageSize(uint64(4 * datasize.KB)).
RoTxsLimiter(semaphore.NewWeighted(9_000)).
Path(dbDir)

if writeMap {
dbCfg = dbCfg.WriteMap()
}
Path(dbDir).
WriteMap(writeMap)
db, err = dbCfg.Open(ctx)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("torrentcfg.openClient: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions erigon-lib/kv/mdbx/kv_mdbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ func (opts MdbxOpts) MapSize(sz datasize.ByteSize) MdbxOpts {
return opts
}

func (opts MdbxOpts) WriteMap() MdbxOpts {
opts.flags |= mdbx.WriteMap
func (opts MdbxOpts) WriteMap(flag bool) MdbxOpts {
if flag {
opts.flags |= mdbx.WriteMap
}
return opts
}
func (opts MdbxOpts) LifoReclaim() MdbxOpts {
Expand Down Expand Up @@ -231,9 +233,7 @@ func PathDbMap() map[string]kv.RoDB {
var ErrDBDoesNotExists = fmt.Errorf("can't create database - because opening in `Accede` mode. probably another (main) process can create it")

func (opts MdbxOpts) Open(ctx context.Context) (kv.RwDB, error) {
if dbg.WriteMap() {
opts = opts.WriteMap() //nolint
}
opts = opts.WriteMap(dbg.WriteMap())
if dbg.DirtySpace() > 0 {
opts = opts.DirtySpace(dbg.DirtySpace()) //nolint
}
Expand Down
7 changes: 2 additions & 5 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,8 @@ func OpenDatabase(ctx context.Context, config *nodecfg.Config, label kv.Label, n
opts := mdbx.NewMDBX(logger).
Path(dbPath).Label(label).
GrowthStep(16 * datasize.MB).
DBVerbosity(config.DatabaseVerbosity).RoTxsLimiter(roTxsLimiter)

if config.MdbxWriteMap {
opts = opts.WriteMap()
}
DBVerbosity(config.DatabaseVerbosity).RoTxsLimiter(roTxsLimiter).
WriteMap(config.MdbxWriteMap)

if readonly {
opts = opts.Readonly()
Expand Down

0 comments on commit a0e328b

Please sign in to comment.