Search in sources :

Example 1 with ExecuteRegionFunctionOpImpl

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);
}
Also used : ExecuteRegionFunctionOpImpl(org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl) TransactionException(org.apache.geode.cache.TransactionException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) ExecuteFunctionOpImpl(org.apache.geode.cache.client.internal.ExecuteFunctionOp.ExecuteFunctionOpImpl)

Example 2 with ExecuteRegionFunctionOpImpl

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;
}
Also used : ExecuteRegionFunctionOpImpl(org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl) AllConnectionsInUseException(org.apache.geode.cache.client.AllConnectionsInUseException) ExecuteRegionFunctionSingleHopOpImpl(org.apache.geode.cache.client.internal.ExecuteRegionFunctionSingleHopOp.ExecuteRegionFunctionSingleHopOpImpl)

Aggregations

ExecuteRegionFunctionOpImpl (org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl)2 TransactionException (org.apache.geode.cache.TransactionException)1 AllConnectionsInUseException (org.apache.geode.cache.client.AllConnectionsInUseException)1 ExecuteFunctionOpImpl (org.apache.geode.cache.client.internal.ExecuteFunctionOp.ExecuteFunctionOpImpl)1 ExecuteRegionFunctionSingleHopOpImpl (org.apache.geode.cache.client.internal.ExecuteRegionFunctionSingleHopOp.ExecuteRegionFunctionSingleHopOpImpl)1 TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)1