use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class ClientPartitionAdvisor method advisePrimaryServerLocation.
public ServerLocation advisePrimaryServerLocation(int bucketId) {
if (this.bucketServerLocationsMap.containsKey(bucketId)) {
List<BucketServerLocation66> locations = this.bucketServerLocationsMap.get(bucketId);
List<BucketServerLocation66> locationsCopy = new ArrayList<BucketServerLocation66>(locations);
for (BucketServerLocation66 loc : locationsCopy) {
if (loc.isPrimary()) {
return loc;
}
}
}
return null;
}
use of org.apache.geode.internal.cache.BucketServerLocation66 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.internal.cache.BucketServerLocation66 in project geode by apache.
the class RetrieveRegionMetadataFunction method bucketServerMap2ServerBucketSetMap.
/** convert bucket to server map to server to bucket set map */
private HashMap<ServerLocation, HashSet<Integer>> bucketServerMap2ServerBucketSetMap(Map<Integer, List<BucketServerLocation66>> map) {
HashMap<ServerLocation, HashSet<Integer>> serverBucketMap = new HashMap<>();
for (Integer id : map.keySet()) {
List<BucketServerLocation66> locations = map.get(id);
for (BucketServerLocation66 location : locations) {
ServerLocation server = new ServerLocation(location.getHostName(), location.getPort());
if (location.isPrimary()) {
HashSet<Integer> set = serverBucketMap.get(server);
if (set == null) {
set = new HashSet<>();
serverBucketMap.put(server, set);
}
set.add(id);
break;
}
}
}
return serverBucketMap;
}
Aggregations