use of org.apache.geode.cache.client.internal.ExecuteFunctionOp.ExecuteFunctionOpImpl in project geode by apache.
the class OpExecutorImpl method executeWithServerAffinity.
/**
* execute the given op on the given server. If the server cannot be reached, sends a
* TXFailoverOp, then retries the given op
*
* @param loc the server to execute the op on
* @param op the op to execute
* @return the result of execution
*/
private Object executeWithServerAffinity(ServerLocation loc, Op op) {
try {
Object retVal = executeOnServer(loc, op, true, false);
affinityRetryCount.set(0);
return retVal;
} catch (ServerConnectivityException e) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while executing with affinity:{}", e.getMessage(), e);
}
if (!this.serverAffinityFailover || e instanceof ServerOperationException) {
affinityRetryCount.set(0);
throw e;
}
int retryCount = affinityRetryCount.get();
if ((retryAttempts != -1 && retryCount >= retryAttempts) || retryCount > TX_RETRY_ATTEMPT) {
// prevent
// stack
// overflow
// fixes
// bug
// 46535
affinityRetryCount.set(0);
throw e;
}
affinityRetryCount.set(retryCount + 1);
}
this.affinityServerLocation.set(null);
if (logger.isDebugEnabled()) {
logger.debug("reset server affinity: attempting txFailover");
}
// send TXFailoverOp, so that new server can
// do bootstrapping, then re-execute original op
AbstractOp absOp = (AbstractOp) op;
absOp.getMessage().setIsRetry();
int transactionId = absOp.getMessage().getTransactionId();
// so set it explicitly for TXFailoverOp
try {
TXFailoverOp.execute(this.pool, transactionId);
} catch (TransactionException e) {
// If this is the first operation in the transaction then
// do not throw TransactionDataNodeHasDeparted back to the
// user, re-try the op instead. fixes bug 44375. NOTE: TXFailoverOp
// is sent even after first op, as it is not known if the first
// operation has established a TXState already
TXStateProxy txState = TXManagerImpl.getCurrentTXState();
if (txState == null) {
throw e;
} else if (txState.operationCount() > 1) {
throw e;
}
}
if (op instanceof ExecuteRegionFunctionOpImpl) {
op = new ExecuteRegionFunctionOpImpl((ExecuteRegionFunctionOpImpl) op, (byte) 1, /* isReExecute */
new HashSet<String>());
((ExecuteRegionFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
} else if (op instanceof ExecuteFunctionOpImpl) {
op = new ExecuteFunctionOpImpl((ExecuteFunctionOpImpl) op, (byte) 1);
((ExecuteFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
}
return this.pool.execute(op);
}
Aggregations