2021-09-27 17:51:31 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-11-21 12:19:41 +08:00
|
|
|
"io"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2021-09-27 17:51:31 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-12-26 16:15:03 +08:00
|
|
|
volumeServer = flag.String("volumeServer", "localhost:8080", "a volume server")
|
|
|
|
volumeId = flag.Int("volumeId", -1, "a volume id to stream read")
|
|
|
|
grpcDialOption grpc.DialOption
|
2021-09-27 17:51:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
util.LoadConfiguration("security", false)
|
|
|
|
grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
|
|
|
|
|
|
|
|
vid := uint32(*volumeId)
|
|
|
|
|
|
|
|
eachNeedleFunc := func(resp *volume_server_pb.ReadAllNeedlesResponse) error {
|
2022-11-21 12:19:41 +08:00
|
|
|
fmt.Printf("%d,%x%08x %d %v %d %x\n", resp.VolumeId, resp.NeedleId, resp.Cookie, len(resp.NeedleBlob), resp.NeedleBlobCompressed, resp.LastModified, resp.Crc)
|
2021-09-27 17:51:31 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
err := operation.WithVolumeServerClient(true, pb.ServerAddress(*volumeServer), grpcDialOption, func(vs volume_server_pb.VolumeServerClient) error {
|
2021-09-27 17:51:31 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
copyFileClient, err := vs.ReadAllNeedles(ctx, &volume_server_pb.ReadAllNeedlesRequest{
|
2021-12-26 16:15:03 +08:00
|
|
|
VolumeIds: []uint32{vid},
|
2021-09-27 17:51:31 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
resp, err := copyFileClient.Recv()
|
|
|
|
if errors.Is(err, io.EOF) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err = eachNeedleFunc(resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("read %s: %v\n", *volumeServer, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|