mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-03-10 10:47:28 +08:00
mdbx: add migration from pebble option
This commit is contained in:
parent
9ad7426920
commit
128252a7b8
59
node/main.go
59
node/main.go
@ -97,6 +97,11 @@ var (
|
||||
false,
|
||||
"print node related information",
|
||||
)
|
||||
migrate = flag.String(
|
||||
"migrate",
|
||||
"",
|
||||
"migrate from Pebble to MDBX from specified path (e.g. /home/user/backup/.config/store)",
|
||||
)
|
||||
debug = flag.Bool(
|
||||
"debug",
|
||||
false,
|
||||
@ -375,6 +380,60 @@ func main() {
|
||||
console.Run()
|
||||
return
|
||||
}
|
||||
if *migrate != "" {
|
||||
fmt.Printf("Migrating from Pebble to MDBX from %s\n", *migrate)
|
||||
d, err := os.Stat(filepath.Join(*migrate, "LOCK"))
|
||||
if err != nil || d == nil {
|
||||
fmt.Printf("%s does not look like a pebble db! Double check your path", *migrate)
|
||||
return
|
||||
}
|
||||
dbConfig := &config.DBConfig{
|
||||
Path: *migrate,
|
||||
}
|
||||
pebbleInput := store.NewPebbleDB(dbConfig)
|
||||
mdbxOutput := store.NewMDBXDB(nodeConfig.DB)
|
||||
|
||||
allIter, err := pebbleInput.NewIter(nil, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
batch := mdbxOutput.NewBatch(false)
|
||||
total := 0
|
||||
for allIter.First(); allIter.Valid(); allIter.Next() {
|
||||
err := batch.Set(allIter.Key(), allIter.Value())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total++
|
||||
if total%10_000 == 0 {
|
||||
err := batch.Commit()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Commit. Total: %d", total)
|
||||
}
|
||||
}
|
||||
err = batch.Commit()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Commit. Total: %d", total)
|
||||
err = allIter.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = pebbleInput.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = mdbxOutput.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Done.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if *dhtOnly {
|
||||
done := make(chan os.Signal, 1)
|
||||
|
||||
@ -553,6 +553,9 @@ func (m *MDBXBatch) Commit() error {
|
||||
return err
|
||||
}
|
||||
key, _, err := cursor.Get(op.operand1, nil, mdbx.SetRange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for bytes.Compare(key, op.operand1) >= 0 && bytes.Compare(key, op.operand2) < 0 {
|
||||
err = cursor.Del(mdbx.Current)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user