From 852af28f91262ce8e0eb6862b4d679a83f1f9ca5 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 21 Jul 2018 17:41:21 -0700 Subject: [PATCH] needle priting format --- weed/server/volume_server_handlers_write.go | 4 ++-- weed/storage/file_id.go | 10 +++++++--- weed/storage/needle.go | 12 ++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/weed/server/volume_server_handlers_write.go b/weed/server/volume_server_handlers_write.go index 55ef2a613..02eb6dff9 100644 --- a/weed/server/volume_server_handlers_write.go +++ b/weed/server/volume_server_handlers_write.go @@ -9,8 +9,8 @@ import ( "github.com/chrislusf/seaweedfs/weed/operation" "github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/topology" - "time" "strconv" + "time" ) func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) { @@ -55,7 +55,7 @@ func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) { volumeId, _ := storage.NewVolumeId(vid) n.ParsePath(fid) - glog.V(2).Infoln("deleting", n) + glog.V(2).Infof("volume %d deleting %s", vid, n) cookie := n.Cookie diff --git a/weed/storage/file_id.go b/weed/storage/file_id.go index 0871bfb25..37dcb7c70 100644 --- a/weed/storage/file_id.go +++ b/weed/storage/file_id.go @@ -20,11 +20,15 @@ func NewFileId(VolumeId VolumeId, key uint64, cookie uint32) *FileId { } func (n *FileId) String() string { + return n.VolumeId.String() + "," + formatNeedleIdCookie(n.Key, n.Cookie) +} + +func formatNeedleIdCookie(key NeedleId, cookie Cookie) string { bytes := make([]byte, NeedleIdSize+CookieSize) - NeedleIdToBytes(bytes[0:NeedleIdSize], n.Key) - CookieToBytes(bytes[NeedleIdSize:NeedleIdSize+CookieSize], n.Cookie) + NeedleIdToBytes(bytes[0:NeedleIdSize], key) + CookieToBytes(bytes[NeedleIdSize:NeedleIdSize+CookieSize], cookie) nonzero_index := 0 for ; bytes[nonzero_index] == 0; nonzero_index++ { } - return n.VolumeId.String() + "," + hex.EncodeToString(bytes[nonzero_index:]) + return hex.EncodeToString(bytes[nonzero_index:]) } diff --git a/weed/storage/needle.go b/weed/storage/needle.go index 46ba933ca..31bada091 100644 --- a/weed/storage/needle.go +++ b/weed/storage/needle.go @@ -29,12 +29,12 @@ type Needle struct { DataSize uint32 `comment:"Data size"` //version2 Data []byte `comment:"The actual file data"` - Flags byte `comment:"boolean flags"` //version2 - NameSize uint8 //version2 + Flags byte `comment:"boolean flags"` //version2 + NameSize uint8 //version2 Name []byte `comment:"maximum 256 characters"` //version2 - MimeSize uint8 //version2 + MimeSize uint8 //version2 Mime []byte `comment:"maximum 256 characters"` //version2 - PairsSize uint16 //version2 + PairsSize uint16 //version2 Pairs []byte `comment:"additional name value pairs, json format, maximum 64kB"` LastModified uint64 //only store LastModifiedBytesLength bytes, which is 5 bytes to disk Ttl *TTL @@ -44,7 +44,7 @@ type Needle struct { } func (n *Needle) String() (str string) { - str = fmt.Sprintf("Cookie:%d, Id:%d, Size:%d, DataSize:%d, Name: %s, Mime: %s", n.Cookie, n.Id, n.Size, n.DataSize, n.Name, n.Mime) + str = fmt.Sprintf("%s Size:%d, DataSize:%d, Name:%s, Mime:%s", formatNeedleIdCookie(n.Id, n.Cookie), n.Size, n.DataSize, n.Name, n.Mime) return } @@ -134,7 +134,7 @@ func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) { dotSep := strings.LastIndex(r.URL.Path, ".") fid := r.URL.Path[commaSep+1:] if dotSep > 0 { - fid = r.URL.Path[commaSep+1: dotSep] + fid = r.URL.Path[commaSep+1 : dotSep] } e = n.ParsePath(fid)