From 089eb8ad3900d6e61343d6606f094a2ffe9b0a9e Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Fri, 26 Dec 2014 13:29:44 +0800 Subject: [PATCH 1/3] add String function for needle to print --- go/storage/needle.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/go/storage/needle.go b/go/storage/needle.go index aa3206920..5b4357614 100644 --- a/go/storage/needle.go +++ b/go/storage/needle.go @@ -3,6 +3,7 @@ package storage import ( "encoding/hex" "errors" + "fmt" "io/ioutil" "mime" "net/http" @@ -45,6 +46,11 @@ type Needle struct { Padding []byte `comment:"Aligned to 8 bytes"` } +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) + return +} + func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string, isGzipped bool, modifiedTime uint64, ttl *TTL, e error) { form, fe := r.MultipartReader() if fe != nil { From 5a40f539f23bbc262c3a10f64cc53bba67b3df21 Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Fri, 26 Dec 2014 15:36:33 +0800 Subject: [PATCH 2/3] fix bug: upload a file which already existed return a wrong file size. --- go/storage/needle.go | 1 + go/storage/store.go | 12 ++++++++++++ go/storage/volume.go | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/go/storage/needle.go b/go/storage/needle.go index 5b4357614..11610dd80 100644 --- a/go/storage/needle.go +++ b/go/storage/needle.go @@ -25,6 +25,7 @@ const ( ) /* +* A Needle means a uploaded and stored file. * Needle file size is limited to 4GB for now. */ type Needle struct { diff --git a/go/storage/store.go b/go/storage/store.go index 80d8a30b8..e1d9d2b01 100644 --- a/go/storage/store.go +++ b/go/storage/store.go @@ -33,6 +33,10 @@ type MasterNodes struct { lastNode int } +func (mn *MasterNodes) String() string { + return fmt.Sprintf("nodes:%v, lastNode:%d", mn.nodes, mn.lastNode) +} + func NewMasterNodes(bootstrapNode string) (mn *MasterNodes) { mn = &MasterNodes{nodes: []string{bootstrapNode}, lastNode: -1} return @@ -65,6 +69,9 @@ func (mn *MasterNodes) findMaster() (string, error) { return mn.nodes[mn.lastNode], nil } +/* + * A VolumeServer contains one Store + */ type Store struct { Port int Ip string @@ -77,6 +84,11 @@ type Store struct { masterNodes *MasterNodes } +func (s *Store) String() (str string) { + str = fmt.Sprintf("Ip:%s, Port:%d, PublicUrl:%s, dataCenter:%s, rack:%s, connected:%v, volumeSizeLimit:%d, masterNodes:%s", s.Ip, s.Port, s.PublicUrl, s.dataCenter, s.rack, s.connected, s.volumeSizeLimit, s.masterNodes) + return +} + func NewStore(port int, ip, publicUrl string, dirnames []string, maxVolumeCounts []int) (s *Store) { s = &Store{Port: port, Ip: ip, PublicUrl: publicUrl} s.Locations = make([]*DiskLocation, 0) diff --git a/go/storage/volume.go b/go/storage/volume.go index 5b0a83605..a1eccd62c 100644 --- a/go/storage/volume.go +++ b/go/storage/volume.go @@ -33,6 +33,10 @@ func NewVolume(dirname string, collection string, id VolumeId, replicaPlacement e = v.load(true, true) return } +func (v *Volume) String() string { + return fmt.Sprintf("Id:%v, dir:%s, Collection:%s, dataFile:%v, nm:%v, readOnly:%v", v.Id, v.dir, v.Collection, v.dataFile, v.nm, v.readOnly) +} + func loadVolumeWithoutIndex(dirname string, collection string, id VolumeId) (v *Volume, e error) { v = &Volume{dir: dirname, Collection: collection, Id: id} v.SuperBlock = SuperBlock{} @@ -135,7 +139,7 @@ func (v *Volume) isFileUnchanged(n *Needle) bool { oldNeedle := new(Needle) oldNeedle.Read(v.dataFile, int64(nv.Offset)*NeedlePaddingSize, nv.Size, v.Version()) if oldNeedle.Checksum == n.Checksum && bytes.Equal(oldNeedle.Data, n.Data) { - n.Size = oldNeedle.Size + n.DataSize = oldNeedle.DataSize return true } } @@ -165,7 +169,7 @@ func (v *Volume) write(n *Needle) (size uint32, err error) { v.accessLock.Lock() defer v.accessLock.Unlock() if v.isFileUnchanged(n) { - size = n.Size + size = n.DataSize glog.V(4).Infof("needle is unchanged!") return } From 5b7628cf08b246bb8dd075a28f29e1bd3401eb2d Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Fri, 26 Dec 2014 16:59:53 +0800 Subject: [PATCH 3/3] use github.com/golang/protobuf/proto instead of code.google.com/p/goprotobuf/proto --- go/operation/system_message.pb.go | 2 +- go/operation/system_message_test.go | 2 +- go/storage/store.go | 2 +- go/weed/weed_server/master_server_handlers_admin.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/operation/system_message.pb.go b/go/operation/system_message.pb.go index 9f00dd74d..6f0f974c5 100644 --- a/go/operation/system_message.pb.go +++ b/go/operation/system_message.pb.go @@ -14,7 +14,7 @@ It has these top-level messages: */ package operation -import proto "code.google.com/p/goprotobuf/proto" +import "github.com/golang/protobuf/proto" import math "math" // Reference imports to suppress errors if they are not otherwise used. diff --git a/go/operation/system_message_test.go b/go/operation/system_message_test.go index b5624c258..d18ca49a4 100644 --- a/go/operation/system_message_test.go +++ b/go/operation/system_message_test.go @@ -5,7 +5,7 @@ import ( "log" "testing" - proto "code.google.com/p/goprotobuf/proto" + "github.com/golang/protobuf/proto" ) func TestSerialDeserial(t *testing.T) { diff --git a/go/storage/store.go b/go/storage/store.go index e1d9d2b01..65eed1d0e 100644 --- a/go/storage/store.go +++ b/go/storage/store.go @@ -9,10 +9,10 @@ import ( "strconv" "strings" - proto "code.google.com/p/goprotobuf/proto" "github.com/chrislusf/weed-fs/go/glog" "github.com/chrislusf/weed-fs/go/operation" "github.com/chrislusf/weed-fs/go/util" + "github.com/golang/protobuf/proto" ) const ( diff --git a/go/weed/weed_server/master_server_handlers_admin.go b/go/weed/weed_server/master_server_handlers_admin.go index d7124e567..75e059365 100644 --- a/go/weed/weed_server/master_server_handlers_admin.go +++ b/go/weed/weed_server/master_server_handlers_admin.go @@ -8,12 +8,12 @@ import ( "strconv" "strings" - proto "code.google.com/p/goprotobuf/proto" "github.com/chrislusf/weed-fs/go/glog" "github.com/chrislusf/weed-fs/go/operation" "github.com/chrislusf/weed-fs/go/storage" "github.com/chrislusf/weed-fs/go/topology" "github.com/chrislusf/weed-fs/go/util" + "github.com/golang/protobuf/proto" ) func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.Request) {