From 4a02189ba0460edcc8b4e7a128684fb2778d0fec Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Thu, 28 Mar 2024 07:18:40 +0800 Subject: [PATCH] feat: add env to choose which node to start decom (#19310) add a temporary env _MINIO_DECOM_ENDPOINT to choose the node to start decom from, in situations when first node first pool is not available. --- cmd/admin-handlers-pools.go | 52 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/admin-handlers-pools.go b/cmd/admin-handlers-pools.go index e862292ad..26f48ee7f 100644 --- a/cmd/admin-handlers-pools.go +++ b/cmd/admin-handlers-pools.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2021 MinIO, Inc. +// Copyright (c) 2015-2024 MinIO, Inc. // // This file is part of MinIO Object Storage stack // @@ -18,6 +18,7 @@ package cmd import ( + "context" "encoding/json" "errors" "fmt" @@ -27,6 +28,7 @@ import ( "github.com/minio/minio/internal/logger" "github.com/minio/mux" + "github.com/minio/pkg/v2/env" "github.com/minio/pkg/v2/policy" ) @@ -106,21 +108,12 @@ func (a adminAPIHandlers) StartDecommission(w http.ResponseWriter, r *http.Reque poolIndices = append(poolIndices, idx) } - if len(poolIndices) > 0 && !globalEndpoints[poolIndices[0]].Endpoints[0].IsLocal { - ep := globalEndpoints[poolIndices[0]].Endpoints[0] - for nodeIdx, proxyEp := range globalProxyEndpoints { - if proxyEp.Endpoint.Host == ep.Host { - if proxyRequestByNodeIndex(ctx, w, r, nodeIdx) { - return - } - } + if len(poolIndices) == 0 || !proxyDecommissionRequest(ctx, globalEndpoints[poolIndices[0]].Endpoints[0], w, r) { + if err := z.Decommission(r.Context(), poolIndices...); err != nil { + writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) + return } } - - if err := z.Decommission(r.Context(), poolIndices...); err != nil { - writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) - return - } } func (a adminAPIHandlers) CancelDecommission(w http.ResponseWriter, r *http.Request) { @@ -162,20 +155,12 @@ func (a adminAPIHandlers) CancelDecommission(w http.ResponseWriter, r *http.Requ return } - if ep := globalEndpoints[idx].Endpoints[0]; !ep.IsLocal { - for nodeIdx, proxyEp := range globalProxyEndpoints { - if proxyEp.Endpoint.Host == ep.Host { - if proxyRequestByNodeIndex(ctx, w, r, nodeIdx) { - return - } - } + if !proxyDecommissionRequest(ctx, globalEndpoints[idx].Endpoints[0], w, r) { + if err := pools.DecommissionCancel(ctx, idx); err != nil { + writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) + return } } - - if err := pools.DecommissionCancel(ctx, idx); err != nil { - writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) - return - } } func (a adminAPIHandlers) StatusPool(w http.ResponseWriter, r *http.Request) { @@ -391,3 +376,18 @@ func (a adminAPIHandlers) RebalanceStop(w http.ResponseWriter, r *http.Request) writeSuccessResponseHeadersOnly(w) logger.LogIf(ctx, pools.saveRebalanceStats(GlobalContext, 0, rebalSaveStoppedAt)) } + +func proxyDecommissionRequest(ctx context.Context, defaultEndPoint Endpoint, w http.ResponseWriter, r *http.Request) (proxy bool) { + host := env.Get("_MINIO_DECOM_ENDPOINT_HOST", defaultEndPoint.Host) + if host == "" { + return + } + for nodeIdx, proxyEp := range globalProxyEndpoints { + if proxyEp.Endpoint.Host == host && !proxyEp.IsLocal { + if proxyRequestByNodeIndex(ctx, w, r, nodeIdx) { + return true + } + } + } + return +}