erigon-pulse/cmd/snapshots/utils/utils.go
b00ris 565a4250d6
Snapshot sync headers stage (#1836)
* save state

* snapshot update works

* save state

* snapshot migrator

* tx test

* save state

* migrations stages refactor

* refactor snapshot migrator

* compilation fixed

* integrate snapshot migrator

* goerli sync headers

* debug async snapshotter on goerly

* move verify headers, remove experiments, fix remove old snapshot

* save state

* refactor snapshotsync injection

* fix deadlock

* replace snapshot generation stage logic to migrate method

* change done for body snapshot

* clean

* clean&&change deleted value

* clean

* fix hash len

* fix hash len

* remove one of wrap methods, add remove snapshots on start

* add err check

* fix shadowing

* stages unwind order debug

* matryoshka experiments

* steam test

* fix build

* fix test

* fix lint

* fix test

* fix test datarace

* add get test

* return timeout

* fix mdbx overlap

* fix after merge

* change epoch size

* clean todo

* fix

* return testdata

* added return from sndownloader gorutine

* fix review comments

* Fix

* More info

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-08 09:45:40 +01:00

46 lines
1007 B
Go

package utils
import (
"errors"
"os"
"github.com/ledgerwatch/turbo-geth/ethdb"
)
const (
TypeLMDB = "lmdb"
TypeMDBX = "mdbx"
)
var ErrUnsupported error = errors.New("unsupported KV type")
func RmTmpFiles(dbType string, snapshotPath string) error {
switch dbType {
case TypeLMDB:
return rmLmdbLock(snapshotPath)
case TypeMDBX:
return rmMdbxLock(snapshotPath)
default:
return ErrUnsupported
}
}
func rmLmdbLock(snapshotPath string) error {
err := os.Remove(snapshotPath + "/lock.mdb")
if err != nil {
return err
}
return os.Remove(snapshotPath + "/LOCK")
}
func rmMdbxLock(path string) error {
return os.Remove(path + "/mdbx.lck")
}
func OpenSnapshotKV(dbType string, configsFunc ethdb.BucketConfigsFunc, path string) ethdb.RwKV {
if dbType == TypeLMDB {
return ethdb.NewLMDB().WithBucketsConfig(configsFunc).Path(path).MustOpen()
} else if dbType == TypeMDBX {
return ethdb.NewMDBX().WithBucketsConfig(configsFunc).Path(path).MustOpen()
}
panic(ErrUnsupported.Error())
}