use of org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl 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);
}
use of org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl in project geode by apache.
the class SingleHopOperationCallable method call.
public Object call() throws Exception {
op.initMessagePart();
Object result = null;
boolean onlyUseExistingCnx = ((pool.getMaxConnections() != -1 && pool.getConnectionCount() >= pool.getMaxConnections()) ? true : false);
op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
try {
UserAttributes.userAttributes.set(securityAttributes);
result = this.pool.executeOn(server, op, true, onlyUseExistingCnx);
} catch (AllConnectionsInUseException ex) {
// server
if (op instanceof ExecuteRegionFunctionSingleHopOpImpl) {
ExecuteRegionFunctionSingleHopOpImpl newop = (ExecuteRegionFunctionSingleHopOpImpl) op;
result = this.pool.execute(new ExecuteRegionFunctionOpImpl(newop));
} else {
result = this.pool.execute(this.op);
}
} finally {
UserAttributes.userAttributes.set(null);
}
return result;
}
Aggregations