fix region may miss in rawscan

Signed-off-by: TrafalgarRicardoLu <trafalgarricardolu@gmail.com>
This commit is contained in:
TrafalgarRicardoLu 2022-06-28 16:45:24 +08:00
parent e3559f69bb
commit d2409efd48
3 changed files with 10 additions and 0 deletions

View File

@ -77,6 +77,10 @@ public class ConcreteScanIterator extends ScanIterator {
client.setTimeout(conf.getScanTimeout());
BackOffer backOffer = ConcreteBackOffer.newScannerNextMaxBackOff();
currentCache = client.scan(backOffer, startKey, version);
// If we get region before scan, we will use region from cache which
// may have wrong end key. This may miss some regions that split from old region.
// Client will get the newest region during scan. So we need to
// update region after scan.
region = client.getRegion();
return region;
}

View File

@ -57,6 +57,9 @@ public class RawScanIterator extends ScanIterator {
} else {
try {
currentCache = client.rawScan(backOffer, startKey, limit, keyOnly);
// Client will get the newest region during scan. So we need to
// update region after scan.
region = client.getRegion();
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
continue;

View File

@ -1253,6 +1253,9 @@ public class RegionStoreClient extends AbstractRegionStoreClient {
regionManager, this, resp -> resp.hasRegionError() ? resp.getRegionError() : null);
RawScanResponse resp =
callWithRetry(backOffer, TikvGrpc.getRawScanMethod(), factory, handler);
// RegionErrorHandler may refresh region cache due to outdated region info,
// This region need to get newest ino from cache.
region = regionManager.getRegionByKey(key, backOffer);
return rawScanHelper(resp);
} finally {
requestTimer.observeDuration();