forked from tikv/pd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an automated cherry-pick of tikv#4875
close tikv#4769 Signed-off-by: ti-chi-bot <[email protected]>
- Loading branch information
1 parent
35a202d
commit 4e61080
Showing
10 changed files
with
856 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2022 TiKV Project Authors. | ||
// | ||
// 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, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cluster | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/tikv/pd/pkg/syncutil" | ||
"github.com/tikv/pd/server/core" | ||
) | ||
|
||
type prepareChecker struct { | ||
syncutil.RWMutex | ||
reactiveRegions map[uint64]int | ||
start time.Time | ||
sum int | ||
prepared bool | ||
} | ||
|
||
func newPrepareChecker() *prepareChecker { | ||
return &prepareChecker{ | ||
start: time.Now(), | ||
reactiveRegions: make(map[uint64]int), | ||
} | ||
} | ||
|
||
// Before starting up the scheduler, we need to take the proportion of the regions on each store into consideration. | ||
func (checker *prepareChecker) check(c *core.BasicCluster) bool { | ||
checker.RLock() | ||
defer checker.RUnlock() | ||
if checker.prepared { | ||
return true | ||
} | ||
if time.Since(checker.start) > collectTimeout { | ||
checker.prepared = true | ||
return true | ||
} | ||
// The number of active regions should be more than total region of all stores * collectFactor | ||
if float64(c.GetRegionCount())*collectFactor > float64(checker.sum) { | ||
return false | ||
} | ||
for _, store := range c.GetStores() { | ||
if !store.IsPreparing() && !store.IsServing() { | ||
continue | ||
} | ||
storeID := store.GetID() | ||
// For each store, the number of active regions should be more than total region of the store * collectFactor | ||
if float64(c.GetStoreRegionCount(storeID))*collectFactor > float64(checker.reactiveRegions[storeID]) { | ||
return false | ||
} | ||
} | ||
checker.prepared = true | ||
return true | ||
} | ||
|
||
func (checker *prepareChecker) collect(region *core.RegionInfo) { | ||
checker.Lock() | ||
defer checker.Unlock() | ||
for _, p := range region.GetPeers() { | ||
checker.reactiveRegions[p.GetStoreId()]++ | ||
} | ||
checker.sum++ | ||
} | ||
|
||
func (checker *prepareChecker) isPrepared() bool { | ||
checker.RLock() | ||
defer checker.RUnlock() | ||
return checker.prepared | ||
} |
Oops, something went wrong.