mirror of https://github.com/tikv/client-java.git
Signed-off-by: marsishandsome <marsishandsome@gmail.com>
This commit is contained in:
parent
f3a3abf3ef
commit
599da193df
|
|
@ -94,7 +94,7 @@ public class RegionManager {
|
|||
}
|
||||
|
||||
public TiRegion getRegionByKey(ByteString key) {
|
||||
return getRegionByKey(key, ConcreteBackOffer.newGetBackOff());
|
||||
return getRegionByKey(key, defaultBackOff());
|
||||
}
|
||||
|
||||
public TiRegion getRegionByKey(ByteString key, BackOffer backOffer) {
|
||||
|
|
@ -124,7 +124,7 @@ public class RegionManager {
|
|||
// Consider region A, B. After merge of (A, B) -> A, region ID B does not exist.
|
||||
// This request is unrecoverable.
|
||||
public TiRegion getRegionById(long regionId) {
|
||||
BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
TiRegion region = cache.getRegionById(regionId);
|
||||
if (region == null) {
|
||||
Pair<Metapb.Region, Metapb.Peer> regionAndLeader =
|
||||
|
|
@ -144,7 +144,7 @@ public class RegionManager {
|
|||
}
|
||||
|
||||
public Pair<TiRegion, TiStore> getRegionStorePairByKey(ByteString key, TiStoreType storeType) {
|
||||
return getRegionStorePairByKey(key, storeType, ConcreteBackOffer.newGetBackOff());
|
||||
return getRegionStorePairByKey(key, storeType, defaultBackOff());
|
||||
}
|
||||
|
||||
public Pair<TiRegion, TiStore> getRegionStorePairByKey(
|
||||
|
|
@ -216,7 +216,7 @@ public class RegionManager {
|
|||
}
|
||||
|
||||
public TiStore getStoreById(long id) {
|
||||
return getStoreById(id, ConcreteBackOffer.newGetBackOff());
|
||||
return getStoreById(id, defaultBackOff());
|
||||
}
|
||||
|
||||
public void onRegionStale(TiRegion region) {
|
||||
|
|
@ -264,4 +264,8 @@ public class RegionManager {
|
|||
public void invalidateRegion(TiRegion region) {
|
||||
cache.invalidateRegion(region);
|
||||
}
|
||||
|
||||
private BackOffer defaultBackOff() {
|
||||
return ConcreteBackOffer.newCustomBackOff(conf.getRawKVDefaultBackoffInMS());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1302,19 +1302,39 @@ public class RegionStoreClient extends AbstractRegionStoreClient {
|
|||
return build(key, TiStoreType.TiKV);
|
||||
}
|
||||
|
||||
public synchronized RegionStoreClient build(ByteString key, BackOffer backOffer)
|
||||
throws GrpcException {
|
||||
return build(key, TiStoreType.TiKV, backOffer);
|
||||
}
|
||||
|
||||
public synchronized RegionStoreClient build(ByteString key, TiStoreType storeType)
|
||||
throws GrpcException {
|
||||
Pair<TiRegion, TiStore> pair = regionManager.getRegionStorePairByKey(key, storeType);
|
||||
return build(key, storeType, defaultBackOff());
|
||||
}
|
||||
|
||||
public synchronized RegionStoreClient build(
|
||||
ByteString key, TiStoreType storeType, BackOffer backOffer) throws GrpcException {
|
||||
Pair<TiRegion, TiStore> pair =
|
||||
regionManager.getRegionStorePairByKey(key, storeType, backOffer);
|
||||
return build(pair.first, pair.second, storeType);
|
||||
}
|
||||
|
||||
public synchronized RegionStoreClient build(TiRegion region) throws GrpcException {
|
||||
TiStore store = regionManager.getStoreById(region.getLeader().getStoreId());
|
||||
return build(region, defaultBackOff());
|
||||
}
|
||||
|
||||
public synchronized RegionStoreClient build(TiRegion region, BackOffer backOffer)
|
||||
throws GrpcException {
|
||||
TiStore store = regionManager.getStoreById(region.getLeader().getStoreId(), backOffer);
|
||||
return build(region, store, TiStoreType.TiKV);
|
||||
}
|
||||
|
||||
public RegionManager getRegionManager() {
|
||||
return regionManager;
|
||||
}
|
||||
|
||||
private BackOffer defaultBackOff() {
|
||||
return ConcreteBackOffer.newCustomBackOff(conf.getRawKVDefaultBackoffInMS());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package org.tikv.common.util;
|
|||
public interface BackOffer {
|
||||
// Back off types.
|
||||
int seconds = 1000;
|
||||
int COP_BUILD_TASK_MAX_BACKOFF = 5 * seconds;
|
||||
int TSO_MAX_BACKOFF = 5 * seconds;
|
||||
int SCANNER_NEXT_MAX_BACKOFF = 40 * seconds;
|
||||
int BATCH_GET_MAX_BACKOFF = 40 * seconds;
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
try {
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
while (true) {
|
||||
RegionStoreClient client = clientBuilder.build(key);
|
||||
RegionStoreClient client = clientBuilder.build(key, backOffer);
|
||||
try {
|
||||
client.rawPut(backOffer, key, value, ttl, atomicForCAS);
|
||||
RAW_REQUEST_SUCCESS.labels(label).inc();
|
||||
|
|
@ -211,7 +211,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
try {
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
while (true) {
|
||||
RegionStoreClient client = clientBuilder.build(key);
|
||||
RegionStoreClient client = clientBuilder.build(key, backOffer);
|
||||
try {
|
||||
client.rawCompareAndSet(backOffer, key, prevValue, value, ttl);
|
||||
RAW_REQUEST_SUCCESS.labels(label).inc();
|
||||
|
|
@ -269,7 +269,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
try {
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
while (true) {
|
||||
RegionStoreClient client = clientBuilder.build(key);
|
||||
RegionStoreClient client = clientBuilder.build(key, backOffer);
|
||||
try {
|
||||
Optional<ByteString> result = client.rawGet(defaultBackOff(), key);
|
||||
RAW_REQUEST_SUCCESS.labels(label).inc();
|
||||
|
|
@ -342,7 +342,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
try {
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
while (true) {
|
||||
RegionStoreClient client = clientBuilder.build(key);
|
||||
RegionStoreClient client = clientBuilder.build(key, backOffer);
|
||||
try {
|
||||
Optional<Long> result = client.rawGetKeyTTL(defaultBackOff(), key);
|
||||
RAW_REQUEST_SUCCESS.labels(label).inc();
|
||||
|
|
@ -590,7 +590,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
try {
|
||||
BackOffer backOffer = defaultBackOff();
|
||||
while (true) {
|
||||
RegionStoreClient client = clientBuilder.build(key);
|
||||
RegionStoreClient client = clientBuilder.build(key, backOffer);
|
||||
try {
|
||||
client.rawDelete(defaultBackOff(), key, atomicForCAS);
|
||||
RAW_REQUEST_SUCCESS.labels(label).inc();
|
||||
|
|
@ -820,7 +820,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
|
||||
private Pair<List<Batch>, List<KvPair>> doSendBatchGetInBatchesWithRetry(
|
||||
BackOffer backOffer, Batch batch) {
|
||||
RegionStoreClient client = clientBuilder.build(batch.getRegion());
|
||||
RegionStoreClient client = clientBuilder.build(batch.getRegion(), backOffer);
|
||||
try {
|
||||
List<KvPair> partialResult = client.rawBatchGet(backOffer, batch.getKeys());
|
||||
return Pair.create(new ArrayList<>(), partialResult);
|
||||
|
|
@ -860,7 +860,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
}
|
||||
|
||||
private List<Batch> doSendBatchDeleteInBatchesWithRetry(BackOffer backOffer, Batch batch) {
|
||||
RegionStoreClient client = clientBuilder.build(batch.getRegion());
|
||||
RegionStoreClient client = clientBuilder.build(batch.getRegion(), backOffer);
|
||||
try {
|
||||
client.rawBatchDelete(backOffer, batch.getKeys(), atomicForCAS);
|
||||
return new ArrayList<>();
|
||||
|
|
@ -910,7 +910,7 @@ public class RawKVClient implements AutoCloseable {
|
|||
}
|
||||
|
||||
private List<DeleteRange> doSendDeleteRangeWithRetry(BackOffer backOffer, DeleteRange range) {
|
||||
try (RegionStoreClient client = clientBuilder.build(range.getRegion())) {
|
||||
try (RegionStoreClient client = clientBuilder.build(range.getRegion(), backOffer)) {
|
||||
client.setTimeout(conf.getScanTimeout());
|
||||
client.rawDeleteRange(backOffer, range.getStartKey(), range.getEndKey());
|
||||
return new ArrayList<>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue