diff options
| author | chrislu <chris.lu@gmail.com> | 2023-11-09 08:02:57 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2023-11-09 08:02:57 -0800 |
| commit | 85bed4d92e3bbb44db6ac4e6d17a3d2e079c226b (patch) | |
| tree | ca4de2e4610e7a73e769d1125caface28db6f1a8 /weed | |
| parent | c563386675010969ddb6e75c604ea65427ab59c8 (diff) | |
| parent | a1c6f1fbd68b64a4546ea00d1adf33ada95f024b (diff) | |
| download | seaweedfs-85bed4d92e3bbb44db6ac4e6d17a3d2e079c226b.tar.xz seaweedfs-85bed4d92e3bbb44db6ac4e6d17a3d2e079c226b.zip | |
Merge branch 'master' of https://github.com/seaweedfs/seaweedfs
Diffstat (limited to 'weed')
| -rw-r--r-- | weed/server/volume_server_handlers.go | 26 | ||||
| -rw-r--r-- | weed/server/webdav_server.go | 3 | ||||
| -rw-r--r-- | weed/shell/command_volume_fix_replication.go | 6 |
3 files changed, 22 insertions, 13 deletions
diff --git a/weed/server/volume_server_handlers.go b/weed/server/volume_server_handlers.go index dcb92aa6b..9523eee56 100644 --- a/weed/server/volume_server_handlers.go +++ b/weed/server/volume_server_handlers.go @@ -36,13 +36,14 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Credentials", "true") } - stats.VolumeServerRequestCounter.WithLabelValues(r.Method).Inc() start := time.Now() - defer func(start time.Time) { - stats.VolumeServerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) - }(start) + requestMethod := r.Method + defer func(start time.Time, method *string) { + stats.VolumeServerRequestCounter.WithLabelValues(*method).Inc() + stats.VolumeServerRequestHistogram.WithLabelValues(*method).Observe(time.Since(start).Seconds()) + }(start, &requestMethod) switch r.Method { - case "GET", "HEAD": + case http.MethodGet, http.MethodHead: stats.ReadRequest() vs.inFlightDownloadDataLimitCond.L.Lock() inFlightDownloadSize := atomic.LoadInt64(&vs.inFlightDownloadDataSize) @@ -61,10 +62,12 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque } vs.inFlightDownloadDataLimitCond.L.Unlock() vs.GetOrHeadHandler(w, r) - case "DELETE": + case http.MethodDelete: + stats.VolumeServerRequestCounter.WithLabelValues(r.Method).Inc() stats.DeleteRequest() vs.guard.WhiteList(vs.DeleteHandler)(w, r) - case "PUT", "POST": + case http.MethodPut, http.MethodPost: + stats.VolumeServerRequestCounter.WithLabelValues(r.Method).Inc() contentLength := getContentLength(r) // exclude the replication from the concurrentUploadLimitMB if r.URL.Query().Get("type") != "replicate" && vs.concurrentUploadLimit != 0 { @@ -98,10 +101,13 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque stats.WriteRequest() vs.guard.WhiteList(vs.PostHandler)(w, r) - case "OPTIONS": + case http.MethodOptions: stats.ReadRequest() w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS") w.Header().Add("Access-Control-Allow-Headers", "*") + default: + requestMethod = "INVALID" + writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("unsupported method %s", r.Method)) } } @@ -124,7 +130,7 @@ func (vs *VolumeServer) publicReadOnlyHandler(w http.ResponseWriter, r *http.Req w.Header().Set("Access-Control-Allow-Credentials", "true") } switch r.Method { - case "GET", "HEAD": + case http.MethodGet, http.MethodHead: stats.ReadRequest() vs.inFlightDownloadDataLimitCond.L.Lock() inFlightDownloadSize := atomic.LoadInt64(&vs.inFlightDownloadDataSize) @@ -135,7 +141,7 @@ func (vs *VolumeServer) publicReadOnlyHandler(w http.ResponseWriter, r *http.Req } vs.inFlightDownloadDataLimitCond.L.Unlock() vs.GetOrHeadHandler(w, r) - case "OPTIONS": + case http.MethodOptions: stats.ReadRequest() w.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS") w.Header().Add("Access-Control-Allow-Headers", "*") diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index 945c68279..35c554839 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -568,6 +568,9 @@ func (f *WebDavFile) Readdir(count int) (ret []os.FileInfo, err error) { ret = append(ret, &fi) return nil }) + if err != nil { + return nil, err + } old := f.off if old >= int64(len(ret)) { diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 43db0ff3b..9b6a64e6f 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -572,12 +572,12 @@ func isMisplaced(replicas []*VolumeReplica, replicaPlacement *super_block.Replic for i := 0; i < len(replicas); i++ { others := otherThan(replicas, i) - if satisfyReplicaPlacement(replicaPlacement, others, *replicas[i].location) { - return false + if !satisfyReplicaPlacement(replicaPlacement, others, *replicas[i].location) { + return true } } - return true + return false } |
