Search in sources :

Example 86 with ServerLocation

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

the class AutoConnectionSourceImpl method updateLocatorList.

protected void updateLocatorList(LocatorListResponse response) {
    if (response == null)
        return;
    isBalanced = response.isBalanced();
    List<ServerLocation> locatorResponse = response.getLocators();
    List<InetSocketAddress> newLocators = new ArrayList<InetSocketAddress>(locatorResponse.size());
    List<InetSocketAddress> newOnlineLocators = new ArrayList<InetSocketAddress>(locatorResponse.size());
    Set<InetSocketAddress> badLocators = new HashSet<InetSocketAddress>(initialLocators);
    for (Iterator<ServerLocation> itr = locatorResponse.iterator(); itr.hasNext(); ) {
        ServerLocation locator = itr.next();
        InetSocketAddress address = new InetSocketAddress(locator.getHostName(), locator.getPort());
        newLocators.add(address);
        newOnlineLocators.add(address);
        badLocators.remove(address);
    }
    addbadLocators(newLocators, badLocators);
    if (logger.isInfoEnabled()) {
        LocatorList oldLocators = (LocatorList) locators.get();
        ArrayList<InetSocketAddress> removedLocators = new ArrayList<InetSocketAddress>(oldLocators.getLocators());
        removedLocators.removeAll(newLocators);
        ArrayList<InetSocketAddress> addedLocators = new ArrayList<InetSocketAddress>(newLocators);
        addedLocators.removeAll(oldLocators.getLocators());
        if (!addedLocators.isEmpty()) {
            locatorCallback.locatorsDiscovered(Collections.unmodifiableList(addedLocators));
            logger.info(LocalizedMessage.create(LocalizedStrings.AutoConnectionSourceImpl_AUTOCONNECTIONSOURCE_DISCOVERED_NEW_LOCATORS_0, addedLocators));
        }
        if (!removedLocators.isEmpty()) {
            locatorCallback.locatorsRemoved(Collections.unmodifiableList(removedLocators));
            logger.info(LocalizedMessage.create(LocalizedStrings.AutoConnectionSourceImpl_AUTOCONNECTIONSOURCE_DROPPING_PREVIOUSLY_DISCOVERED_LOCATORS_0, removedLocators));
        }
    }
    LocatorList newLocatorList = new LocatorList(newLocators);
    locators.set(newLocatorList);
    onlineLocators.set(new LocatorList(newOnlineLocators));
    pool.getStats().setLocatorCount(newLocators.size());
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 87 with ServerLocation

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

the class ClientMetadataService method pruneNodes.

private HashMap<ServerLocation, HashSet<Integer>> pruneNodes(ClientPartitionAdvisor prAdvisor, Set<Integer> buckets) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("ClientMetadataService: The buckets to be pruned are: {}", buckets);
    }
    HashMap<ServerLocation, HashSet<Integer>> serverToBucketsMap = new HashMap<ServerLocation, HashSet<Integer>>();
    HashMap<ServerLocation, HashSet<Integer>> prunedServerToBucketsMap = new HashMap<ServerLocation, HashSet<Integer>>();
    for (Integer bucketId : buckets) {
        List<BucketServerLocation66> serversList = prAdvisor.adviseServerLocations(bucketId);
        if (isDebugEnabled) {
            logger.debug("ClientMetadataService: For bucketId {} the server list is {}", bucketId, serversList);
        }
        if (serversList == null || serversList.size() == 0) {
            // will cause us to use the non-single hop path.
            return null;
        }
        if (isDebugEnabled) {
            logger.debug("ClientMetadataService: The buckets owners of the bucket: {} are: {}", bucketId, serversList);
        }
        for (ServerLocation server : serversList) {
            if (serverToBucketsMap.get(server) == null) {
                HashSet<Integer> bucketSet = new HashSet<Integer>();
                bucketSet.add(bucketId);
                serverToBucketsMap.put(server, bucketSet);
            } else {
                HashSet<Integer> bucketSet = serverToBucketsMap.get(server);
                bucketSet.add(bucketId);
                serverToBucketsMap.put(server, bucketSet);
            }
        }
    }
    if (isDebugEnabled) {
        logger.debug("ClientMetadataService: The server to buckets map is : {}", serverToBucketsMap);
    }
    HashSet<Integer> currentBucketSet = new HashSet<Integer>();
    // ServerLocation randomFirstServer =
    // prAdvisor.adviseRandomServerLocation(); // get a random server here
    ServerLocation randomFirstServer = null;
    if (serverToBucketsMap.isEmpty()) {
        return null;
    } else {
        int size = serverToBucketsMap.size();
        randomFirstServer = (ServerLocation) serverToBucketsMap.keySet().toArray()[rand.nextInt(size)];
    }
    HashSet<Integer> bucketSet = serverToBucketsMap.get(randomFirstServer);
    if (isDebugEnabled) {
        logger.debug("ClientMetadataService: Adding the server : {} which is random and buckets {} to prunedMap", randomFirstServer, bucketSet);
    }
    currentBucketSet.addAll(bucketSet);
    prunedServerToBucketsMap.put(randomFirstServer, bucketSet);
    serverToBucketsMap.remove(randomFirstServer);
    while (!currentBucketSet.equals(buckets)) {
        ServerLocation server = findNextServer(serverToBucketsMap.entrySet(), currentBucketSet);
        if (server == null) {
            // prunedServerToBucketsMap.put(randomFirstServer, rBuckets);
            break;
        }
        HashSet<Integer> bucketSet2 = serverToBucketsMap.get(server);
        bucketSet2.removeAll(currentBucketSet);
        if (bucketSet2.isEmpty()) {
            serverToBucketsMap.remove(server);
            continue;
        }
        currentBucketSet.addAll(bucketSet2);
        prunedServerToBucketsMap.put(server, bucketSet2);
        if (isDebugEnabled) {
            logger.debug("ClientMetadataService: Adding the server : {} and buckets {} to prunedServer.", server, bucketSet2);
        }
        serverToBucketsMap.remove(server);
    }
    if (isDebugEnabled) {
        logger.debug("ClientMetadataService: The final prunedServerToBucket calculated is : {}", prunedServerToBucketsMap);
    }
    return prunedServerToBucketsMap;
}
Also used : BucketServerLocation66(org.apache.geode.internal.cache.BucketServerLocation66) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 88 with ServerLocation

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

the class ClientMetadataService method getBucketServerLocation.

public ServerLocation getBucketServerLocation(Region region, Operation operation, Object key, Object value, Object callbackArg) {
    ClientPartitionAdvisor prAdvisor = this.getClientPartitionAdvisor(region.getFullPath());
    if (prAdvisor == null) {
        return null;
    }
    int totalNumberOfBuckets = prAdvisor.getTotalNumBuckets();
    final PartitionResolver resolver = getResolver(region, key, callbackArg);
    Object resolveKey;
    EntryOperation entryOp = null;
    if (resolver == null) {
        // client has not registered PartitionResolver
        // Assuming even PR at server side is not using PartitionResolver
        resolveKey = key;
    } else {
        entryOp = new EntryOperationImpl(region, operation, key, value, callbackArg);
        resolveKey = resolver.getRoutingObject(entryOp);
        if (resolveKey == null) {
            throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_THE_ROUTINGOBJECT_RETURNED_BY_PARTITIONRESOLVER_IS_NULL.toLocalizedString());
        }
    }
    int bucketId;
    if (resolver instanceof FixedPartitionResolver) {
        if (entryOp == null) {
            entryOp = new EntryOperationImpl(region, Operation.FUNCTION_EXECUTION, key, null, null);
        }
        String partition = ((FixedPartitionResolver) resolver).getPartitionName(entryOp, prAdvisor.getFixedPartitionNames());
        if (partition == null) {
            Object[] prms = new Object[] { region.getName(), resolver };
            throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_FOR_REGION_0_PARTITIONRESOLVER_1_RETURNED_PARTITION_NAME_NULL.toLocalizedString(prms));
        } else {
            bucketId = prAdvisor.assignFixedBucketId(region, partition, resolveKey);
            if (bucketId == -1) {
                // scheduleGetPRMetaData((LocalRegion)region);
                return null;
            }
        }
    } else {
        bucketId = PartitionedRegionHelper.getHashKey(resolveKey, totalNumberOfBuckets);
    }
    ServerLocation bucketServerLocation = getServerLocation(region, operation, bucketId);
    ServerLocation location = null;
    if (bucketServerLocation != null) {
        location = new ServerLocation(bucketServerLocation.getHostName(), bucketServerLocation.getPort());
    }
    return location;
}
Also used : EntryOperationImpl(org.apache.geode.internal.cache.EntryOperationImpl) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionResolver(org.apache.geode.cache.PartitionResolver) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) EntryOperation(org.apache.geode.cache.EntryOperation)

Example 89 with ServerLocation

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

the class ConnectionFactoryImpl method authenticateIfRequired.

private void authenticateIfRequired(Connection conn) {
    cancelCriterion.checkCancelInProgress(null);
    if (!pool.isUsedByGateway() && !pool.getMultiuserAuthentication()) {
        ServerLocation server = conn.getServer();
        if (server.getRequiresCredentials()) {
            if (server.getUserId() == -1) {
                Long uniqueID = (Long) AuthenticateUserOp.executeOn(conn, pool);
                server.setUserId(uniqueID);
                if (logger.isDebugEnabled()) {
                    logger.debug("CFI.authenticateIfRequired() Completed authentication on {}", conn);
                }
            }
        }
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Example 90 with ServerLocation

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

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