Skip to content

Commit

Permalink
[fix][dingo-sdk] Fix regionId not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
wt0530 authored and ketor committed Sep 5, 2024
1 parent 558dce3 commit d251f3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RegionChannelProvider implements ChannelProvider {
private Location location;
private Channel channel;
private RegionEpoch regionEpoch;
private boolean status = true;

public RegionChannelProvider(CoordinatorService coordinatorService, long regionId) {
this.coordinatorService = coordinatorService;
Expand Down Expand Up @@ -64,6 +65,13 @@ public void before(Message.Request message) {
}
}

public boolean isStatus() {
if (!status) {
throw new DingoClientException.InvalidRouteTableException("region id not found");
}
return true;
}

public boolean isIn(byte[] key) {
if (range == null) {
throw new RuntimeException("Not refresh!");
Expand All @@ -86,7 +94,7 @@ private void refresh(long trace) {
channel = ChannelManager.getChannel(location);
regionEpoch = $.getRegionEpoch();
range = $.getRange();
});
}).ifAbsent(() -> status = false);
}

private synchronized void refreshIdKey(long trace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ public static RegionChannelProvider regionChannelProvider(
if (region != null) {
Range range = Optional.mapOrNull(region, ScanRegionInfo::getRange);
if (range != null && compare(key, range.getStartKey()) >= 0 && compare(key, range.getEndKey()) < 0) {
RegionChannelProvider regionProvider = regionCache.get(locations).get(region.getRegionId());
if (regionProvider.isIn(key)) {
return regionProvider;
try {
RegionChannelProvider regionProvider = regionCache.get(locations).get(region.getRegionId());
if (regionProvider.isStatus() && regionProvider.isIn(key)) {
return regionProvider;
}
} catch (DingoClientException.InvalidRouteTableException | UncheckedExecutionException ignore) {
}
}
}
Expand Down

0 comments on commit d251f3e

Please sign in to comment.