From 73958e357dba827cd82e3ed8b277d865aae37a72 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 18 Feb 2021 19:10:20 -0800 Subject: [PATCH] add descriptive error if no free volumes --- weed/server/master_grpc_server_volume.go | 2 +- weed/server/master_server_handlers.go | 2 +- weed/storage/super_block/replica_placement.go | 6 ++--- weed/topology/volume_growth.go | 22 ++++++++++--------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/weed/server/master_grpc_server_volume.go b/weed/server/master_grpc_server_volume.go index 1699eaa36..29aff5c0b 100644 --- a/weed/server/master_grpc_server_volume.go +++ b/weed/server/master_grpc_server_volume.go @@ -77,7 +77,7 @@ func (ms *MasterServer) Assign(ctx context.Context, req *master_pb.AssignRequest if !ms.Topo.HasWritableVolume(option) { if ms.Topo.AvailableSpaceFor(option) <= 0 { - return nil, fmt.Errorf("No free volumes left!") + return nil, fmt.Errorf("no free volumes left for "+option.String()) } ms.vgLock.Lock() if !ms.Topo.HasWritableVolume(option) { diff --git a/weed/server/master_server_handlers.go b/weed/server/master_server_handlers.go index 117423ec6..a9fecc5bd 100644 --- a/weed/server/master_server_handlers.go +++ b/weed/server/master_server_handlers.go @@ -113,7 +113,7 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request) if !ms.Topo.HasWritableVolume(option) { if ms.Topo.AvailableSpaceFor(option) <= 0 { - writeJsonQuiet(w, r, http.StatusNotFound, operation.AssignResult{Error: "No free volumes left!"}) + writeJsonQuiet(w, r, http.StatusNotFound, operation.AssignResult{Error: "No free volumes left for " + option.String()}) return } ms.vgLock.Lock() diff --git a/weed/storage/super_block/replica_placement.go b/weed/storage/super_block/replica_placement.go index fcccbba7d..65ec53819 100644 --- a/weed/storage/super_block/replica_placement.go +++ b/weed/storage/super_block/replica_placement.go @@ -6,9 +6,9 @@ import ( ) type ReplicaPlacement struct { - SameRackCount int - DiffRackCount int - DiffDataCenterCount int + SameRackCount int `json:"node,omitempty"` + DiffRackCount int `json:"rack,omitempty"` + DiffDataCenterCount int `json:"dc,omitempty"` } func NewReplicaPlacementFromString(t string) (*ReplicaPlacement, error) { diff --git a/weed/topology/volume_growth.go b/weed/topology/volume_growth.go index 4b0a4837e..8941a049b 100644 --- a/weed/topology/volume_growth.go +++ b/weed/topology/volume_growth.go @@ -1,6 +1,7 @@ package topology import ( + "encoding/json" "fmt" "github.com/chrislusf/seaweedfs/weed/storage/types" "math/rand" @@ -25,15 +26,15 @@ This package is created to resolve these replica placement issues: */ type VolumeGrowOption struct { - Collection string - ReplicaPlacement *super_block.ReplicaPlacement - Ttl *needle.TTL - DiskType types.DiskType - Prealloacte int64 - DataCenter string - Rack string - DataNode string - MemoryMapMaxSizeMb uint32 + Collection string `json:"collection,omitempty"` + ReplicaPlacement *super_block.ReplicaPlacement `json:"replication,omitempty"` + Ttl *needle.TTL `json:"ttl,omitempty"` + DiskType types.DiskType `json:"disk,omitempty"` + Prealloacte int64 `json:"prealloacte,omitempty"` + DataCenter string `json:"dataCenter,omitempty"` + Rack string `json:"rack,omitempty"` + DataNode string `json:"dataNode,omitempty"` + MemoryMapMaxSizeMb uint32 `json:"memoryMapMaxSizeMb,omitempty"` } type VolumeGrowth struct { @@ -41,7 +42,8 @@ type VolumeGrowth struct { } func (o *VolumeGrowOption) String() string { - return fmt.Sprintf("Collection:%s, ReplicaPlacement:%v, Ttl:%v, DataCenter:%s, Rack:%s, DataNode:%s", o.Collection, o.ReplicaPlacement, o.Ttl, o.DataCenter, o.Rack, o.DataNode) + blob, _ := json.Marshal(o) + return string(blob) } func NewDefaultVolumeGrowth() *VolumeGrowth {