Search in sources :

Example 81 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class QueueManagerImpl method createNewPrimary.

/**
   * Create a new primary server from a non-redundant server.
   * 
   * Add any failed servers to the excludedServers set.
   */
private QueueConnectionImpl createNewPrimary(Set excludedServers) {
    QueueConnectionImpl primary = null;
    while (primary == null && pool.getPoolOrCacheCancelInProgress() == null) {
        List servers = findQueueServers(excludedServers, 1, false, printPrimaryNotFoundError, LocalizedStrings.QueueManagerImpl_COULD_NOT_FIND_SERVER_TO_CREATE_PRIMARY_CLIENT_QUEUE);
        // printed above
        printPrimaryNotFoundError = false;
        if (servers == null || servers.isEmpty()) {
            break;
        }
        Connection connection = null;
        try {
            connection = factory.createClientToServerConnection((ServerLocation) servers.get(0), true);
        } catch (GemFireSecurityException e) {
            throw e;
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("SubscriptionManagerImpl - error creating a connection to server {}", servers.get(0));
            }
        }
        if (connection != null) {
            primary = initializeQueueConnection(connection, true, queueConnections.getFailedUpdater());
        }
        excludedServers.addAll(servers);
    }
    if (primary != null && sentClientReady && primary.sendClientReady()) {
        readyForEventsAfterFailover(primary);
    }
    return primary;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 82 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class QueueManagerImpl method recoverRedundancy.

/**
   * Make sure that we have enough backup servers.
   * 
   * Add any servers we fail to connect to to the excluded servers list.
   */
protected boolean recoverRedundancy(Set excludedServers, boolean recoverInterest) {
    if (pool.getPoolOrCacheCancelInProgress() != null) {
        return true;
    }
    int additionalBackups;
    while (pool.getPoolOrCacheCancelInProgress() == null && ((additionalBackups = redundancyLevel - getCurrentRedundancy()) > 0 || redundancyLevel == -1)) {
        if (redundancyLevel != -1 && printRecoveringRedundant) {
            logger.info(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_SUBSCRIPTION_MANAGER_REDUNDANCY_SATISFIER_REDUNDANT_ENDPOINT_HAS_BEEN_LOST_ATTEMPTIMG_TO_RECOVER));
            printRecoveringRedundant = false;
        }
        List servers = findQueueServers(excludedServers, redundancyLevel == -1 ? -1 : additionalBackups, false, (redundancyLevel == -1 ? false : printRedundancyNotSatisfiedError), LocalizedStrings.QueueManagerImpl_COULD_NOT_FIND_SERVER_TO_CREATE_REDUNDANT_CLIENT_QUEUE);
        if (servers == null || servers.isEmpty()) {
            if (redundancyLevel != -1) {
                if (printRedundancyNotSatisfiedError) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_REDUNDANCY_LEVEL_0_IS_NOT_SATISFIED_BUT_THERE_ARE_NO_MORE_SERVERS_AVAILABLE_REDUNDANCY_IS_CURRENTLY_1, new Object[] { redundancyLevel, getCurrentRedundancy() }));
                }
            }
            // printed above
            printRedundancyNotSatisfiedError = false;
            return false;
        }
        excludedServers.addAll(servers);
        final boolean isDebugEnabled = logger.isDebugEnabled();
        for (Iterator itr = servers.iterator(); itr.hasNext(); ) {
            ServerLocation server = (ServerLocation) itr.next();
            Connection connection = null;
            try {
                connection = factory.createClientToServerConnection(server, true);
            } catch (GemFireSecurityException e) {
                throw e;
            } catch (Exception e) {
                if (isDebugEnabled) {
                    logger.debug("SubscriptionManager - Error connecting to server: ()", server, e);
                }
            }
            if (connection == null) {
                continue;
            }
            QueueConnectionImpl queueConnection = initializeQueueConnection(connection, false, null);
            if (queueConnection != null) {
                boolean isFirstNewConnection = false;
                synchronized (lock) {
                    if (recoverInterest && queueConnections.getPrimary() == null && queueConnections.getBackups().isEmpty()) {
                        // we lost our queue at some point. We Need to recover
                        // interest. This server will be made primary after this method
                        // finishes
                        // because whoever killed the primary when this method started
                        // should
                        // have scheduled a task to recover the primary.
                        isFirstNewConnection = true;
                    // TODO - Actually, we need a better check than the above. There's
                    // still a chance
                    // that we haven't realized that the primary has died but it is
                    // already gone. We should
                    // get some information from the queue server about whether it was
                    // able to copy the
                    // queue from another server and decide if we need to recover our
                    // interest based on
                    // that information.
                    }
                }
                boolean promotionFailed = false;
                if (isFirstNewConnection) {
                    if (!promoteBackupCnxToPrimary(queueConnection)) {
                        promotionFailed = true;
                    }
                }
                if (!promotionFailed) {
                    if (addToConnectionList(queueConnection, isFirstNewConnection)) {
                        // redundancy satisfied
                        printRedundancyNotSatisfiedError = true;
                        printRecoveringRedundant = true;
                        if (logger.isDebugEnabled()) {
                            logger.debug("SubscriptionManager redundancy satisfier - created a queue on server {}", queueConnection.getEndpoint());
                        }
                        // redundant server.
                        if (recoverInterest) {
                            recoverInterest(queueConnection, isFirstNewConnection);
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 83 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class ExplicitConnectionSourceImpl method pickQueueServers.

private List pickQueueServers(Set excludedServers, int numServers) {
    ArrayList result = new ArrayList();
    ServerLocation nextQueue;
    int startIndex = nextQueueIndex;
    do {
        nextQueue = (ServerLocation) serverList.get(nextQueueIndex);
        if (++nextQueueIndex >= serverList.size()) {
            nextQueueIndex = 0;
        }
        if (!excludedServers.contains(nextQueue)) {
            result.add(nextQueue);
        }
    } while (nextQueueIndex != startIndex && result.size() < numServers);
    return result;
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Example 84 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class GetAllOp method constructGetAllTasks.

static List constructGetAllTasks(String region, final Map<ServerLocation, HashSet> serverToFilterMap, final PoolImpl pool, final Object callback) {
    final List<SingleHopOperationCallable> tasks = new ArrayList<SingleHopOperationCallable>();
    ArrayList<ServerLocation> servers = new ArrayList<ServerLocation>(serverToFilterMap.keySet());
    if (logger.isDebugEnabled()) {
        logger.debug("Constructing tasks for the servers {}", servers);
    }
    for (ServerLocation server : servers) {
        Set filterSet = serverToFilterMap.get(server);
        AbstractOp getAllOp = new GetAllOpImpl(region, new ArrayList(filterSet), callback);
        SingleHopOperationCallable task = new SingleHopOperationCallable(new ServerLocation(server.getHostName(), server.getPort()), pool, getAllOp, UserAttributes.userAttributes.get());
        tasks.add(task);
    }
    return tasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList)

Example 85 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation 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)

Aggregations

ServerLocation (org.apache.geode.distributed.internal.ServerLocation)95 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 List (java.util.List)18 HashMap (java.util.HashMap)17 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)17 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)13 Map (java.util.Map)12 Iterator (java.util.Iterator)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Set (java.util.Set)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 LinkedHashSet (java.util.LinkedHashSet)7 Host (org.apache.geode.test.dunit.Host)7 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5