From 9653a54766fbb7d9e7453c0df0eb0de016cfbce6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 16 Apr 2014 17:29:58 -0700 Subject: [PATCH] added typed join result --- go/operation/data_struts.go | 8 ++++++++ go/storage/store.go | 9 ++++----- go/weed/weed_server/master_server_handlers_admin.go | 7 +++---- go/weed/weed_server/volume_server.go | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 go/operation/data_struts.go diff --git a/go/operation/data_struts.go b/go/operation/data_struts.go new file mode 100644 index 000000000..09fab05d1 --- /dev/null +++ b/go/operation/data_struts.go @@ -0,0 +1,8 @@ +package operation + +import () + +type JoinResult struct { + VolumeSizeLimit uint64 `json:"VolumeSizeLimit,omitempty"` + Error string `json:"error,omitempty"` +} diff --git a/go/storage/store.go b/go/storage/store.go index 6a853122f..157344781 100644 --- a/go/storage/store.go +++ b/go/storage/store.go @@ -251,10 +251,6 @@ func (s *Store) Status() []*VolumeInfo { return stats } -type JoinResult struct { - VolumeSizeLimit uint64 -} - func (s *Store) SetDataCenter(dataCenter string) { s.dataCenter = dataCenter } @@ -303,10 +299,13 @@ func (s *Store) Join() error { s.masterNodes.reset() return err } - var ret JoinResult + var ret operation.JoinResult if err := json.Unmarshal(jsonBlob, &ret); err != nil { return err } + if ret.Error != "" { + return errors.New(ret.Error) + } s.volumeSizeLimit = ret.VolumeSizeLimit s.connected = true return nil diff --git a/go/weed/weed_server/master_server_handlers_admin.go b/go/weed/weed_server/master_server_handlers_admin.go index 44080d393..d34baa349 100644 --- a/go/weed/weed_server/master_server_handlers_admin.go +++ b/go/weed/weed_server/master_server_handlers_admin.go @@ -1,6 +1,7 @@ package weed_server import ( + "code.google.com/p/weed-fs/go/operation" "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/topology" "code.google.com/p/weed-fs/go/util" @@ -39,14 +40,12 @@ func (ms *MasterServer) dirJoinHandler(w http.ResponseWriter, r *http.Request) { publicUrl := r.FormValue("publicUrl") volumes := new([]storage.VolumeInfo) if err := json.Unmarshal([]byte(r.FormValue("volumes")), volumes); err != nil { - writeJsonQuiet(w, r, map[string]string{"error": "Cannot unmarshal \"volumes\": " + err.Error()}) + writeJsonQuiet(w, r, operation.JoinResult{Error: "Cannot unmarshal \"volumes\": " + err.Error()}) return } debug(s, "volumes", r.FormValue("volumes")) ms.Topo.RegisterVolumes(init, *volumes, ip, port, publicUrl, maxVolumeCount, r.FormValue("dataCenter"), r.FormValue("rack")) - m := make(map[string]interface{}) - m["VolumeSizeLimit"] = uint64(ms.volumeSizeLimitMB) * 1024 * 1024 - writeJsonQuiet(w, r, m) + writeJsonQuiet(w, r, operation.JoinResult{VolumeSizeLimit: uint64(ms.volumeSizeLimitMB) * 1024 * 1024}) } func (ms *MasterServer) dirStatusHandler(w http.ResponseWriter, r *http.Request) { diff --git a/go/weed/weed_server/volume_server.go b/go/weed/weed_server/volume_server.go index b522c160f..377e1e99c 100644 --- a/go/weed/weed_server/volume_server.go +++ b/go/weed/weed_server/volume_server.go @@ -57,6 +57,7 @@ func NewVolumeServer(r *http.ServeMux, ip string, port int, publicUrl string, fo glog.V(0).Infoln("Reconnected with master") } } else { + glog.V(4).Infoln("Failing to talk with master:", err.Error()) if connected { connected = false }