METANOIA/store/cli/cli.go

106 lines
2.1 KiB
Go
Raw Normal View History

package main
import (
"flag"
2022-02-04 10:45:53 +00:00
"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")
2022-02-06 16:55:54 +00:00
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)
}
2022-02-04 11:07:39 +00:00
defer source.Close()
destination, err := store.NewAppendStore(*destinationPath, true, true)
if err != nil {
log.Panic(err)
}
2022-02-04 11:07:39 +00:00
defer destination.Close()
2022-02-06 16:55:54 +00:00
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)
}
2022-02-04 10:45:53 +00:00
taskState.Wait()
} else if *command == "badger" {
source, err := store.NewAppendConverter(*sourcePath, true, true)
if err != nil {
log.Panic(err)
}
2022-02-04 11:07:39 +00:00
defer source.Close()
2022-02-04 10:45:53 +00:00
2022-02-04 14:37:31 +00:00
destination, err := specializedstore.NewBadgerStore(*destinationPath, true, false, 5000000)
2022-02-04 10:45:53 +00:00
if err != nil {
log.Panic(err)
}
2022-02-04 11:07:39 +00:00
defer destination.Close()
2022-02-04 10:45:53 +00:00
2022-02-06 16:55:54 +00:00
taskState := source.ConvertToBadger(destination, *split)
2022-02-04 10:45:53 +00:00
2022-02-06 17:13:31 +00:00
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)
}
2022-02-04 11:15:09 +00:00
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()
}
}