diff options
| author | liubaojiang <1838095916@qq.com> | 2022-05-31 09:40:25 +0800 |
|---|---|---|
| committer | liubaojiang <1838095916@qq.com> | 2022-05-31 09:49:07 +0800 |
| commit | f0ee3e6f2129eb2637ea0fdb18540f18147bf474 (patch) | |
| tree | 184eac4e7deb230474b8a2b30fa78e2de1b291cf | |
| parent | 076e48a6761396034b6c8132278330593ca698c5 (diff) | |
| download | seaweedfs-f0ee3e6f2129eb2637ea0fdb18540f18147bf474.tar.xz seaweedfs-f0ee3e6f2129eb2637ea0fdb18540f18147bf474.zip | |
reduce the scope of inFlightUploadDataLimitCond lock
| -rw-r--r-- | weed/server/volume_server_handlers.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/weed/server/volume_server_handlers.go b/weed/server/volume_server_handlers.go index aa231e650..7e4c11fed 100644 --- a/weed/server/volume_server_handlers.go +++ b/weed/server/volume_server_handlers.go @@ -58,31 +58,27 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque case "PUT", "POST": contentLength := getContentLength(r) - startTime := time.Now() - vs.inFlightUploadDataLimitCond.L.Lock() // exclude the replication from the concurrentUploadLimitMB if r.URL.Query().Get("type") != "replicate" { + startTime := time.Now() + vs.inFlightUploadDataLimitCond.L.Lock() for vs.concurrentUploadLimit != 0 && vs.inFlightUploadDataSize > vs.concurrentUploadLimit { - //wait timeout + //wait timeout check if startTime.Add(vs.inflightUploadDataTimeout).Before(time.Now()) { - err := fmt.Errorf("reject because inflight upload data %d > %d, and wait timeout", vs.inFlightUploadDataSize, vs.concurrentUploadLimit) vs.inFlightUploadDataLimitCond.L.Unlock() + err := fmt.Errorf("reject because inflight upload data %d > %d, and wait timeout", vs.inFlightUploadDataSize, vs.concurrentUploadLimit) glog.V(1).Infof("too many requests: %v", err) writeJsonError(w, r, http.StatusTooManyRequests, err) return } - glog.V(4).Infof("wait because inflight upload data %d > %d", vs.inFlightUploadDataSize, vs.concurrentUploadLimit) vs.inFlightUploadDataLimitCond.Wait() } + vs.inFlightUploadDataLimitCond.L.Unlock() } - vs.inFlightUploadDataSize += contentLength - vs.inFlightUploadDataLimitCond.L.Unlock() - + atomic.AddInt64(&vs.inFlightUploadDataSize, contentLength) defer func() { - vs.inFlightUploadDataLimitCond.L.Lock() - vs.inFlightUploadDataSize -= contentLength - vs.inFlightUploadDataLimitCond.L.Unlock() + atomic.AddInt64(&vs.inFlightUploadDataSize, -contentLength) vs.inFlightUploadDataLimitCond.Signal() }() |
