Skip to content

Commit 83802ff

Browse files
authored
retry queryAndMutate operation in odp mode (#359)
1 parent 4b03b22 commit 83802ff

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,28 +2268,28 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
22682268
if (tableQuery.getKeyRanges().isEmpty()) {
22692269
tableQuery.addKeyRange(ObNewRange.getWholeRange());
22702270
}
2271-
if (isOdpMode()) {
2272-
request.setTimeout(getOdpTable().getObTableOperationTimeout());
2273-
return getOdpTable().execute(request);
2274-
} else {
2275-
int tryTimes = 0;
2276-
boolean needRefreshTabletLocation = false;
2277-
long startExecute = System.currentTimeMillis();
2278-
while (true) {
2279-
long currentExecute = System.currentTimeMillis();
2280-
long costMillis = currentExecute - startExecute;
2281-
if (costMillis > getRuntimeMaxWait()) {
2282-
logger.error(
2283-
"tablename:{} it has tried " + tryTimes
2284-
+ " times and it has waited " + costMillis
2285-
+ "/ms which exceeds response timeout "
2286-
+ getRuntimeMaxWait() + "/ms", request.getTableName());
2287-
throw new ObTableTimeoutExcetion("it has tried " + tryTimes
2288-
+ " times and it has waited " + costMillis
2289-
+ "/ms which exceeds response timeout "
2290-
+ getRuntimeMaxWait() + "/ms");
2291-
}
2292-
try {
2271+
int tryTimes = 0;
2272+
boolean needRefreshTabletLocation = false;
2273+
long startExecute = System.currentTimeMillis();
2274+
while (true) {
2275+
long currentExecute = System.currentTimeMillis();
2276+
long costMillis = currentExecute - startExecute;
2277+
if (costMillis > getRuntimeMaxWait()) {
2278+
logger.error(
2279+
"tablename:{} it has tried " + tryTimes
2280+
+ " times and it has waited " + costMillis
2281+
+ "/ms which exceeds response timeout "
2282+
+ getRuntimeMaxWait() + "/ms", request.getTableName());
2283+
throw new ObTableTimeoutExcetion("it has tried " + tryTimes
2284+
+ " times and it has waited " + costMillis
2285+
+ "/ms which exceeds response timeout "
2286+
+ getRuntimeMaxWait() + "/ms");
2287+
}
2288+
try {
2289+
if (odpMode) {
2290+
request.setTimeout(getOdpTable().getObTableOperationTimeout());
2291+
return getOdpTable().execute(request);
2292+
} else {
22932293
// Recalculate partIdMapObTable
22942294
if (needRefreshTabletLocation) {
22952295
needRefreshTabletLocation = false;
@@ -2317,8 +2317,29 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
23172317

23182318
// Attempt to execute the operation
23192319
return executeWithRetry(obTable, request, request.getTableName());
2320-
} catch (Exception ex) {
2321-
tryTimes++;
2320+
}
2321+
} catch (Exception ex) {
2322+
tryTimes++;
2323+
if (odpMode) {
2324+
// about routing problems, ODP will retry on their side
2325+
if (ex instanceof ObTableException) {
2326+
// errors needed to retry will retry until timeout
2327+
if (((ObTableException) ex).isNeedRetryError()) {
2328+
logger.warn(
2329+
"meet need retry exception when execute queryAndMutate in odp mode. tablename: {}, errorCode: {} , errorMsg: {}, try times {}",
2330+
request.getTableName(), ((ObTableException) ex).getErrorCode(),
2331+
ex.getMessage(), tryTimes);
2332+
} else {
2333+
logger.warn("meet table exception when execute queryAndMutate in odp mode. tablename: {}, errMsg: {}"
2334+
, request.getTableName(), ex.getMessage());
2335+
throw ex;
2336+
}
2337+
} else {
2338+
logger.warn("meet exception when execute queryAndMutate in odp mode. tablename: {}, errMsg: {}",
2339+
request.getTableName(), ex.getMessage());
2340+
throw ex;
2341+
}
2342+
} else {
23222343
if (ex instanceof ObTableException &&
23232344
(((ObTableException) ex).isNeedRefreshTableEntry() || ((ObTableException) ex).isNeedRetryError())) {
23242345
logger.warn(

0 commit comments

Comments
 (0)