erigon-pulse/cmd/snapshots/utils/utils.go
Alex Sharov 0be3044b7e
rename (#1978)
* rename

* rename "make grpc"

* rename "abi bindings templates"

* rename "abi bindings templates"
2021-05-20 19:25:53 +01:00

46 lines
1003 B
Go

package utils
import (
"errors"
"os"
"github.com/ledgerwatch/erigon/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())
}