-
Notifications
You must be signed in to change notification settings - Fork 720
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
*: add region option for random pick region #1005
Changes from 2 commits
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 |
---|---|---|
|
@@ -279,10 +279,10 @@ func (c *clusterInfo) getRegions() []*core.RegionInfo { | |
return c.Regions.GetRegions() | ||
} | ||
|
||
func (c *clusterInfo) randomRegion() *core.RegionInfo { | ||
func (c *clusterInfo) randomRegion(opts ...core.RegionOption) *core.RegionInfo { | ||
c.RLock() | ||
defer c.RUnlock() | ||
return c.Regions.RandRegion() | ||
return c.Regions.RandRegion(opts...) | ||
} | ||
|
||
func (c *clusterInfo) getMetaRegions() []*metapb.Region { | ||
|
@@ -324,17 +324,17 @@ func (c *clusterInfo) getStoreLeaderCount(storeID uint64) int { | |
} | ||
|
||
// RandLeaderRegion returns a random region that has leader on the store. | ||
func (c *clusterInfo) RandLeaderRegion(storeID uint64) *core.RegionInfo { | ||
func (c *clusterInfo) RandLeaderRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
c.RLock() | ||
defer c.RUnlock() | ||
return c.BasicCluster.RandLeaderRegion(storeID) | ||
return c.BasicCluster.RandLeaderRegion(storeID, ops...) | ||
} | ||
|
||
// RandFollowerRegion returns a random region that has a follower on the store. | ||
func (c *clusterInfo) RandFollowerRegion(storeID uint64) *core.RegionInfo { | ||
func (c *clusterInfo) RandFollowerRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
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. ditto |
||
c.RLock() | ||
defer c.RUnlock() | ||
return c.BasicCluster.RandFollowerRegion(storeID) | ||
return c.BasicCluster.RandFollowerRegion(storeID, ops...) | ||
} | ||
|
||
// GetRegionStores returns all stores that contains the region's peer. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,9 +60,9 @@ func (c *namespaceCluster) checkRegion(region *core.RegionInfo) bool { | |
const randRegionMaxRetry = 10 | ||
|
||
// RandFollowerRegion returns a random region that has a follower on the store. | ||
func (c *namespaceCluster) RandFollowerRegion(storeID uint64) *core.RegionInfo { | ||
func (c *namespaceCluster) RandFollowerRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
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. ditto. |
||
for i := 0; i < randRegionMaxRetry; i++ { | ||
r := c.Cluster.RandFollowerRegion(storeID) | ||
r := c.Cluster.RandFollowerRegion(storeID, ops...) | ||
if r == nil { | ||
return nil | ||
} | ||
|
@@ -74,9 +74,9 @@ func (c *namespaceCluster) RandFollowerRegion(storeID uint64) *core.RegionInfo { | |
} | ||
|
||
// RandLeaderRegion returns a random region that has leader on the store. | ||
func (c *namespaceCluster) RandLeaderRegion(storeID uint64) *core.RegionInfo { | ||
func (c *namespaceCluster) RandLeaderRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
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. ditto |
||
for i := 0; i < randRegionMaxRetry; i++ { | ||
r := c.Cluster.RandLeaderRegion(storeID) | ||
r := c.Cluster.RandLeaderRegion(storeID, ops...) | ||
if r == nil { | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,13 +146,13 @@ func (bc *BasicCluster) UnblockStore(storeID uint64) { | |
} | ||
|
||
// RandFollowerRegion returns a random region that has a follower on the store. | ||
func (bc *BasicCluster) RandFollowerRegion(storeID uint64) *core.RegionInfo { | ||
return bc.Regions.RandFollowerRegion(storeID) | ||
func (bc *BasicCluster) RandFollowerRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
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. ditto |
||
return bc.Regions.RandFollowerRegion(storeID, ops...) | ||
} | ||
|
||
// RandLeaderRegion returns a random region that has leader on the store. | ||
func (bc *BasicCluster) RandLeaderRegion(storeID uint64) *core.RegionInfo { | ||
return bc.Regions.RandLeaderRegion(storeID) | ||
func (bc *BasicCluster) RandLeaderRegion(storeID uint64, ops ...core.RegionOption) *core.RegionInfo { | ||
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. ditto |
||
return bc.Regions.RandLeaderRegion(storeID, ops...) | ||
} | ||
|
||
// IsRegionHot checks if a region is in hot state. | ||
|
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.
s/ops/opts