Skip to content

Commit

Permalink
cluster/spec: report store state as up if any of the stores is not to…
Browse files Browse the repository at this point in the history
…mbstone
  • Loading branch information
AstroProfundis committed Dec 24, 2020
1 parent 081877a commit 26daa42
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/cluster/spec/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
Expand Down Expand Up @@ -70,15 +71,31 @@ func checkStoreStatus(storeAddr string, tlsCfg *tls.Config, pdList ...string) st
return "Down"
}

// only get status of the latest store, it is the store with lagest ID number
// only get status of the latest store, it is the store with largest ID number
// older stores might be legacy ones that already offlined
var latestStore *pdserverapi.StoreInfo

for _, store := range stores.Stores {
if storeAddr == store.Store.Address {
if latestStore == nil {
latestStore = store
continue
}

// If the PD leader has been switched multiple times, the store IDs
// may be not monitonically assigned. To workaround this, we iterate
// over the whole store list to see if any of the store's state is
// not marked as "tombstone", then use that as the result.
// See: https://github.com/tikv/pd/issues/3303
//
// It's logically not necessary to find the store with largest ID
// number anymore in this process, but we're keeping the behavior
// as the reasonable approach would still be using the state from
// latest store, and this is only a workaround.
if store.Store.State != metapb.StoreState_Tombstone {
return store.Store.StateName
}

if store.Store.Id > latestStore.Store.Id {
latestStore = store
}
Expand Down

0 comments on commit 26daa42

Please sign in to comment.