diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/RegionChannelProvider.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/RegionChannelProvider.java index 25022b434..cdfd6d7b2 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/RegionChannelProvider.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/RegionChannelProvider.java @@ -1,5 +1,6 @@ package io.dingodb.sdk.service; +import io.dingodb.sdk.common.DingoClientException; import io.dingodb.sdk.common.codec.CodecUtils; import io.dingodb.sdk.common.utils.ByteArrayUtils; import io.dingodb.sdk.common.utils.Optional; @@ -32,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; @@ -64,6 +66,9 @@ public void before(Message.Request message) { } public boolean isIn(byte[] key) { + if (!status) { + throw new DingoClientException.InvalidRouteTableException("region id not found"); + } if (range == null) { throw new RuntimeException("Not refresh!"); } @@ -85,7 +90,7 @@ private void refresh(long trace) { channel = ChannelManager.getChannel(location); regionEpoch = $.getRegionEpoch(); range = $.getRange(); - }); + }).ifAbsent(() -> status = false); } private synchronized void refreshIdKey(long trace) { diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java index 73286ee79..d77594671 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java @@ -3,6 +3,8 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; +import io.dingodb.sdk.common.DingoClientException; import io.dingodb.sdk.common.codec.CodecUtils; import io.dingodb.sdk.common.utils.ByteArrayUtils; import io.dingodb.sdk.common.utils.Optional; @@ -240,9 +242,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.isIn(key)) { + return regionProvider; + } + } catch (DingoClientException.InvalidRouteTableException | UncheckedExecutionException ignore) { } } }