use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class SerializationHelper method readBucketServerLocationSet.
public static HashSet<BucketServerLocation66> readBucketServerLocationSet(DataInput in) throws IOException, ClassNotFoundException {
int size = in.readInt();
if (size < 0) {
return null;
}
HashSet bucketServerLocations = new HashSet(size);
for (int i = 0; i < size; i++) {
BucketServerLocation66 next = new BucketServerLocation66();
InternalDataSerializer.invokeFromData(next, in);
bucketServerLocations.add(next);
}
return bucketServerLocations;
}
use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class ClientPartitionAdvisor method updateBucketServerLocations.
public void updateBucketServerLocations(int bucketId, List<BucketServerLocation66> bucketServerLocations, ClientMetadataService cms) {
List<BucketServerLocation66> locationCopy = new ArrayList<BucketServerLocation66>();
List<BucketServerLocation66> locations;
boolean honourSeverGroup = cms.honourServerGroup();
if (this.serverGroup.length() != 0 && honourSeverGroup) {
for (BucketServerLocation66 s : bucketServerLocations) {
String[] groups = s.getServerGroups();
if (groups.length > 0) {
for (String str : groups) {
if (str.equals(this.serverGroup)) {
locationCopy.add(s);
break;
}
}
} else {
locationCopy.add(s);
}
}
locations = Collections.unmodifiableList(locationCopy);
} else {
locations = Collections.unmodifiableList(bucketServerLocations);
}
this.bucketServerLocationsMap.put(bucketId, locations);
}
use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class ClientMetadataService method getMetaDataVersion.
public byte getMetaDataVersion(Region region, Operation operation, Object key, Object value, Object callbackArg) {
ClientPartitionAdvisor prAdvisor = this.getClientPartitionAdvisor(region.getFullPath());
if (prAdvisor == null) {
return 0;
}
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);
}
} else {
bucketId = PartitionedRegionHelper.getHashKey(resolveKey, totalNumberOfBuckets);
}
BucketServerLocation66 bsl = (BucketServerLocation66) getPrimaryServerLocation(region, bucketId);
if (bsl == null) {
return 0;
}
return bsl.getVersion();
}
use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class GetClientPRMetadataCommand method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
} else {
Region region = crHelper.getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
} else {
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PR_METADATA);
PartitionedRegion prRgion = (PartitionedRegion) region;
Map<Integer, List<BucketServerLocation66>> bucketToServerLocations = prRgion.getRegionAdvisor().getAllClientBucketProfiles();
responseMsg.setNumberOfParts(bucketToServerLocations.size());
for (List<BucketServerLocation66> serverLocations : bucketToServerLocations.values()) {
List<BucketServerLocation> oldServerLocations = new ArrayList<BucketServerLocation>();
for (BucketServerLocation66 bs : serverLocations) {
oldServerLocations.add(new BucketServerLocation(bs.getBucketId(), bs.getPort(), bs.getHostName(), bs.isPrimary(), bs.getVersion()));
responseMsg.addObjPart(oldServerLocations);
}
}
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
}
}
use of org.apache.geode.internal.cache.BucketServerLocation66 in project geode by apache.
the class GetClientPRMetadataCommand66 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
} else {
Region region = crHelper.getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
} else {
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PR_METADATA);
PartitionedRegion prRgion = (PartitionedRegion) region;
Map<Integer, List<BucketServerLocation66>> bucketToServerLocations = prRgion.getRegionAdvisor().getAllClientBucketProfiles();
responseMsg.setNumberOfParts(bucketToServerLocations.size());
for (List<BucketServerLocation66> serverLocations : bucketToServerLocations.values()) {
responseMsg.addObjPart(serverLocations);
}
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
}
}
Aggregations