-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
session: support leader-and-follower for tidb_replica_read #14761
Changes from 1 commit
4d33125
ac1ce45
158fac9
0825f4e
5733d41
5101e14
4f37ea3
ae469c2
150595c
55ddc67
3e82e28
c08bc4c
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 |
---|---|---|
|
@@ -115,6 +115,31 @@ func (r *RegionStore) follower(seed uint32) int32 { | |
return r.workTiKVIdx | ||
} | ||
|
||
// return next leader or follower store's index | ||
func (r *RegionStore) peer(seed uint32) int32 { | ||
l := uint32(len(r.stores)) | ||
if l <= 1 { | ||
return r.workTiKVIdx | ||
} | ||
|
||
candidates := make([]int32, 0, len(r.stores)) | ||
for i := 0; i < len(r.stores); i++ { | ||
if r.stores[i].storeType != kv.TiKV { | ||
continue | ||
} | ||
if r.storeFails[i] != atomic.LoadUint32(&r.stores[i].fail) { | ||
continue | ||
} | ||
candidates = append(candidates, int32(i)) | ||
} | ||
|
||
if len(candidates) == 0 { | ||
return r.workTiKVIdx | ||
} else { | ||
return int32(seed) % int32(len(candidates)) | ||
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.
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. or stores value are 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. Fixed. PTAL. |
||
} | ||
} | ||
|
||
// init initializes region after constructed. | ||
func (r *Region) init(c *RegionCache) { | ||
// region store pull used store from global store map | ||
|
@@ -306,6 +331,8 @@ func (c *RegionCache) GetTiKVRPCContext(bo *Backoffer, id RegionVerID, replicaRe | |
switch replicaRead { | ||
case kv.ReplicaReadFollower: | ||
store, peer, storeIdx = cachedRegion.FollowerStorePeer(regionStore, followerStoreSeed) | ||
case kv.ReplicaReadMixed: | ||
store, peer, storeIdx = cachedRegion.AnyStorePeer(regionStore, followerStoreSeed) | ||
default: | ||
store, peer, storeIdx = cachedRegion.WorkStorePeer(regionStore) | ||
} | ||
|
@@ -1055,6 +1082,11 @@ func (r *Region) FollowerStorePeer(rs *RegionStore, followerStoreSeed uint32) (* | |
return r.getStorePeer(rs, rs.follower(followerStoreSeed)) | ||
} | ||
|
||
// AnyStorePeer returns a leader or follower store with the associated peer. | ||
func (r *Region) AnyStorePeer(rs *RegionStore, followerStoreSeed uint32) (*Store, *metapb.Peer, int) { | ||
return r.getStorePeer(rs, rs.peer(followerStoreSeed)) | ||
} | ||
|
||
// RegionVerID is a unique ID that can identify a Region at a specific version. | ||
type RegionVerID struct { | ||
id uint64 | ||
|
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.
@lysu @hicqu Seems the comment is not correct.