From e98e5f24787367bfb6ed547ebd74787524d229a5 Mon Sep 17 00:00:00 2001 From: nexustar Date: Wed, 21 Sep 2022 15:19:40 +0800 Subject: [PATCH 1/2] cluster: remove tombstone nodes on pd when prune --- pkg/cluster/api/pdapi.go | 10 ++++++++++ pkg/cluster/manager/destroy.go | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/cluster/api/pdapi.go b/pkg/cluster/api/pdapi.go index d8c1f2fdd7..8cca609392 100644 --- a/pkg/cluster/api/pdapi.go +++ b/pkg/cluster/api/pdapi.go @@ -137,6 +137,7 @@ var ( pdStoreURI = "pd/api/v1/store" pdStoresURI = "pd/api/v1/stores" pdStoresLimitURI = "pd/api/v1/stores/limit" + pdRemoveTombstone = "pd/api/v1/stores/remove-tombstone" pdRegionsCheckURI = "pd/api/v1/regions/check" ) @@ -728,6 +729,15 @@ func (pc *PDClient) DelStore(host string, retryOpt *utils.RetryOption) error { return nil } +func (pc *PDClient) RemoveTombstone() error { + endpoints := pc.getEndpoints(pdRemoveTombstone) + _, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) { + _, _, err := pc.httpClient.Delete(pc.ctx, endpoint, nil) + return nil, err + }) + return err +} + func (pc *PDClient) updateConfig(url string, body io.Reader) error { endpoints := pc.getEndpoints(url) _, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) { diff --git a/pkg/cluster/manager/destroy.go b/pkg/cluster/manager/destroy.go index 1d53084322..8e37adc12d 100644 --- a/pkg/cluster/manager/destroy.go +++ b/pkg/cluster/manager/destroy.go @@ -17,10 +17,12 @@ import ( "context" "errors" "fmt" + "time" "github.com/fatih/color" "github.com/joomcode/errorx" perrs "github.com/pingcap/errors" + "github.com/pingcap/tiup/pkg/cluster/api" "github.com/pingcap/tiup/pkg/cluster/clusterutil" "github.com/pingcap/tiup/pkg/cluster/ctxt" operator "github.com/pingcap/tiup/pkg/cluster/operation" @@ -175,6 +177,14 @@ func (m *Manager) DestroyTombstone( ParallelStep("+ Refresh instance configs", gOpt.Force, regenConfigTasks...). ParallelStep("+ Reload prometheus and grafana", gOpt.Force, buildReloadPromAndGrafanaTasks(metadata.GetTopology(), m.logger, gOpt)...). + Func("RemoveTomestoneNodesInPD", func(ctx context.Context) (err error) { + pdEndpoints := make([]string, 0) + for _, pd := range cluster.PDServers { + pdEndpoints = append(pdEndpoints, fmt.Sprintf("%s:%d", pd.Host, pd.ClientPort)) + } + pdAPI := api.NewPDClient(ctx, pdEndpoints, time.Second*time.Duration(gOpt.APITimeout), tlsCfg) + return pdAPI.RemoveTombstone() + }). Build() if err := t.Execute(ctx); err != nil { From 3e70ac25c68b31dc3f1aeef92204ad14694d985f Mon Sep 17 00:00:00 2001 From: nexustar Date: Tue, 25 Jun 2024 15:04:25 +0800 Subject: [PATCH 2/2] lint fix --- pkg/cluster/api/pdapi.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/cluster/api/pdapi.go b/pkg/cluster/api/pdapi.go index fac5c392d9..3ac193a830 100644 --- a/pkg/cluster/api/pdapi.go +++ b/pkg/cluster/api/pdapi.go @@ -868,6 +868,7 @@ func (pc *PDClient) DelStore(host string, retryOpt *utils.RetryOption) error { return nil } +// RemoveTombstone remove tombstone instance func (pc *PDClient) RemoveTombstone() error { endpoints := pc.getEndpoints(pdRemoveTombstone) _, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) {