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.

71 lines
1.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/operation"
  7. "github.com/chrislusf/seaweedfs/weed/security"
  8. weed_server "github.com/chrislusf/seaweedfs/weed/server"
  9. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  10. util2 "github.com/chrislusf/seaweedfs/weed/util"
  11. "github.com/spf13/viper"
  12. "golang.org/x/tools/godoc/util"
  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. rewindDuration = flag.Duration("rewind", -1, "rewind back in time. -1 means from the first entry. 0 means from now.")
  18. timeoutSeconds = flag.Int("timeoutSeconds", 0, "disconnect if no activity after these seconds")
  19. showTextFile = flag.Bool("showTextFile", false, "display textual file content")
  20. )
  21. func main() {
  22. flag.Parse()
  23. weed_server.LoadConfiguration("security", false)
  24. grpcDialOption := security.LoadClientTLS(viper.Sub("grpc"), "client")
  25. vid := needle.VolumeId(*volumeId)
  26. var sinceTimeNs int64
  27. if *rewindDuration == 0 {
  28. sinceTimeNs = time.Now().UnixNano()
  29. } else if *rewindDuration == -1 {
  30. sinceTimeNs = 0
  31. } else if *rewindDuration > 0 {
  32. sinceTimeNs = time.Now().Add(-*rewindDuration).UnixNano()
  33. }
  34. err := operation.TailVolume(*master, grpcDialOption, vid, uint64(sinceTimeNs), *timeoutSeconds, func(n *needle.Needle) (err error) {
  35. if n.Size == 0 {
  36. println("-", n.String())
  37. return nil
  38. } else {
  39. println("+", n.String())
  40. }
  41. if *showTextFile {
  42. data := n.Data
  43. if n.IsGzipped() {
  44. if data, err = util2.UnGzipData(data); err != nil {
  45. return err
  46. }
  47. }
  48. if util.IsText(data) {
  49. println(string(data))
  50. }
  51. println("-", n.String(), "compressed", n.IsGzipped(), "original size", len(data))
  52. }
  53. return nil
  54. })
  55. if err != nil {
  56. log.Printf("Error VolumeTailSender volume %d: %v", vid, err)
  57. }
  58. }