-
Notifications
You must be signed in to change notification settings - Fork 727
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: try to replace the down replicas instead of removing directly #1222
Changes from 5 commits
8abce6a
2fad2b0
f92835a
44486c8
7381274
b7d7d01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// // http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cases | ||
|
||
import ( | ||
"github.com/pingcap/kvproto/pkg/metapb" | ||
"github.com/pingcap/pd/pkg/faketikv/simutil" | ||
"github.com/pingcap/pd/server/core" | ||
) | ||
|
||
func newMakeupDownReplicas() *Conf { | ||
var conf Conf | ||
var id idAllocator | ||
|
||
for i := 1; i <= 4; i++ { | ||
conf.Stores = append(conf.Stores, &Store{ | ||
ID: id.nextID(), | ||
Status: metapb.StoreState_Up, | ||
Capacity: 1 * TB, | ||
Available: 900 * GB, | ||
Version: "2.1.0", | ||
}) | ||
} | ||
|
||
for i := 0; i < 400; i++ { | ||
peers := []*metapb.Peer{ | ||
{Id: id.nextID(), StoreId: uint64(i)%4 + 1}, | ||
{Id: id.nextID(), StoreId: uint64(i+1)%4 + 1}, | ||
{Id: id.nextID(), StoreId: uint64(i+2)%4 + 1}, | ||
} | ||
conf.Regions = append(conf.Regions, Region{ | ||
ID: id.nextID(), | ||
Peers: peers, | ||
Leader: peers[0], | ||
Size: 96 * MB, | ||
Keys: 960000, | ||
}) | ||
} | ||
conf.MaxID = id.maxID | ||
|
||
numNodes := 4 | ||
down := false | ||
e := &DeleteNodesInner{} | ||
e.Step = func(tick int64) uint64 { | ||
if numNodes > 3 && tick%100 == 0 { | ||
numNodes-- | ||
return uint64(1) | ||
} | ||
if tick == 300 { | ||
down = true | ||
} | ||
return 0 | ||
} | ||
conf.Events = []EventInner{e} | ||
|
||
conf.Checker = func(regions *core.RegionsInfo) bool { | ||
sum := 0 | ||
regionCounts := make([]int, 0, 3) | ||
for i := 1; i <= 4; i++ { | ||
regionCount := regions.GetStoreRegionCount(uint64(i)) | ||
if i != 1 { | ||
regionCounts = append(regionCounts, regionCount) | ||
} | ||
sum += regionCount | ||
} | ||
simutil.Logger.Infof("region counts: %v", regionCounts) | ||
|
||
if down && sum < 1200 { | ||
// only need to print once | ||
down = false | ||
simutil.Logger.Error("making up replicas don't start immediately") | ||
return false | ||
} | ||
|
||
for _, regionCount := range regionCounts { | ||
if regionCount != 400 { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
return &conf | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
package schedule | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingcap/kvproto/pkg/metapb" | ||
"github.com/pingcap/pd/server/core" | ||
"github.com/pingcap/pd/server/namespace" | ||
|
@@ -169,7 +171,8 @@ func (r *ReplicaChecker) checkDownPeer(region *core.RegionInfo) *Operator { | |
if stats.GetDownSeconds() < uint64(r.cluster.GetMaxStoreDownTime().Seconds()) { | ||
continue | ||
} | ||
return CreateRemovePeerOperator("removeDownReplica", r.cluster, OpReplica, region, peer.GetStoreId()) | ||
|
||
return r.fixPeer(region, peer, "Down") | ||
} | ||
return nil | ||
} | ||
|
@@ -194,29 +197,7 @@ func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator { | |
continue | ||
} | ||
|
||
// Check the number of replicas first. | ||
if len(region.GetPeers()) > r.cluster.GetMaxReplicas() { | ||
return CreateRemovePeerOperator("removeExtraOfflineReplica", r.cluster, OpReplica, region, peer.GetStoreId()) | ||
} | ||
|
||
// Consider we have 3 peers (A, B, C), we set the store that contains C to | ||
// offline while C is pending. If we generate an operator that adds a replica | ||
// D then removes C, D will not be successfully added util C is normal again. | ||
// So it's better to remove C directly. | ||
if region.GetPendingPeer(peer.GetId()) != nil { | ||
return CreateRemovePeerOperator("removePendingOfflineReplica", r.cluster, OpReplica, region, peer.GetStoreId()) | ||
} | ||
|
||
storeID, _ := r.SelectBestReplacementStore(region, peer, NewStorageThresholdFilter()) | ||
if storeID == 0 { | ||
log.Debugf("[region %d] no best store to add replica", region.GetID()) | ||
return nil | ||
} | ||
newPeer, err := r.cluster.AllocPeer(storeID) | ||
if err != nil { | ||
return nil | ||
} | ||
return CreateMovePeerOperator("replaceOfflineReplica", r.cluster, region, OpReplica, peer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId()) | ||
return r.fixPeer(region, peer, "Offline") | ||
} | ||
|
||
return nil | ||
|
@@ -250,3 +231,33 @@ func (r *ReplicaChecker) checkBestReplacement(region *core.RegionInfo) *Operator | |
checkerCounter.WithLabelValues("replica_checker", "new_operator").Inc() | ||
return CreateMovePeerOperator("moveToBetterLocation", r.cluster, region, OpReplica, oldPeer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId()) | ||
} | ||
|
||
func (r *ReplicaChecker) fixPeer(region *core.RegionInfo, peer *metapb.Peer, status string) *Operator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does fixPeer mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It means this peer needs to be removed in order to be made up in another store or just simply be replaced. The name before addressing the comment is |
||
removeExtra := fmt.Sprintf("removeExtra%sReplica", status) | ||
// Check the number of replicas first. | ||
if len(region.GetPeers()) > r.cluster.GetMaxReplicas() { | ||
return CreateRemovePeerOperator(removeExtra, r.cluster, OpReplica, region, peer.GetStoreId()) | ||
} | ||
|
||
removePending := fmt.Sprintf("removePending%sReplica", status) | ||
// Consider we have 3 peers (A, B, C), we set the store that contains C to | ||
// offline/down while C is pending. If we generate an operator that adds a replica | ||
// D then removes C, D will not be successfully added util C is normal again. | ||
// So it's better to remove C directly. | ||
if region.GetPendingPeer(peer.GetId()) != nil { | ||
return CreateRemovePeerOperator(removePending, r.cluster, OpReplica, region, peer.GetStoreId()) | ||
} | ||
|
||
storeID, _ := r.SelectBestReplacementStore(region, peer, NewStorageThresholdFilter()) | ||
if storeID == 0 { | ||
log.Debugf("[region %d] no best store to add replica", region.GetID()) | ||
return nil | ||
} | ||
newPeer, err := r.cluster.AllocPeer(storeID) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
replace := fmt.Sprintf("replace%sReplica", status) | ||
return CreateMovePeerOperator(replace, r.cluster, region, OpReplica, peer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we abstract a statistic to evaluate different strategies instead of just print a log message? For example, we may count the number of regions with insufficient replicas in the scheduling process.