mdbx: add migration from pebble option

This commit is contained in:
Victor Shyba 2025-05-19 11:29:22 -03:00
parent 9ad7426920
commit 128252a7b8
2 changed files with 62 additions and 0 deletions

View File

@ -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)

View File

@ -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 {