|
@ -14,6 +14,7 @@ import ( |
|
|
"runtime" |
|
|
"runtime" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"sync" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -48,6 +49,7 @@ var ( |
|
|
|
|
|
|
|
|
var topo *topology.Topology |
|
|
var topo *topology.Topology |
|
|
var vg *replication.VolumeGrowth |
|
|
var vg *replication.VolumeGrowth |
|
|
|
|
|
var vgLock sync.Mutex |
|
|
|
|
|
|
|
|
func dirLookupHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func dirLookupHandler(w http.ResponseWriter, r *http.Request) { |
|
|
vid := r.FormValue("volumeId") |
|
|
vid := r.FormValue("volumeId") |
|
@ -97,12 +99,16 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) { |
|
|
writeJsonQuiet(w, r, map[string]string{"error": "No free volumes left!"}) |
|
|
writeJsonQuiet(w, r, map[string]string{"error": "No free volumes left!"}) |
|
|
return |
|
|
return |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
vgLock.Lock() |
|
|
|
|
|
defer vgLock.Unlock() |
|
|
|
|
|
if topo.GetVolumeLayout(rt).GetActiveVolumeCount(dataCenter) <= 0 { |
|
|
if _, err = vg.AutomaticGrowByType(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()}) |
|
|
writeJsonQuiet(w, r, map[string]string{"error": "Cannot grow volume group! " + err.Error()}) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
fid, count, dn, err := topo.PickForWrite(rt, c, dataCenter) |
|
|
fid, count, dn, err := topo.PickForWrite(rt, c, dataCenter) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
writeJsonQuiet(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "publicUrl": dn.PublicUrl, "count": count}) |
|
|
writeJsonQuiet(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "publicUrl": dn.PublicUrl, "count": count}) |
|
|