|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security" |
|
|
@ -119,6 +120,13 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request) |
|
|
|
|
|
|
|
vl := ms.Topo.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.DiskType) |
|
|
|
|
|
|
|
var ( |
|
|
|
lastErr error |
|
|
|
maxTimeout = time.Second * 10 |
|
|
|
startTime = time.Now() |
|
|
|
) |
|
|
|
|
|
|
|
for time.Now().Sub(startTime) < maxTimeout { |
|
|
|
fid, count, dnList, shouldGrow, err := ms.Topo.PickForWrite(requestedCount, option, vl) |
|
|
|
if shouldGrow && !vl.HasGrowRequest() { |
|
|
|
// if picked volume is almost full, trigger a volume-grow request
|
|
|
@ -140,13 +148,24 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if err == nil { |
|
|
|
if err != nil { |
|
|
|
// glog.Warningf("PickForWrite %+v: %v", req, err)
|
|
|
|
lastErr = err |
|
|
|
time.Sleep(200 * time.Millisecond) |
|
|
|
continue |
|
|
|
} else { |
|
|
|
ms.maybeAddJwtAuthorization(w, fid, true) |
|
|
|
dn := dnList.Head() |
|
|
|
|
|
|
|
writeJsonQuiet(w, r, http.StatusOK, operation.AssignResult{Fid: fid, Url: dn.Url(), PublicUrl: dn.PublicUrl, Count: count}) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if lastErr != nil { |
|
|
|
writeJsonQuiet(w, r, http.StatusNotAcceptable, operation.AssignResult{Error: lastErr.Error()}) |
|
|
|
} else { |
|
|
|
writeJsonQuiet(w, r, http.StatusNotAcceptable, operation.AssignResult{Error: err.Error()}) |
|
|
|
writeJsonQuiet(w, r, http.StatusRequestTimeout, operation.AssignResult{Error: "request timeout"}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|