use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class LockResolverTest method checkTTLNotExpired.
void checkTTLNotExpired(String key) {
try {
RegionStoreClient client = getRegionStoreClient(key);
BackOffer backOffer = ConcreteBackOffer.newCustomBackOff(CHECK_TTL_BACKOFF);
// In SI mode, a lock <key, value2> is read. Try resolve it, but failed, cause TTL not
// expires.
client.get(backOffer, ByteString.copyFromUtf8(key), session.getTimestamp().getVersion());
fail();
} catch (GrpcException e) {
assertEquals(e.getMessage(), "retry is exhausted.");
}
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class TTLManager method doKeepAlive.
private void doKeepAlive() {
BackOffer bo = ConcreteBackOffer.newCustomBackOff(MANAGED_LOCK_TTL);
long uptime = calculateUptime(kvClient, startTS);
long ttl = uptime + MANAGED_LOCK_TTL;
LOG.info("doKeepAlive key={} uptime={} ttl={}", LogDesensitization.hide(KeyUtils.formatBytes(primaryLock)), uptime, ttl);
try {
sendTxnHeartBeat(bo, ttl);
LOG.info("doKeepAlive success");
} catch (Exception e) {
LOG.warn("doKeepAlive error", e);
}
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class StoreVersion method minTiKVVersion.
public static boolean minTiKVVersion(String version, PDClient pdClient) {
StoreVersion storeVersion = new StoreVersion(version);
BackOffer bo = ConcreteBackOffer.newCustomBackOff(BackOffer.PD_INFO_BACKOFF);
List<Metapb.Store> storeList = pdClient.getAllStores(bo).stream().filter(store -> !isTiFlash(store) && (store.getState() == Metapb.StoreState.Up || store.getState() == Metapb.StoreState.Offline)).collect(Collectors.toList());
for (Metapb.Store store : storeList) {
if (storeVersion.greatThan(new StoreVersion(store.getVersion()))) {
return false;
}
}
return true;
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class TiSession method splitRegion.
private List<TiRegion> splitRegion(List<ByteString> splitKeys, BackOffer backOffer) {
List<TiRegion> regions = new ArrayList<>();
Map<TiRegion, List<ByteString>> groupKeys = groupKeysByRegion(regionManager, splitKeys, backOffer);
for (Map.Entry<TiRegion, List<ByteString>> entry : groupKeys.entrySet()) {
Pair<TiRegion, Metapb.Store> pair = getRegionManager().getRegionStorePairByKey(entry.getKey().getStartKey());
TiRegion region = pair.first;
Metapb.Store store = pair.second;
List<ByteString> splits = entry.getValue().stream().filter(k -> !k.equals(region.getStartKey()) && !k.equals(region.getEndKey())).collect(Collectors.toList());
if (splits.isEmpty()) {
logger.warn("split key equal to region start key or end key. Region splitting is not needed.");
} else {
logger.info("start to split region id={}, split size={}", region.getId(), splits.size());
List<TiRegion> newRegions;
try {
newRegions = getRegionStoreClientBuilder().build(region, store).splitRegion(splits);
} catch (final TiKVException e) {
// retry
logger.warn("ReSplitting ranges for splitRegion", e);
clientBuilder.getRegionManager().invalidateRegion(region);
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
newRegions = splitRegion(splits, backOffer);
}
logger.info("region id={}, new region size={}", region.getId(), newRegions.size());
regions.addAll(newRegions);
}
}
logger.info("splitRegion: return region size={}", regions.size());
return regions;
}
use of com.pingcap.tikv.util.BackOffer in project tispark by pingcap.
the class TwoPhaseCommitter method doPrewriteSecondaryKeys.
private void doPrewriteSecondaryKeys(ByteString primaryKey, Iterator<Pair<ByteString, ByteString>> pairs, int maxBackOfferMS) throws TiBatchWriteException {
try {
int taskBufferSize = writeThreadPerTask * 2;
int totalSize = 0, cnt = 0;
Pair<ByteString, ByteString> pair;
ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<>(executorService);
while (pairs.hasNext()) {
List<ByteString> keyBytes = new ArrayList<>(writeBufferSize);
List<ByteString> valueBytes = new ArrayList<>(writeBufferSize);
while (keyBytes.size() < writeBufferSize && pairs.hasNext()) {
pair = pairs.next();
keyBytes.add(pair.first);
valueBytes.add(pair.second);
}
int curSize = keyBytes.size();
cnt++;
if (cnt > taskBufferSize) {
// consume one task if reaches task limit
completionService.take().get();
}
BackOffer backOffer = ConcreteBackOffer.newCustomBackOff(maxBackOfferMS);
completionService.submit(() -> {
doPrewriteSecondaryKeysInBatchesWithRetry(backOffer, primaryKey, keyBytes, valueBytes, curSize, 0);
return null;
});
totalSize = totalSize + keyBytes.size();
}
for (int i = 0; i < Math.min(taskBufferSize, cnt); i++) {
completionService.take().get();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TiBatchWriteException("Current thread interrupted.", e);
} catch (ExecutionException e) {
throw new TiBatchWriteException("Execution exception met.", e);
}
}
Aggregations