fix when volume growth are partial successful in automatic mode

This commit is contained in:
Chris Lu 2013-07-24 10:31:51 -07:00
parent 3ae2eabf09
commit 63ebafa113
2 changed files with 21 additions and 9 deletions

View file

@ -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()

View file

@ -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
}