2019-04-18 18:05:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2021-09-13 05:47:52 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2019-04-19 04:17:43 +00:00
|
|
|
"log"
|
|
|
|
"time"
|
2019-04-18 18:05:02 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/security"
|
2019-04-19 04:43:36 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
util2 "github.com/chrislusf/seaweedfs/weed/util"
|
2019-04-19 02:22:13 +00:00
|
|
|
"golang.org/x/tools/godoc/util"
|
2019-04-18 18:05:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
master = flag.String("master", "localhost:9333", "master server host and port")
|
|
|
|
volumeId = flag.Int("volumeId", -1, "a volume id")
|
2019-04-19 04:17:43 +00:00
|
|
|
rewindDuration = flag.Duration("rewind", -1, "rewind back in time. -1 means from the first entry. 0 means from now.")
|
2019-04-18 18:05:02 +00:00
|
|
|
timeoutSeconds = flag.Int("timeoutSeconds", 0, "disconnect if no activity after these seconds")
|
2019-04-19 02:22:13 +00:00
|
|
|
showTextFile = flag.Bool("showTextFile", false, "display textual file content")
|
2019-04-18 18:05:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
util2.LoadConfiguration("security", false)
|
2020-05-25 12:45:21 +00:00
|
|
|
grpcDialOption := security.LoadClientTLS(util2.GetViper(), "grpc.client")
|
2019-04-18 18:05:02 +00:00
|
|
|
|
2019-04-19 04:43:36 +00:00
|
|
|
vid := needle.VolumeId(*volumeId)
|
2019-04-18 18:05:02 +00:00
|
|
|
|
2019-04-19 04:17:43 +00:00
|
|
|
var sinceTimeNs int64
|
|
|
|
if *rewindDuration == 0 {
|
|
|
|
sinceTimeNs = time.Now().UnixNano()
|
|
|
|
} else if *rewindDuration == -1 {
|
|
|
|
sinceTimeNs = 0
|
|
|
|
} else if *rewindDuration > 0 {
|
|
|
|
sinceTimeNs = time.Now().Add(-*rewindDuration).UnixNano()
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
err := operation.TailVolume(func()pb.ServerAddress{return pb.ServerAddress(*master)}, grpcDialOption, vid, uint64(sinceTimeNs), *timeoutSeconds, func(n *needle.Needle) (err error) {
|
2019-04-19 03:04:44 +00:00
|
|
|
if n.Size == 0 {
|
|
|
|
println("-", n.String())
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
println("+", n.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if *showTextFile {
|
|
|
|
|
|
|
|
data := n.Data
|
2020-06-20 05:45:27 +00:00
|
|
|
if n.IsCompressed() {
|
2020-06-20 15:16:16 +00:00
|
|
|
if data, err = util2.DecompressData(data); err != nil {
|
2019-04-19 03:04:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if util.IsText(data) {
|
|
|
|
println(string(data))
|
|
|
|
}
|
|
|
|
|
2020-06-20 05:45:27 +00:00
|
|
|
println("-", n.String(), "compressed", n.IsCompressed(), "original size", len(data))
|
2019-04-19 03:04:44 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2019-04-20 18:35:20 +00:00
|
|
|
log.Printf("Error VolumeTailSender volume %d: %v", vid, err)
|
2019-04-19 03:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|