From 63ebafa113d0e9db11e85c8f199bc2b95a5cc84e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 24 Jul 2013 10:31:51 -0700 Subject: [PATCH] fix when volume growth are partial successful in automatic mode --- go/replication/volume_growth.go | 28 ++++++++++++++++++++-------- go/weed/master.go | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/go/replication/volume_growth.go b/go/replication/volume_growth.go index 6b3030293..d5950790d 100644 --- a/go/replication/volume_growth.go +++ b/go/replication/volume_growth.go @@ -32,22 +32,34 @@ func NewDefaultVolumeGrowth() *VolumeGrowth { return &VolumeGrowth{copy1factor: 7, copy2factor: 6, copy3factor: 3} } -func (vg *VolumeGrowth) GrowByType(repType storage.ReplicationType, dataCenter string, topo *topology.Topology) (int, error) { +func (vg *VolumeGrowth) AutomaticGrowByType(repType storage.ReplicationType, dataCenter string, topo *topology.Topology) (count int, err error) { + factor := 1 switch repType { case storage.Copy000: - return vg.GrowByCountAndType(vg.copy1factor, repType, dataCenter, topo) + factor = 1 + count, err = vg.GrowByCountAndType(vg.copy1factor, repType, dataCenter, topo) case storage.Copy001: - return vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) + factor = 2 + count, err = vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) case storage.Copy010: - return vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) + factor = 2 + count, err = vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) case storage.Copy100: - return vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) + factor = 2 + count, err = vg.GrowByCountAndType(vg.copy2factor, repType, dataCenter, topo) case storage.Copy110: - return vg.GrowByCountAndType(vg.copy3factor, repType, dataCenter, topo) + factor = 3 + count, err = vg.GrowByCountAndType(vg.copy3factor, repType, dataCenter, topo) case storage.Copy200: - return vg.GrowByCountAndType(vg.copy3factor, repType, dataCenter, topo) + factor = 3 + count, err = vg.GrowByCountAndType(vg.copy3factor, repType, dataCenter, topo) + default: + err = errors.New("Unknown Replication Type!") } - return 0, errors.New("Unknown Replication Type!") + if count > 0 && count%factor == 0 { + return count, nil + } + return count, err } func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.ReplicationType, dataCenter string, topo *topology.Topology) (counter int, err error) { vg.accessLock.Lock() diff --git a/go/weed/master.go b/go/weed/master.go index a37a8df5a..5ed3c43fd 100644 --- a/go/weed/master.go +++ b/go/weed/master.go @@ -91,7 +91,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) { writeJsonQuiet(w, r, map[string]string{"error": "No free volumes left!"}) return } else { - if _, err = vg.GrowByType(rt, dataCenter, topo); err != nil { + if _, err = vg.AutomaticGrowByType(rt, dataCenter, topo); err != nil { writeJsonQuiet(w, r, map[string]string{"error": "Cannot grow volume group! " + err.Error()}) return }