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());
}
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;
}
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;
}
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);
}
}
}
}
}
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);
}
Aggregations