seaweedfs/unmaintained/volume_tailer/volume_tailer.go

74 lines
2.0 KiB
Go
Raw Permalink Normal View History

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