From 44647a46c0dc82350cc994da0784f3c3936270d6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 17 Mar 2019 23:28:43 -0700 Subject: [PATCH] needle scanner read appendAtNs --- unmaintained/see_dat/see_dat.go | 6 ++++-- weed/storage/needle_read_write.go | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/unmaintained/see_dat/see_dat.go b/unmaintained/see_dat/see_dat.go index f79c0a6a9..28d6447d6 100644 --- a/unmaintained/see_dat/see_dat.go +++ b/unmaintained/see_dat/see_dat.go @@ -4,6 +4,7 @@ import ( "flag" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/storage" + "time" ) var ( @@ -22,11 +23,12 @@ func (scanner *VolumeFileScanner4SeeDat) VisitSuperBlock(superBlock storage.Supe } func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool { - return false + return true } func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *storage.Needle, offset int64) error { - glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie) + t := time.Unix(int64(n.AppendAtNs)/int64(time.Second), int64(n.AppendAtNs)%int64(time.Second)) + glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie, t) return nil } diff --git a/weed/storage/needle_read_write.go b/weed/storage/needle_read_write.go index c99395f8b..e69d70dc3 100644 --- a/weed/storage/needle_read_write.go +++ b/weed/storage/needle_read_write.go @@ -283,6 +283,7 @@ func NeedleBodyLength(needleSize uint32, version Version) int64 { //n should be a needle already read the header //the input stream will read until next file entry func (n *Needle) ReadNeedleBody(r *os.File, version Version, offset int64, bodyLength int64) (err error) { + if bodyLength <= 0 { return nil } @@ -301,6 +302,11 @@ func (n *Needle) ReadNeedleBody(r *os.File, version Version, offset int64, bodyL } n.readNeedleDataVersion2(bytes[0:n.Size]) n.Checksum = NewCRC(n.Data) + + if version == Version3 { + tsOffset := n.Size+NeedleChecksumSize + n.AppendAtNs = util.BytesToUint64(bytes[tsOffset : tsOffset+TimestampSize]) + } default: err = fmt.Errorf("Unsupported Version! (%d)", version) }