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.

69 lines
1.8 KiB

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