106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"git.gammaspectra.live/S.O.N.G/Hibiki/utilities/specializedstore"
|
|
"git.gammaspectra.live/S.O.N.G/METANOIA/store"
|
|
"log"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
command := flag.String("cmd", "sort", "Commands: sort")
|
|
split := flag.Int("split", runtime.NumCPU(), "Number of splits for bulk tasks")
|
|
sourcePath := flag.String("src", "", "Source database append log path")
|
|
destinationPath := flag.String("dst", "", "Destination database append log path")
|
|
|
|
flag.Parse()
|
|
|
|
if *command == "sort" {
|
|
source, err := store.NewAppendConverter(*sourcePath, true, true)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer source.Close()
|
|
|
|
destination, err := store.NewAppendStore(*destinationPath, true, true)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer destination.Close()
|
|
|
|
taskState := source.SortHashes(destination, *split)
|
|
|
|
for {
|
|
p, t := taskState.Progress()
|
|
|
|
log.Printf("%.03f%% %d/%d", float64(p*100)/float64(t), p, t)
|
|
|
|
if p >= t {
|
|
break
|
|
}
|
|
|
|
time.Sleep(time.Second * 5)
|
|
}
|
|
|
|
taskState.Wait()
|
|
} else if *command == "badger" {
|
|
source, err := store.NewAppendConverter(*sourcePath, true, true)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer source.Close()
|
|
|
|
destination, err := specializedstore.NewBadgerStore(*destinationPath, true, false, 5000000)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer destination.Close()
|
|
|
|
taskState := source.ConvertToBadger(destination, *split)
|
|
|
|
for {
|
|
p, t := taskState.Progress()
|
|
|
|
log.Printf("%.03f%% %d/%d", float64(p*100)/float64(t), p, t)
|
|
|
|
if p >= t {
|
|
break
|
|
}
|
|
|
|
time.Sleep(time.Second * 5)
|
|
}
|
|
|
|
taskState.Wait()
|
|
} else if *command == "bptree" {
|
|
source, err := store.NewAppendConverter(*sourcePath, true, true)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer source.Close()
|
|
|
|
destination, err := specializedstore.NewBPTreeFileStore(*destinationPath, true)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
defer destination.Close()
|
|
|
|
taskState := source.ConvertToBPTree(destination)
|
|
|
|
for {
|
|
p, t := taskState.Progress()
|
|
|
|
log.Printf("%.03f%% %d/%d", float64(p*100)/float64(t), p, t)
|
|
|
|
if p >= t {
|
|
break
|
|
}
|
|
|
|
time.Sleep(time.Second * 5)
|
|
}
|
|
|
|
taskState.Wait()
|
|
}
|
|
}
|