Search in sources :

Example 1 with ServerConnectivityException

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

the class SingleHopClientExecutor method submitAllHA.

static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    boolean reexecute = false;
    if (callableTasks != null && !callableTasks.isEmpty()) {
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            GemFireException functionExecutionException = null;
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    fut.get();
                    if (isDebugEnabled) {
                        logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
                    }
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        reexecute = true;
                        failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            rc.clearResults();
                        } else {
                            if (ee.getCause().getCause() != null) {
                                functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
                            } else {
                                functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
                            }
                        }
                    } else if (ee.getCause() instanceof FunctionException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
                        }
                        FunctionException fe = (FunctionException) ee.getCause();
                        if (isHA) {
                            throw fe;
                        } else {
                            functionExecutionException = fe;
                        }
                    } else if (ee.getCause() instanceof ServerOperationException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        if (isHA) {
                            throw soe;
                        } else {
                            functionExecutionException = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            reexecute = true;
                            rc.clearResults();
                        } else {
                            functionExecutionException = (ServerConnectivityException) ee.getCause();
                        }
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            if (functionExecutionException != null) {
                throw functionExecutionException;
            }
        }
    }
    return reexecute;
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalGemFireException(org.apache.geode.InternalGemFireException) GemFireException(org.apache.geode.GemFireException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ServerConnectivityException

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

the class QueueManagerImpl method getAllConnections.

public QueueConnections getAllConnections() {
    ConnectionList snapshot = queueConnections;
    if (snapshot.getPrimary() == null) {
        // wait for a new primary to become available.
        synchronized (lock) {
            snapshot = queueConnections;
            while (snapshot.getPrimary() == null && !snapshot.primaryDiscoveryFailed() && !shuttingDown && pool.getPoolOrCacheCancelInProgress() == null) {
                try {
                    lock.wait();
                } catch (InterruptedException ignore) {
                    Thread.currentThread().interrupt();
                    break;
                }
                snapshot = queueConnections;
            }
        }
    }
    if (snapshot.getPrimary() == null) {
        pool.getCancelCriterion().checkCancelInProgress(null);
        GemFireException exception = snapshot.getPrimaryDiscoveryException();
        if (exception == null || exception instanceof NoSubscriptionServersAvailableException) {
            exception = new NoSubscriptionServersAvailableException(exception);
        } else {
            exception = new ServerConnectivityException(exception.getMessage(), exception);
        }
        throw exception;
    }
    return snapshot;
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireException(org.apache.geode.GemFireException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 3 with ServerConnectivityException

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

the class ExecuteFunctionOp method execute.

public static void execute(final PoolImpl pool, String functionId, ServerFunctionExecutor executor, Object args, MemberMappedArgument memberMappedArg, boolean allServers, byte hasResult, ResultCollector rc, boolean isFnSerializationReqd, boolean isHA, boolean optimizeForWrite, UserAttributes properties, String[] groups) {
    final AbstractOp op = new ExecuteFunctionOpImpl(functionId, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, isHA, optimizeForWrite, (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, functionId, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, isHA, optimizeForWrite, properties);
        SingleHopClientExecutor.submitAll(callableTasks);
    } else {
        boolean reexecuteForServ = false;
        AbstractOp reexecOp = null;
        int retryAttempts = 0;
        boolean reexecute = false;
        int maxRetryAttempts = 0;
        if (isHA) {
            maxRetryAttempts = pool.getRetryAttempts();
        }
        final boolean isDebugEnabled = logger.isDebugEnabled();
        do {
            try {
                if (reexecuteForServ) {
                    reexecOp = new ExecuteFunctionOpImpl(functionId, args, memberMappedArg, hasResult, rc, isFnSerializationReqd, isHA, optimizeForWrite, (byte) 1, 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 && isHA) {
            ExecuteFunctionOp.reexecute(pool, functionId, executor, rc, hasResult, isFnSerializationReqd, maxRetryAttempts - 1, args, isHA, optimizeForWrite, 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 4 with ServerConnectivityException

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

the class GetAllOp method execute.

public static VersionedObjectList execute(ExecutablePool pool, Region region, List keys, int retryAttempts, Object callback) {
    AbstractOp op = new GetAllOpImpl(region.getFullPath(), keys, callback);
    ClientMetadataService cms = ((LocalRegion) region).getCache().getClientMetadataService();
    Map<ServerLocation, HashSet> serverToFilterMap = cms.getServerToFilterMap(keys, region, true);
    if (serverToFilterMap == null || serverToFilterMap.isEmpty()) {
        op.initMessagePart();
        return ((VersionedObjectList) pool.execute(op)).setKeys(keys);
    } else {
        VersionedObjectList result = null;
        ServerConnectivityException se = null;
        List retryList = new ArrayList();
        List callableTasks = constructGetAllTasks(region.getFullPath(), serverToFilterMap, (PoolImpl) pool, callback);
        Map<ServerLocation, Object> results = SingleHopClientExecutor.submitGetAll(serverToFilterMap, callableTasks, cms, (LocalRegion) region);
        for (ServerLocation server : results.keySet()) {
            Object serverResult = results.get(server);
            if (serverResult instanceof ServerConnectivityException) {
                se = (ServerConnectivityException) serverResult;
                retryList.addAll(serverToFilterMap.get(server));
            } else {
                if (result == null) {
                    result = (VersionedObjectList) serverResult;
                } else {
                    result.addAll((VersionedObjectList) serverResult);
                }
            }
        }
        if (se != null) {
            if (retryAttempts == 0) {
                throw se;
            } else {
                VersionedObjectList retryResult = GetAllOp.execute(pool, region.getFullPath(), retryList, callback);
                if (result == null) {
                    result = retryResult;
                } else {
                    result.addAll(retryResult);
                }
            }
        }
        return result;
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) ArrayList(java.util.ArrayList) List(java.util.List) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) HashSet(java.util.HashSet)

Example 5 with ServerConnectivityException

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

the class GetOp method execute.

/**
   * Does a region get 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 get on
   * @param key the entry key to do the get on
   * @param callbackArg an optional callback arg to pass to any cache callbacks
   * @param clientEvent holder for returning version information
   * @return the entry value found by the get if any
   */
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object callbackArg, boolean prSingleHopEnabled, EntryEventImpl clientEvent) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    GetOpImpl op = new GetOpImpl(region, key, callbackArg, prSingleHopEnabled, clientEvent);
    if (logger.isDebugEnabled()) {
        logger.debug("GetOp invoked for key {}", key);
    }
    if (prSingleHopEnabled) {
        ServerLocation server = cms.getBucketServerLocation(region, Operation.GET, 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(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);
            } catch (CacheLoaderException e) {
                if (e.getCause() instanceof ServerConnectivityException)
                    cms.removeBucketServerLocation(server);
            }
        }
    }
    return pool.execute(op);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) 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