Search in sources :

Example 31 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ExecuteFunctionOp method execute.

/**
   * Does a execute Function on a server using connections from the given pool to communicate with
   * the server.
   * 
   * @param pool the pool to use to communicate with the server.
   * @param function of the function to be executed
   * @param args specified arguments to the application function
   */
public static void execute(final PoolImpl pool, Function function, ServerFunctionExecutor executor, Object args, MemberMappedArgument memberMappedArg, boolean allServers, byte hasResult, ResultCollector rc, boolean isFnSerializationReqd, UserAttributes attributes, String[] groups) {
    final AbstractOp op = new ExecuteFunctionOpImpl(function, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, (byte) 0, groups, allServers, executor.isIgnoreDepartedMembers());
    if (allServers && groups.length == 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("ExecuteFunctionOp#execute : Sending Function Execution Message:{} to all servers using pool: {}", op.getMessage(), pool);
        }
        List callableTasks = constructAndGetFunctionTasks(pool, function, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, attributes);
        SingleHopClientExecutor.submitAll(callableTasks);
    } else {
        boolean reexecuteForServ = false;
        AbstractOp reexecOp = null;
        int retryAttempts = 0;
        boolean reexecute = false;
        int maxRetryAttempts = 0;
        if (function.isHA())
            maxRetryAttempts = pool.getRetryAttempts();
        final boolean isDebugEnabled = logger.isDebugEnabled();
        do {
            try {
                if (reexecuteForServ) {
                    if (isDebugEnabled) {
                        logger.debug("ExecuteFunctionOp#execute.reexecuteForServ : Sending Function Execution Message:{} to server using pool: {} with groups:{} all members:{} ignoreFailedMembers:{}", op.getMessage(), pool, Arrays.toString(groups), allServers, executor.isIgnoreDepartedMembers());
                    }
                    reexecOp = new ExecuteFunctionOpImpl(function, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, (byte) 1, /* isReExecute */
                    groups, allServers, executor.isIgnoreDepartedMembers());
                    pool.execute(reexecOp, 0);
                } else {
                    if (isDebugEnabled) {
                        logger.debug("ExecuteFunctionOp#execute : Sending Function Execution Message:{} to server using pool: {} with groups:{} all members:{} ignoreFailedMembers:{}", op.getMessage(), pool, Arrays.toString(groups), allServers, executor.isIgnoreDepartedMembers());
                    }
                    pool.execute(op, 0);
                }
                reexecute = false;
                reexecuteForServ = false;
            } catch (InternalFunctionInvocationTargetException e) {
                if (isDebugEnabled) {
                    logger.debug("ExecuteFunctionOp#execute : Received InternalFunctionInvocationTargetException. The failed node is {}", e.getFailedNodeSet());
                }
                reexecute = true;
                rc.clearResults();
            } catch (ServerConnectivityException se) {
                retryAttempts++;
                if (isDebugEnabled) {
                    logger.debug("ExecuteFunctionOp#execute : Received ServerConnectivityException. The exception is {} The retryAttempt is : {} maxRetryAttempts  {}", se, retryAttempts, maxRetryAttempts);
                }
                if (se instanceof ServerOperationException) {
                    throw se;
                }
                if ((retryAttempts > maxRetryAttempts && maxRetryAttempts != -1))
                    throw se;
                reexecuteForServ = true;
                rc.clearResults();
            }
        } while (reexecuteForServ);
        if (reexecute && function.isHA()) {
            ExecuteFunctionOp.reexecute(pool, function, executor, rc, hasResult, isFnSerializationReqd, maxRetryAttempts - 1, groups, allServers);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) ArrayList(java.util.ArrayList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 32 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class PutOp method execute.

/**
   * Does a region put on a server using connections from the given pool to communicate with the
   * server.
   * 
   * @param pool the pool to use to communicate with the server.
   * @param region the region to do the put on
   * @param key the entry key to do the put on
   * @param value the entry value to put
   * @param event the event for this put
   * @param requireOldValue
   * @param expectedOldValue
   * @param callbackArg an optional callback arg to pass to any cache callbacks
   */
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object value, byte[] deltaBytes, EntryEventImpl event, Operation operation, boolean requireOldValue, Object expectedOldValue, Object callbackArg, boolean prSingleHopEnabled) {
    PutOpImpl op = new PutOpImpl(region, key, value, deltaBytes, event, operation, requireOldValue, expectedOldValue, callbackArg, false, /* donot send full obj; send delta */
    prSingleHopEnabled);
    if (prSingleHopEnabled) {
        ClientMetadataService cms = region.getCache().getClientMetadataService();
        ServerLocation server = cms.getBucketServerLocation(region, Operation.UPDATE, key, value, callbackArg);
        if (server != null) {
            try {
                PoolImpl poolImpl = (PoolImpl) pool;
                boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
                op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
                return pool.executeOn(new ServerLocation(server.getHostName(), server.getPort()), op, true, onlyUseExistingCnx);
            } catch (AllConnectionsInUseException e) {
            } catch (ServerConnectivityException e) {
                if (e instanceof ServerOperationException) {
                    // fixed 44656
                    throw e;
                }
                cms.removeBucketServerLocation(server);
            }
        }
    }
    return pool.execute(op);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AllConnectionsInUseException(org.apache.geode.cache.client.AllConnectionsInUseException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 33 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class PoolImpl method killPrimaryEndpoint.

/**
   * Test hook used to simulate a kill of the primaryEndpoint
   */
public // throws ServerException
void killPrimaryEndpoint() {
    boolean ok = false;
    if (this.queueManager != null) {
        QueueManager.QueueConnections cons = this.queueManager.getAllConnections();
        Connection con = cons.getPrimary();
        if (con != null) {
            final String msg = "killing primary endpoint";
            logger.info("<ExpectedException action=add>{}</ExpectedException>", msg);
            Exception e = new Exception(msg);
            try {
                processException(e, con);
            } catch (ServerConnectivityException ignore) {
            } finally {
                logger.info("<ExpectedException action=remove>{}</ExpectedException>", msg);
            }
            // do some validation here that we are no longer connected to "sl"
            ok = true;
        }
    }
    if (!ok) {
        throw new IllegalStateException("primaryEndpoint was null");
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CancelException(org.apache.geode.CancelException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) PoolCancelledException(org.apache.geode.distributed.PoolCancelledException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException)

Example 34 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class ServerFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(String functionId, ResultCollector rc, byte hasResult, boolean isHA, boolean optimizeForWrite) {
    FunctionStats stats = FunctionStats.getFunctionStats(functionId);
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        ExecuteFunctionOp.execute(this.pool, functionId, this, args, memberMappedArg, this.allServers, hasResult, rc, this.isFnSerializationReqd, isHA, optimizeForWrite, UserAttributes.userAttributes.get(), groups);
        stats.endFunctionExecution(start, true);
        rc.endResults();
        return rc;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (ServerConnectivityException exception) {
        throw exception;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 35 with ServerConnectivityException

use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.

the class DestroyOp method execute.

/**
   * Does a region entry destroy on a server using connections from the given pool to communicate
   * with the server.
   * 
   * @param pool the pool to use to communicate with the server.
   * @param region the region to do the entry destroy on
   * @param key the entry key to do the destroy on
   * @param event the event for this destroy operation
   * @param callbackArg an optional callback arg to pass to any cache callbacks
   */
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object expectedOldValue, Operation operation, EntryEventImpl event, Object callbackArg, boolean prSingleHopEnabled) {
    if (logger.isDebugEnabled()) {
        logger.debug("Preparing DestroyOp for {} operation={}", key, operation);
    }
    DestroyOpImpl op = new DestroyOpImpl(region, key, expectedOldValue, operation, event, callbackArg, prSingleHopEnabled);
    if (prSingleHopEnabled) {
        ClientMetadataService cms = region.getCache().getClientMetadataService();
        ServerLocation server = cms.getBucketServerLocation(region, Operation.DESTROY, key, null, callbackArg);
        if (server != null) {
            try {
                PoolImpl poolImpl = (PoolImpl) pool;
                boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
                op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
                return pool.executeOn(server, op, true, onlyUseExistingCnx);
            } catch (AllConnectionsInUseException e) {
            } catch (ServerConnectivityException e) {
                if (e instanceof ServerOperationException) {
                    // fixed 44656
                    throw e;
                }
                cms.removeBucketServerLocation(server);
            }
        }
    }
    return pool.execute(op);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AllConnectionsInUseException(org.apache.geode.cache.client.AllConnectionsInUseException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Aggregations

ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)44 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)25 FunctionException (org.apache.geode.cache.execute.FunctionException)17 IOException (java.io.IOException)16 Region (org.apache.geode.cache.Region)13 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)12 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)10 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 CacheClosedException (org.apache.geode.cache.CacheClosedException)8 Pool (org.apache.geode.cache.client.Pool)6 ExecutablePool (org.apache.geode.cache.client.internal.ExecutablePool)6 Test (org.junit.Test)6 SocketTimeoutException (java.net.SocketTimeoutException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Execution (org.apache.geode.cache.execute.Execution)4