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 Aug 29, 2024
1 parent 956c4e3 commit 2d5bed9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!");
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -244,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.isIn(key)) {
return regionProvider;
}
} catch (DingoClientException.InvalidRouteTableException | UncheckedExecutionException ignore) {
}
}
}
Expand Down

0 comments on commit 2d5bed9

Please sign in to comment.