Skip to content
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

store/tikv: drop the unreachable store's regions from cache. #2792

Merged
merged 5 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions store/tikv/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ func (c *RegionCache) OnRequestFail(ctx *RPCContext) {
c.storeMu.Lock()
delete(c.storeMu.stores, storeID)
c.storeMu.Unlock()

c.mu.Lock()
for id, r := range c.mu.regions {
if r.peer.GetStoreId() == storeID {
c.dropRegionFromCache(id)
}
}
c.mu.Unlock()
}

// OnRegionStale removes the old region and inserts new regions into the cache.
Expand Down
22 changes: 22 additions & 0 deletions store/tikv/region_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ func (s *testRegionCacheSuite) TestRequestFail(c *C) {
c.Assert(region.unreachableStores, HasLen, 0)
}

func (s *testRegionCacheSuite) TestRequestFail2(c *C) {
// ['' - 'm' - 'z']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments: key range:

region2 := s.cluster.AllocID()
newPeers := s.cluster.AllocIDs(2)
s.cluster.Split(s.region1, region2, []byte("m"), newPeers, newPeers[0])

// Check the two regions.
loc1, err := s.cache.LocateKey(s.bo, []byte("a"))
c.Assert(err, IsNil)
c.Assert(loc1.Region.id, Equals, s.region1)
loc2, err := s.cache.LocateKey(s.bo, []byte("x"))
c.Assert(err, IsNil)
c.Assert(loc2.Region.id, Equals, region2)

// Request fails on region1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fails/should fail/

ctx, _ := s.cache.GetRPCContext(s.bo, loc1.Region)
s.cache.OnRequestFail(ctx)
// Both region2 and store should be dropped from cache.
c.Assert(s.cache.storeMu.stores, HasLen, 0)
c.Assert(s.cache.getRegionFromCache([]byte("x")), IsNil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard for me to understand this test case==

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It first splits the cluster to 2 regions (region1, region2) while their leaders are on the same store (store1). After request fails on region1, we check if region2 and store1 are removed from cache.

}

func (s *testRegionCacheSuite) TestUpdateStoreAddr(c *C) {
client := &RawKVClient{
clusterID: 0,
Expand Down