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

[fix #623] region may be missed #624

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ TiRegion loadCurrentRegionToCache() throws GrpcException {
TiRegion region;
try (RegionStoreClient client = builder.build(startKey)) {
client.setTimeout(conf.getScanTimeout());
region = client.getRegion();
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();
Copy link
Member

Choose a reason for hiding this comment

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

We might add some comments about this update since the scan has some implicit side effects. In addition, this issue might occur in

TiRegion loadCurrentRegionToCache() throws GrpcException {
, the raw scan of client-java. We might add some mock tests for this interface, at least a TODO should be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have add comment and fix it in RawScanIterator. I think test it is not easy, so a TODO is added.

return region;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ TiRegion loadCurrentRegionToCache() throws GrpcException {
} 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract class ScanIterator implements Iterator<Kvrpcpb.KvPair> {
*
* @return TiRegion of current data loaded to cache
* @throws GrpcException if scan still fails after backoff
* <p>TODO : Add test to check it correctness
*/
abstract TiRegion loadCurrentRegionToCache() throws GrpcException;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/tikv/common/region/RegionStoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,9 @@ public List<KvPair> rawScan(BackOffer backOffer, ByteString key, int limit, bool
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,
iosmanthus marked this conversation as resolved.
Show resolved Hide resolved
// This region need to get newest info from cache.
region = regionManager.getRegionByKey(key, backOffer);
return rawScanHelper(resp);
} finally {
requestTimer.observeDuration();
Expand Down