From 28000d3fe814cbe3e8e8bbe98c7181ead5275d3d Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 24 Jul 2020 16:20:03 +0800 Subject: [PATCH] region_cache: invalidate cached region for not leader error (#18577) (#18598) Signed-off-by: ti-srebot Signed-off-by: qupeng --- go.sum | 1 + store/tikv/region_request.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index b1014f7c5d615..bd8734732e2f6 100644 --- a/go.sum +++ b/go.sum @@ -186,6 +186,7 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFd github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7 h1:FUL3b97ZY2EPqg2NbXKuMHs5pXJB9hjj1fDHnF2vl28= github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 h1:tB9NOR21++IjLyVx3/PCPhWMwqGNCMQEH96A6dMZ/gc= github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.18.10+incompatible h1:cy84jW6EVRPa5g9HAHrlbxMSIjBhDSX0OFYyMYminYs= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/store/tikv/region_request.go b/store/tikv/region_request.go index d31400ebdc571..258420f24ec91 100644 --- a/store/tikv/region_request.go +++ b/store/tikv/region_request.go @@ -283,9 +283,13 @@ func (s *RegionRequestSender) onRegionError(bo *Backoffer, ctx *RPCContext, regi if notLeader.GetLeader() != nil { boType = BoUpdateLeader } else { + // The peer doesn't know who is the current leader. Generally it's because + // the Raft group is in an election, but it's possible that the peer is + // isolated and removed from the Raft group. So it's necessary to reload + // the region from PD. + s.regionCache.InvalidateCachedRegion(ctx.Region) boType = BoRegionMiss } - if err = bo.Backoff(boType, errors.Errorf("not leader: %v, ctx: %v", notLeader, ctx)); err != nil { return false, errors.Trace(err) }