You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "github.com/chrislusf/seaweedfs/weed/operation"
  6. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  7. "github.com/chrislusf/seaweedfs/weed/security"
  8. weed_server "github.com/chrislusf/seaweedfs/weed/server"
  9. "github.com/chrislusf/seaweedfs/weed/storage"
  10. "github.com/spf13/viper"
  11. "io"
  12. "log"
  13. )
  14. var (
  15. master = flag.String("master", "localhost:9333", "master server host and port")
  16. volumeId = flag.Int("volumeId", -1, "a volume id")
  17. timeoutSeconds = flag.Int("timeoutSeconds", 0, "disconnect if no activity after these seconds")
  18. )
  19. func main() {
  20. flag.Parse()
  21. weed_server.LoadConfiguration("security", false)
  22. grpcDialOption := security.LoadClientTLS(viper.Sub("grpc"), "client")
  23. vid := storage.VolumeId(*volumeId)
  24. // find volume location, replication, ttl info
  25. lookup, err := operation.Lookup(*master, vid.String())
  26. if err != nil {
  27. log.Printf("Error looking up volume %d: %v", vid, err)
  28. return
  29. }
  30. volumeServer := lookup.Locations[0].Url
  31. log.Printf("volume %d is on volume server %s", vid, volumeServer)
  32. err = operation.WithVolumeServerClient(volumeServer, grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
  33. stream, err := client.VolumeTail(context.Background(), &volume_server_pb.VolumeTailRequest{
  34. VolumeId: uint32(vid),
  35. SinceNs: 0,
  36. DrainingSeconds: uint32(*timeoutSeconds),
  37. })
  38. if err != nil {
  39. return err
  40. }
  41. for {
  42. resp, recvErr := stream.Recv()
  43. if recvErr != nil {
  44. if recvErr == io.EOF {
  45. break
  46. } else {
  47. return recvErr
  48. }
  49. }
  50. println("header:", len(resp.NeedleHeader), "body:", len(resp.NeedleBody))
  51. }
  52. return nil
  53. })
  54. if err != nil {
  55. log.Printf("Error VolumeTail volume %d: %v", vid, err)
  56. }
  57. }