From 53be97d5bea8b44db40077c62af5e224e21be3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien?= Date: Tue, 16 Jan 2024 16:40:21 +0100 Subject: [PATCH 1/8] Fix(k8s-chart-helm): `helm upgrade` statefulset error (#5207) --- k8s/charts/seaweedfs/templates/filer-statefulset.yaml | 1 - k8s/charts/seaweedfs/templates/master-statefulset.yaml | 1 - k8s/charts/seaweedfs/templates/volume-statefulset.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/k8s/charts/seaweedfs/templates/filer-statefulset.yaml b/k8s/charts/seaweedfs/templates/filer-statefulset.yaml index 6ee847b91..c8e10f21a 100644 --- a/k8s/charts/seaweedfs/templates/filer-statefulset.yaml +++ b/k8s/charts/seaweedfs/templates/filer-statefulset.yaml @@ -23,7 +23,6 @@ spec: selector: matchLabels: app.kubernetes.io/name: {{ template "seaweedfs.name" . }} - helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: filer template: diff --git a/k8s/charts/seaweedfs/templates/master-statefulset.yaml b/k8s/charts/seaweedfs/templates/master-statefulset.yaml index 03d5d2959..0a7e6198a 100644 --- a/k8s/charts/seaweedfs/templates/master-statefulset.yaml +++ b/k8s/charts/seaweedfs/templates/master-statefulset.yaml @@ -22,7 +22,6 @@ spec: selector: matchLabels: app.kubernetes.io/name: {{ template "seaweedfs.name" . }} - helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: master template: diff --git a/k8s/charts/seaweedfs/templates/volume-statefulset.yaml b/k8s/charts/seaweedfs/templates/volume-statefulset.yaml index 5375a4b7c..e03db4ba7 100644 --- a/k8s/charts/seaweedfs/templates/volume-statefulset.yaml +++ b/k8s/charts/seaweedfs/templates/volume-statefulset.yaml @@ -16,7 +16,6 @@ spec: selector: matchLabels: app.kubernetes.io/name: {{ template "seaweedfs.name" . }} - helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: volume template: From 2eb82778bc85474ef71e5c923780dd141c12856f Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Wed, 17 Jan 2024 10:10:17 -0500 Subject: [PATCH 2/8] chore: fix typos in scaffold help output (#5211) --- weed/command/scaffold.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/weed/command/scaffold.go b/weed/command/scaffold.go index b37254bb5..5d1ccb13f 100644 --- a/weed/command/scaffold.go +++ b/weed/command/scaffold.go @@ -21,9 +21,9 @@ var cmdScaffold = &Command{ For example, the filer.toml mysql password can be overwritten by environment variable export WEED_MYSQL_PASSWORD=some_password Environment variable rules: - * Prefix the variable name with "WEED_" - * Uppercase the reset of variable name. - * Replace '.' with '_' + * Prefix the variable name with "WEED_". + * Uppercase the rest of the variable name. + * Replace '.' with '_'. `, } From f9cf13fada9ca6f99a87dc474959748c41f67ac7 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:17:07 +0500 Subject: [PATCH 3/8] [filer] avoid return http ok for not allowed methods (#5209) --- weed/server/filer_server_handlers.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go index ac66514f2..c1b883f38 100644 --- a/weed/server/filer_server_handlers.go +++ b/weed/server/filer_server_handlers.go @@ -44,7 +44,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS") } - if r.Method == "OPTIONS" { + if r.Method == http.MethodOptions { OptionsHandler(w, r, false) return } @@ -66,7 +66,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) }() - isReadHttpCall := r.Method == "GET" || r.Method == "HEAD" + isReadHttpCall := r.Method == http.MethodGet || r.Method == http.MethodHead if !fs.maybeCheckJwtAuthorization(r, !isReadHttpCall) { writeJsonError(w, r, http.StatusUnauthorized, errors.New("wrong jwt")) return @@ -75,17 +75,15 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) switch r.Method { - case "GET": + case http.MethodGet, http.MethodHead: fs.GetOrHeadHandler(w, r) - case "HEAD": - fs.GetOrHeadHandler(w, r) - case "DELETE": + case http.MethodDelete: if _, ok := r.URL.Query()["tagging"]; ok { fs.DeleteTaggingHandler(w, r) } else { fs.DeleteHandler(w, r) } - case "POST", "PUT": + case http.MethodPost, http.MethodPut: // wait until in flight data is less than the limit contentLength := getContentLength(r) fs.inFlightDataLimitCond.L.Lock() @@ -102,7 +100,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { fs.inFlightDataLimitCond.Signal() }() - if r.Method == "PUT" { + if r.Method == http.MethodPut { if _, ok := r.URL.Query()["tagging"]; ok { fs.PutTaggingHandler(w, r) } else { @@ -111,6 +109,8 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { } else { // method == "POST" fs.PostHandler(w, r, contentLength) } + default: + w.WriteHeader(http.StatusMethodNotAllowed) } } @@ -149,7 +149,7 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) }() // We handle OPTIONS first because it never should be authenticated - if r.Method == "OPTIONS" { + if r.Method == http.MethodOptions { OptionsHandler(w, r, true) return } @@ -162,10 +162,10 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) switch r.Method { - case "GET": - fs.GetOrHeadHandler(w, r) - case "HEAD": + case http.MethodGet, http.MethodHead: fs.GetOrHeadHandler(w, r) + default: + w.WriteHeader(http.StatusMethodNotAllowed) } } From 4e9ea1e628a4d2105a758d12673efdeebe43ebaa Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:46:37 +0500 Subject: [PATCH 4/8] chore: filer healthz handler check filer store (#5208) --- weed/server/filer_server.go | 1 + weed/server/filer_server_handlers.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go index d8b2ad8dc..a04fd1910 100644 --- a/weed/server/filer_server.go +++ b/weed/server/filer_server.go @@ -171,6 +171,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) } if defaultMux != readonlyMux { handleStaticResources(readonlyMux) + readonlyMux.HandleFunc("/healthz", fs.filerHealthzHandler) readonlyMux.HandleFunc("/", fs.readonlyFilerHandler) } diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go index c1b883f38..b5e070fb2 100644 --- a/weed/server/filer_server_handlers.go +++ b/weed/server/filer_server_handlers.go @@ -1,6 +1,7 @@ package weed_server import ( + "context" "errors" "net/http" "os" @@ -9,7 +10,9 @@ import ( "sync/atomic" "time" + "github.com/seaweedfs/seaweedfs/weed/filer" "github.com/seaweedfs/seaweedfs/weed/glog" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" "github.com/seaweedfs/seaweedfs/weed/security" "github.com/seaweedfs/seaweedfs/weed/util" @@ -220,5 +223,10 @@ func (fs *FilerServer) maybeCheckJwtAuthorization(r *http.Request, isWrite bool) func (fs *FilerServer) filerHealthzHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) - w.WriteHeader(http.StatusOK) + if _, err := fs.filer.Store.FindEntry(context.Background(), filer.TopicsDir); err != nil && err != filer_pb.ErrNotFound { + glog.Warningf("filerHealthzHandler FindEntry: %+v", err) + w.WriteHeader(http.StatusServiceUnavailable) + } else { + w.WriteHeader(http.StatusOK) + } } From be166b434f002dba684e8e3630a1e87fdb6a96db Mon Sep 17 00:00:00 2001 From: XIAOYQ Date: Thu, 18 Jan 2024 22:13:46 +0800 Subject: [PATCH 5/8] fix: skip s3 .uploads --- weed/command/filer_sync.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weed/command/filer_sync.go b/weed/command/filer_sync.go index 20464fa50..d84c6325c 100644 --- a/weed/command/filer_sync.go +++ b/weed/command/filer_sync.go @@ -11,6 +11,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/replication/sink" "github.com/seaweedfs/seaweedfs/weed/replication/sink/filersink" "github.com/seaweedfs/seaweedfs/weed/replication/source" + "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants" "github.com/seaweedfs/seaweedfs/weed/security" statsCollect "github.com/seaweedfs/seaweedfs/weed/stats" "github.com/seaweedfs/seaweedfs/weed/util" @@ -393,7 +394,9 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str if debug { glog.V(0).Infof("received %v", resp) } - + if strings.Contains(resp.Directory, "/"+s3_constants.MultipartUploadsFolder+"/") { + return nil + } if !strings.HasPrefix(resp.Directory, sourcePath) { return nil } From 3002087541f2d4447cbccd67c48554b7b86772b1 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 18 Jan 2024 08:58:53 -0800 Subject: [PATCH 6/8] http assign logic should be the same as grpc assign similar logic as bebbc9fe444cd1e8eafe59cc1dd5129d61cad7a4 --- weed/server/master_server_handlers.go | 61 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/weed/server/master_server_handlers.go b/weed/server/master_server_handlers.go index 6ade9402f..ccfb2e0c7 100644 --- a/weed/server/master_server_handlers.go +++ b/weed/server/master_server_handlers.go @@ -6,6 +6,7 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/seaweedfs/seaweedfs/weed/operation" "github.com/seaweedfs/seaweedfs/weed/security" @@ -119,34 +120,52 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request) vl := ms.Topo.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.DiskType) - 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 - glog.V(0).Infof("dirAssign volume growth %v from %v", option.String(), r.RemoteAddr) - if ms.Topo.AvailableSpaceFor(option) <= 0 { - writeJsonQuiet(w, r, http.StatusNotFound, operation.AssignResult{Error: "No free volumes left for " + option.String()}) - return - } + var ( + lastErr error + maxTimeout = time.Second * 10 + startTime = time.Now() + ) - errCh := make(chan error, 1) - vl.AddGrowRequest() - ms.vgCh <- &topology.VolumeGrowRequest{ - Option: option, - Count: writableVolumeCount, - ErrCh: errCh, + 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 + glog.V(0).Infof("dirAssign volume growth %v from %v", option.String(), r.RemoteAddr) + if ms.Topo.AvailableSpaceFor(option) <= 0 { + writeJsonQuiet(w, r, http.StatusNotFound, operation.AssignResult{Error: "No free volumes left for " + option.String()}) + return + } + + errCh := make(chan error, 1) + vl.AddGrowRequest() + ms.vgCh <- &topology.VolumeGrowRequest{ + Option: option, + Count: writableVolumeCount, + ErrCh: errCh, + } + if err := <-errCh; err != nil { + writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("cannot grow volume group! %v", err)) + return + } } - if err := <-errCh; err != nil { - writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("cannot grow volume group! %v", err)) + 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 err == nil { - 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}) + 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"}) } } From 15b66a6633149a2e99ef5d53cd788bdfd143e8b7 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 18 Jan 2024 09:13:14 -0800 Subject: [PATCH 7/8] refactor --- weed/command/filer_remote_sync_dir.go | 9 ++++++--- weed/command/filer_sync.go | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/weed/command/filer_remote_sync_dir.go b/weed/command/filer_remote_sync_dir.go index 00f6d7493..dd3e94be6 100644 --- a/weed/command/filer_remote_sync_dir.go +++ b/weed/command/filer_remote_sync_dir.go @@ -278,7 +278,10 @@ func updateLocalEntry(filerClient filer_pb.FilerClient, dir string, entry *filer } func isMultipartUploadFile(dir string, name string) bool { - return strings.HasPrefix(dir, "/buckets/") && - strings.Contains(dir, "/"+s3_constants.MultipartUploadsFolder+"/") && - strings.HasSuffix(name, ".part") + return isMultipartUploadDir(dir) && strings.HasSuffix(name, ".part") +} + +func isMultipartUploadDir(dir string) bool { + return strings.HasPrefix(dir, "/buckets/") && + strings.Contains(dir, "/"+s3_constants.MultipartUploadsFolder+"/") } diff --git a/weed/command/filer_sync.go b/weed/command/filer_sync.go index d84c6325c..dc954e805 100644 --- a/weed/command/filer_sync.go +++ b/weed/command/filer_sync.go @@ -394,9 +394,11 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str if debug { glog.V(0).Infof("received %v", resp) } - if strings.Contains(resp.Directory, "/"+s3_constants.MultipartUploadsFolder+"/") { + + if isMultipartUploadDir(resp.Directory) { return nil } + if !strings.HasPrefix(resp.Directory, sourcePath) { return nil } From 83e4b0251710b23121ed44b0f8741f150231a68a Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 18 Jan 2024 09:16:20 -0800 Subject: [PATCH 8/8] fix --- weed/command/filer_sync.go | 1 - 1 file changed, 1 deletion(-) diff --git a/weed/command/filer_sync.go b/weed/command/filer_sync.go index dc954e805..292fb0956 100644 --- a/weed/command/filer_sync.go +++ b/weed/command/filer_sync.go @@ -11,7 +11,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/replication/sink" "github.com/seaweedfs/seaweedfs/weed/replication/sink/filersink" "github.com/seaweedfs/seaweedfs/weed/replication/source" - "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants" "github.com/seaweedfs/seaweedfs/weed/security" statsCollect "github.com/seaweedfs/seaweedfs/weed/stats" "github.com/seaweedfs/seaweedfs/weed/util"