mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-23 07:43:37 +08:00
volume: fail fast if too many concurrent requests, to avoid dead lock due to replication.
fix https://github.com/chrislusf/seaweedfs/issues/2755
This commit is contained in:
@@ -84,7 +84,6 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
|||||||
fileSizeLimitBytes: int64(fileSizeLimitMB) * 1024 * 1024,
|
fileSizeLimitBytes: int64(fileSizeLimitMB) * 1024 * 1024,
|
||||||
isHeartbeating: true,
|
isHeartbeating: true,
|
||||||
stopChan: make(chan bool),
|
stopChan: make(chan bool),
|
||||||
inFlightUploadDataLimitCond: sync.NewCond(new(sync.Mutex)),
|
|
||||||
inFlightDownloadDataLimitCond: sync.NewCond(new(sync.Mutex)),
|
inFlightDownloadDataLimitCond: sync.NewCond(new(sync.Mutex)),
|
||||||
concurrentUploadLimit: concurrentUploadLimit,
|
concurrentUploadLimit: concurrentUploadLimit,
|
||||||
concurrentDownloadLimit: concurrentDownloadLimit,
|
concurrentDownloadLimit: concurrentDownloadLimit,
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package weed_server
|
package weed_server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -51,12 +52,12 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque
|
|||||||
|
|
||||||
// wait until in flight data is less than the limit
|
// wait until in flight data is less than the limit
|
||||||
contentLength := getContentLength(r)
|
contentLength := getContentLength(r)
|
||||||
vs.inFlightUploadDataLimitCond.L.Lock()
|
|
||||||
for vs.concurrentUploadLimit != 0 && atomic.LoadInt64(&vs.inFlightUploadDataSize) > vs.concurrentUploadLimit {
|
for vs.concurrentUploadLimit != 0 && atomic.LoadInt64(&vs.inFlightUploadDataSize) > vs.concurrentUploadLimit {
|
||||||
glog.V(4).Infof("wait because inflight upload data %d > %d", vs.inFlightUploadDataSize, vs.concurrentUploadLimit)
|
err := fmt.Errorf("reject because inflight upload data %d > %d", vs.inFlightUploadDataSize, vs.concurrentUploadLimit)
|
||||||
vs.inFlightUploadDataLimitCond.Wait()
|
glog.V(1).Infof("too many requests: %v", err)
|
||||||
|
writeJsonError(w, r, http.StatusTooManyRequests, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
vs.inFlightUploadDataLimitCond.L.Unlock()
|
|
||||||
atomic.AddInt64(&vs.inFlightUploadDataSize, contentLength)
|
atomic.AddInt64(&vs.inFlightUploadDataSize, contentLength)
|
||||||
defer func() {
|
defer func() {
|
||||||
atomic.AddInt64(&vs.inFlightUploadDataSize, -contentLength)
|
atomic.AddInt64(&vs.inFlightUploadDataSize, -contentLength)
|
||||||
|
Reference in New Issue
Block a user