2021-03-18 21:12:48 +01:00
|
|
|
package main
|
|
|
|
|
2021-03-18 22:14:56 +01:00
|
|
|
import (
|
2022-02-08 18:50:37 +01:00
|
|
|
"bytes"
|
2021-03-18 22:14:56 +01:00
|
|
|
"context"
|
2021-04-19 21:25:34 +02:00
|
|
|
"fmt"
|
2021-03-18 22:14:56 +01:00
|
|
|
"log"
|
2022-02-20 14:03:27 +01:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2021-03-18 22:14:56 +01:00
|
|
|
"time"
|
|
|
|
|
2021-12-07 02:36:12 +01:00
|
|
|
"github.com/lbryio/hub/db"
|
2021-12-12 18:40:51 +01:00
|
|
|
"github.com/lbryio/hub/db/prefixes"
|
2021-03-18 22:14:56 +01:00
|
|
|
pb "github.com/lbryio/hub/protobuf/go"
|
2021-04-19 21:25:34 +02:00
|
|
|
"github.com/lbryio/hub/server"
|
2021-06-28 19:54:49 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/extras/util"
|
2021-03-18 22:14:56 +01:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2021-03-18 21:12:48 +01:00
|
|
|
func main() {
|
2021-07-06 02:20:38 +02:00
|
|
|
|
2021-10-25 03:39:37 +02:00
|
|
|
ctx := context.Background()
|
2021-05-25 05:28:43 +02:00
|
|
|
searchRequest := &pb.SearchRequest{}
|
|
|
|
|
2021-10-25 03:39:37 +02:00
|
|
|
args := server.ParseArgs(searchRequest)
|
2021-05-25 05:28:43 +02:00
|
|
|
|
2021-07-06 02:20:38 +02:00
|
|
|
if args.CmdType == server.ServeCmd {
|
2021-10-25 03:39:37 +02:00
|
|
|
// This will cancel goroutines with the server finishes.
|
|
|
|
ctxWCancel, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
2021-05-25 02:09:28 +02:00
|
|
|
|
2022-02-20 14:03:27 +01:00
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
|
|
|
defer signal.Stop(interrupt)
|
|
|
|
|
2021-10-25 03:39:37 +02:00
|
|
|
s := server.MakeHubServer(ctxWCancel, args)
|
2021-10-30 07:27:25 +02:00
|
|
|
s.Run()
|
2021-11-25 00:56:34 +01:00
|
|
|
|
2022-02-20 14:03:27 +01:00
|
|
|
select {
|
|
|
|
case <-interrupt:
|
|
|
|
break
|
|
|
|
case <-ctx.Done():
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Shutting down server...")
|
|
|
|
|
|
|
|
s.EsClient.Stop()
|
|
|
|
s.GrpcServer.GracefulStop()
|
|
|
|
|
|
|
|
log.Println("Returning from main...")
|
|
|
|
|
2021-12-07 02:36:12 +01:00
|
|
|
return
|
|
|
|
} else if args.CmdType == server.DBCmd {
|
2022-02-03 20:18:00 +01:00
|
|
|
options := &db.IterOptions{
|
|
|
|
FillCache: false,
|
|
|
|
Prefix: []byte{prefixes.SupportAmount},
|
|
|
|
Start: nil,
|
|
|
|
Stop: nil,
|
|
|
|
IncludeStart: true,
|
|
|
|
IncludeStop: false,
|
|
|
|
IncludeKey: true,
|
|
|
|
IncludeValue: true,
|
|
|
|
RawKey: true,
|
|
|
|
RawValue: true,
|
|
|
|
}
|
|
|
|
|
2021-12-24 13:17:53 +01:00
|
|
|
dbVal, err := db.GetDB("/mnt/d/data/wallet/lbry-rocksdb/")
|
2021-12-12 18:40:51 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:50:37 +01:00
|
|
|
db.ReadWriteRawN(dbVal, options, "./testdata/support_amount.csv", 10)
|
2022-02-03 20:18:00 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
} else if args.CmdType == server.DBCmd2 {
|
2022-02-08 18:50:37 +01:00
|
|
|
pxs := prefixes.GetPrefixes()
|
|
|
|
for _, prefix := range pxs {
|
|
|
|
//var rawPrefix byte = prefixes.ClaimExpiration
|
|
|
|
|
|
|
|
//prefix := []byte{rawPrefix}
|
|
|
|
columnFamily := string(prefix)
|
|
|
|
options := &db.IterOptions{
|
|
|
|
FillCache: false,
|
|
|
|
Prefix: prefix,
|
|
|
|
Start: nil,
|
|
|
|
Stop: nil,
|
|
|
|
IncludeStart: true,
|
|
|
|
IncludeStop: false,
|
|
|
|
IncludeKey: true,
|
|
|
|
IncludeValue: true,
|
|
|
|
RawKey: true,
|
|
|
|
RawValue: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
dbVal, handles, err := db.GetDBCF("/mnt/d/data/snapshot_1072108/lbry-rocksdb/", columnFamily)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
options.CfHandle = handles[1]
|
|
|
|
var n = 10
|
|
|
|
if bytes.Equal(prefix, []byte{prefixes.Undo}) || bytes.Equal(prefix, []byte{prefixes.DBState}) {
|
|
|
|
n = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
db.ReadWriteRawNCF(dbVal, options, fmt.Sprintf("./testdata/%s.csv", columnFamily), n)
|
2022-02-03 20:18:00 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 11:15:00 +01:00
|
|
|
return
|
|
|
|
} else if args.CmdType == server.DBCmd3 {
|
2022-02-22 01:21:18 +01:00
|
|
|
// channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
|
|
|
|
var rawPrefix byte = prefixes.DBState
|
2022-02-18 11:15:00 +01:00
|
|
|
prefix := []byte{rawPrefix}
|
|
|
|
columnFamily := string(prefix)
|
2022-02-22 01:21:18 +01:00
|
|
|
// start := &prefixes.ChannelCountKey{
|
|
|
|
// Prefix: prefix,
|
|
|
|
// ChannelHash: channelHash,
|
2022-02-20 14:03:27 +01:00
|
|
|
// }
|
2022-02-22 01:21:18 +01:00
|
|
|
// startRaw := prefixes.ChannelCountKeyPackPartial(start, 1)
|
|
|
|
// startRaw := start.PackKey()
|
2022-02-18 11:15:00 +01:00
|
|
|
options := &db.IterOptions{
|
|
|
|
FillCache: false,
|
|
|
|
Prefix: prefix,
|
2022-02-20 14:03:27 +01:00
|
|
|
Start: nil,
|
2022-02-18 11:15:00 +01:00
|
|
|
Stop: nil,
|
|
|
|
IncludeStart: true,
|
|
|
|
IncludeStop: false,
|
|
|
|
IncludeKey: true,
|
|
|
|
IncludeValue: true,
|
|
|
|
RawKey: true,
|
|
|
|
RawValue: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
dbVal, handles, err := db.GetDBCF("/mnt/d/data/snapshot_1072108/lbry-rocksdb/", columnFamily)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
options.CfHandle = handles[1]
|
|
|
|
|
2022-02-22 01:21:18 +01:00
|
|
|
db.ReadWriteRawNColumnFamilies(dbVal, options, fmt.Sprintf("./testdata/%s_resolve.csv", columnFamily), 1)
|
2021-03-18 22:14:56 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-25 03:39:37 +02:00
|
|
|
conn, err := grpc.Dial("localhost:"+args.Port,
|
2021-05-25 02:09:28 +02:00
|
|
|
grpc.WithInsecure(),
|
2021-05-31 03:34:57 +02:00
|
|
|
grpc.WithBlock(),
|
2021-05-25 02:09:28 +02:00
|
|
|
)
|
2021-03-18 22:14:56 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
c := pb.NewHubClient(conn)
|
|
|
|
|
2021-10-25 03:39:37 +02:00
|
|
|
ctxWTimeout, cancelQuery := context.WithTimeout(ctx, time.Second)
|
|
|
|
defer cancelQuery()
|
2021-03-18 22:14:56 +01:00
|
|
|
|
2021-07-06 02:20:38 +02:00
|
|
|
log.Println(args)
|
|
|
|
switch args.CmdType {
|
|
|
|
case server.SearchCmd:
|
2021-10-25 03:39:37 +02:00
|
|
|
r, err := c.Search(ctxWTimeout, searchRequest)
|
2021-07-06 02:20:38 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-05-16 05:13:14 +02:00
|
|
|
|
2021-07-06 02:20:38 +02:00
|
|
|
log.Printf("found %d results\n", r.GetTotal())
|
2021-04-19 21:25:34 +02:00
|
|
|
|
2021-07-06 02:20:38 +02:00
|
|
|
for _, t := range r.Txos {
|
|
|
|
fmt.Printf("%s:%d\n", util.TxHashToTxId(t.TxHash), t.Nout)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Fatalln("Unknown Command Type!")
|
2021-04-19 21:25:34 +02:00
|
|
|
}
|
2021-03-18 21:12:48 +01:00
|
|
|
}
|