-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_node_db.go
61 lines (56 loc) · 1.51 KB
/
copy_node_db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"github.com/deso-smart/deso-backend/v2/scripts/tools/toolslib"
"github.com/deso-smart/deso-core/v2/lib"
)
func main() {
sourceDbDir := "$HOME/data_dirs/hypersync/mini_sentry_nft"
destinationDbDir := "$HOME/data_dirs/hypersync/mini_sentry_nft_copy"
sourceDb, err := toolslib.OpenDataDir(sourceDbDir)
if err != nil {
fmt.Printf("Error reading sourceDb err: %v", err)
return
}
destinationDb, err := toolslib.OpenDataDir(destinationDbDir)
if err != nil {
fmt.Printf("Error reading destinationDb: (%)", err)
return
}
maxBytes := uint32(8 << 22)
totalLen := 0
_ = totalLen
err = func() error {
for prefixByte := range lib.StatePrefixes.StatePrefixesMap {
prefix := []byte{prefixByte}
fmt.Printf("Copying prefix: (%v)\n", prefix)
lastPrefix := prefix
for {
db0Entries, full0, err := lib.DBIteratePrefixKeys(sourceDb, prefix, lastPrefix, maxBytes)
if err != nil {
panic(fmt.Errorf("error on DBIteratePrefixKeys! (%v)", err))
}
wb := destinationDb.NewWriteBatch()
for _, dbEntry := range db0Entries {
err = wb.Set(dbEntry.Key, dbEntry.Value)
if err != nil {
panic(fmt.Errorf("error on write batch set! (%v)", err))
}
}
err = wb.Flush()
if err != nil {
panic(fmt.Errorf("error on write batch flush! (%v)", err))
}
wb.Cancel()
if len(db0Entries) != 0 {
lastPrefix = db0Entries[len(db0Entries)-1].Key
}
if !full0 {
break
}
}
}
return nil
}()
fmt.Println("Successfully copied!")
}