Unverified Commit aaa42620 authored by Zhou Kunqin's avatar Zhou Kunqin Committed by GitHub
Browse files

store: fix possible index out of range in (*RegionStore).kvPeer() (#22319)

parent c2c767a9
Showing with 2 additions and 1 deletion
+2 -1
......@@ -174,7 +174,7 @@ func (r *RegionStore) kvPeer(seed uint32) AccessIndex {
if len(candidates) == 0 {
return r.workTiKVIdx
}
return candidates[int32(seed)%int32(len(candidates))]
return candidates[seed%uint32(len(candidates))]
}
// init initializes region after constructed.
......
......@@ -128,6 +128,7 @@ func (s *testRegionCacheSuite) TestSimple(c *C) {
c.Assert(r.GetID(), Equals, s.region1)
c.Assert(s.getAddr(c, []byte("a"), kv.ReplicaReadLeader, 0), Equals, s.storeAddr(s.store1))
c.Assert(s.getAddr(c, []byte("a"), kv.ReplicaReadFollower, seed), Equals, s.storeAddr(s.store2))
c.Assert(s.getAddr(c, []byte("a"), kv.ReplicaReadMixed, 1<<31+1), Equals, s.storeAddr(s.store2))
s.checkCache(c, 1)
c.Assert(r.GetMeta(), DeepEquals, r.meta)
c.Assert(r.GetLeaderPeerID(), Equals, r.meta.Peers[r.getStore().workTiKVIdx].Id)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment