Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix a bug that may set not empty store to tombstone state. #758

Merged
merged 2 commits into from Sep 18, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion server/cluster.go
Expand Up @@ -539,7 +539,14 @@ func (c *RaftCluster) checkStores() {
if store.GetState() != metapb.StoreState_Offline {
continue
}
if cluster.getStoreRegionCount(store.GetId()) == 0 {
if cluster.getStoreRegionCount(store.GetId()) > 0 {
continue
}
// If pd-server is started recently, or becomes leader recently, the check may
// happen before any heartbeat from tikv. So we need to check region metas to
// verify no region's peer is on the store.
regions := cluster.getMetaRegions()
if c.verifyStoreIsEmpty(regions, store.GetId()) {
err := c.BuryStore(store.GetId(), false)
if err != nil {
log.Errorf("bury store %v failed: %v", store, err)
Expand All @@ -550,6 +557,17 @@ func (c *RaftCluster) checkStores() {
}
}

func (c *RaftCluster) verifyStoreIsEmpty(regions []*metapb.Region, storeID uint64) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/verifyStoreIsEmpty/storeIsEmpty/

for _, region := range regions {
for _, p := range region.GetPeers() {
if p.GetStoreId() == storeID {
return false
}
}
}
return true
}

func (c *RaftCluster) collectMetrics() {
cluster := c.cachedCluster

Expand Down