Skip to content

Commit

Permalink
cluster: remove tombstone nodes on pd when prune (#2044)
Browse files Browse the repository at this point in the history
* cluster: remove tombstone nodes on pd when prune

* lint fix

---------

Co-authored-by: Qiμ$hiЯuí <[email protected]>
Co-authored-by: kaaaaaaang <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 423dd0d commit 8f7230f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/cluster/api/pdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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"
pdServicePrimaryURI = "pd/api/v2/ms/primary"
tsoHealthPrefix = "tso/api/v1/health"
Expand Down Expand Up @@ -867,6 +868,16 @@ 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) {
_, _, 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) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/manager/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -193,6 +195,14 @@ func (m *Manager) DestroyTombstone(
ParallelStep("+ Refresh instance configs", gOpt.Force, regenConfigTasks...).
ParallelStep("+ Reload prometheus and grafana", gOpt.Force,
buildReloadPromAndGrafanaTasks(topo, 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 {
Expand Down

0 comments on commit 8f7230f

Please sign in to comment.