pd backoff use tikv.rawkv.default_backoff_in_ms (#288) (#291)

Signed-off-by: marsishandsome <marsishandsome@gmail.com>
This commit is contained in:
Liangliang Gu 2021-10-22 16:01:48 +08:00 committed by GitHub
parent f3a3abf3ef
commit 599da193df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 15 deletions

View File

@ -94,7 +94,7 @@ public class RegionManager {
} }
public TiRegion getRegionByKey(ByteString key) { public TiRegion getRegionByKey(ByteString key) {
return getRegionByKey(key, ConcreteBackOffer.newGetBackOff()); return getRegionByKey(key, defaultBackOff());
} }
public TiRegion getRegionByKey(ByteString key, BackOffer backOffer) { 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. // Consider region A, B. After merge of (A, B) -> A, region ID B does not exist.
// This request is unrecoverable. // This request is unrecoverable.
public TiRegion getRegionById(long regionId) { public TiRegion getRegionById(long regionId) {
BackOffer backOffer = ConcreteBackOffer.newGetBackOff(); BackOffer backOffer = defaultBackOff();
TiRegion region = cache.getRegionById(regionId); TiRegion region = cache.getRegionById(regionId);
if (region == null) { if (region == null) {
Pair<Metapb.Region, Metapb.Peer> regionAndLeader = Pair<Metapb.Region, Metapb.Peer> regionAndLeader =
@ -144,7 +144,7 @@ public class RegionManager {
} }
public Pair<TiRegion, TiStore> getRegionStorePairByKey(ByteString key, TiStoreType storeType) { 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( public Pair<TiRegion, TiStore> getRegionStorePairByKey(
@ -216,7 +216,7 @@ public class RegionManager {
} }
public TiStore getStoreById(long id) { public TiStore getStoreById(long id) {
return getStoreById(id, ConcreteBackOffer.newGetBackOff()); return getStoreById(id, defaultBackOff());
} }
public void onRegionStale(TiRegion region) { public void onRegionStale(TiRegion region) {
@ -264,4 +264,8 @@ public class RegionManager {
public void invalidateRegion(TiRegion region) { public void invalidateRegion(TiRegion region) {
cache.invalidateRegion(region); cache.invalidateRegion(region);
} }
private BackOffer defaultBackOff() {
return ConcreteBackOffer.newCustomBackOff(conf.getRawKVDefaultBackoffInMS());
}
} }

View File

@ -1302,19 +1302,39 @@ public class RegionStoreClient extends AbstractRegionStoreClient {
return build(key, TiStoreType.TiKV); 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) public synchronized RegionStoreClient build(ByteString key, TiStoreType storeType)
throws GrpcException { 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); return build(pair.first, pair.second, storeType);
} }
public synchronized RegionStoreClient build(TiRegion region) throws GrpcException { 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); return build(region, store, TiStoreType.TiKV);
} }
public RegionManager getRegionManager() { public RegionManager getRegionManager() {
return regionManager; return regionManager;
} }
private BackOffer defaultBackOff() {
return ConcreteBackOffer.newCustomBackOff(conf.getRawKVDefaultBackoffInMS());
}
} }
} }

View File

@ -20,7 +20,6 @@ package org.tikv.common.util;
public interface BackOffer { public interface BackOffer {
// Back off types. // Back off types.
int seconds = 1000; int seconds = 1000;
int COP_BUILD_TASK_MAX_BACKOFF = 5 * seconds;
int TSO_MAX_BACKOFF = 5 * seconds; int TSO_MAX_BACKOFF = 5 * seconds;
int SCANNER_NEXT_MAX_BACKOFF = 40 * seconds; int SCANNER_NEXT_MAX_BACKOFF = 40 * seconds;
int BATCH_GET_MAX_BACKOFF = 40 * seconds; int BATCH_GET_MAX_BACKOFF = 40 * seconds;

View File

@ -125,7 +125,7 @@ public class RawKVClient implements AutoCloseable {
try { try {
BackOffer backOffer = defaultBackOff(); BackOffer backOffer = defaultBackOff();
while (true) { while (true) {
RegionStoreClient client = clientBuilder.build(key); RegionStoreClient client = clientBuilder.build(key, backOffer);
try { try {
client.rawPut(backOffer, key, value, ttl, atomicForCAS); client.rawPut(backOffer, key, value, ttl, atomicForCAS);
RAW_REQUEST_SUCCESS.labels(label).inc(); RAW_REQUEST_SUCCESS.labels(label).inc();
@ -211,7 +211,7 @@ public class RawKVClient implements AutoCloseable {
try { try {
BackOffer backOffer = defaultBackOff(); BackOffer backOffer = defaultBackOff();
while (true) { while (true) {
RegionStoreClient client = clientBuilder.build(key); RegionStoreClient client = clientBuilder.build(key, backOffer);
try { try {
client.rawCompareAndSet(backOffer, key, prevValue, value, ttl); client.rawCompareAndSet(backOffer, key, prevValue, value, ttl);
RAW_REQUEST_SUCCESS.labels(label).inc(); RAW_REQUEST_SUCCESS.labels(label).inc();
@ -269,7 +269,7 @@ public class RawKVClient implements AutoCloseable {
try { try {
BackOffer backOffer = defaultBackOff(); BackOffer backOffer = defaultBackOff();
while (true) { while (true) {
RegionStoreClient client = clientBuilder.build(key); RegionStoreClient client = clientBuilder.build(key, backOffer);
try { try {
Optional<ByteString> result = client.rawGet(defaultBackOff(), key); Optional<ByteString> result = client.rawGet(defaultBackOff(), key);
RAW_REQUEST_SUCCESS.labels(label).inc(); RAW_REQUEST_SUCCESS.labels(label).inc();
@ -342,7 +342,7 @@ public class RawKVClient implements AutoCloseable {
try { try {
BackOffer backOffer = defaultBackOff(); BackOffer backOffer = defaultBackOff();
while (true) { while (true) {
RegionStoreClient client = clientBuilder.build(key); RegionStoreClient client = clientBuilder.build(key, backOffer);
try { try {
Optional<Long> result = client.rawGetKeyTTL(defaultBackOff(), key); Optional<Long> result = client.rawGetKeyTTL(defaultBackOff(), key);
RAW_REQUEST_SUCCESS.labels(label).inc(); RAW_REQUEST_SUCCESS.labels(label).inc();
@ -590,7 +590,7 @@ public class RawKVClient implements AutoCloseable {
try { try {
BackOffer backOffer = defaultBackOff(); BackOffer backOffer = defaultBackOff();
while (true) { while (true) {
RegionStoreClient client = clientBuilder.build(key); RegionStoreClient client = clientBuilder.build(key, backOffer);
try { try {
client.rawDelete(defaultBackOff(), key, atomicForCAS); client.rawDelete(defaultBackOff(), key, atomicForCAS);
RAW_REQUEST_SUCCESS.labels(label).inc(); RAW_REQUEST_SUCCESS.labels(label).inc();
@ -820,7 +820,7 @@ public class RawKVClient implements AutoCloseable {
private Pair<List<Batch>, List<KvPair>> doSendBatchGetInBatchesWithRetry( private Pair<List<Batch>, List<KvPair>> doSendBatchGetInBatchesWithRetry(
BackOffer backOffer, Batch batch) { BackOffer backOffer, Batch batch) {
RegionStoreClient client = clientBuilder.build(batch.getRegion()); RegionStoreClient client = clientBuilder.build(batch.getRegion(), backOffer);
try { try {
List<KvPair> partialResult = client.rawBatchGet(backOffer, batch.getKeys()); List<KvPair> partialResult = client.rawBatchGet(backOffer, batch.getKeys());
return Pair.create(new ArrayList<>(), partialResult); return Pair.create(new ArrayList<>(), partialResult);
@ -860,7 +860,7 @@ public class RawKVClient implements AutoCloseable {
} }
private List<Batch> doSendBatchDeleteInBatchesWithRetry(BackOffer backOffer, Batch batch) { private List<Batch> doSendBatchDeleteInBatchesWithRetry(BackOffer backOffer, Batch batch) {
RegionStoreClient client = clientBuilder.build(batch.getRegion()); RegionStoreClient client = clientBuilder.build(batch.getRegion(), backOffer);
try { try {
client.rawBatchDelete(backOffer, batch.getKeys(), atomicForCAS); client.rawBatchDelete(backOffer, batch.getKeys(), atomicForCAS);
return new ArrayList<>(); return new ArrayList<>();
@ -910,7 +910,7 @@ public class RawKVClient implements AutoCloseable {
} }
private List<DeleteRange> doSendDeleteRangeWithRetry(BackOffer backOffer, DeleteRange range) { 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.setTimeout(conf.getScanTimeout());
client.rawDeleteRange(backOffer, range.getStartKey(), range.getEndKey()); client.rawDeleteRange(backOffer, range.getStartKey(), range.getEndKey());
return new ArrayList<>(); return new ArrayList<>();