use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class QueryDataInconsistencyDUnitTest method createPR.
public void createPR() {
PartitionResolver testKeyBasedResolver = new QueryAPITestPartitionResolver();
cache = CacheFactory.getAnyInstance();
cache.createRegionFactory(RegionShortcut.PARTITION_REDUNDANT).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).create()).create(PartitionedRegionName1);
}
use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class GetClientPartitionAttributesCommand method cmdExecute.
@SuppressWarnings("unchecked")
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);
PartitionedRegion prRgion = (PartitionedRegion) region;
PartitionResolver partitionResolver = prRgion.getPartitionResolver();
// MINUMUM PARTS
int numParts = 2;
if (partitionResolver != null) {
numParts++;
}
responseMsg.setNumberOfParts(numParts);
// PART 1
responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());
// PART 2
if (partitionResolver != null) {
responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
}
// PART 3
String leaderRegionPath = null;
PartitionedRegion leaderRegion = null;
String leaderRegionName = prRgion.getColocatedWith();
if (leaderRegionName != null) {
Cache cache = prRgion.getCache();
while (leaderRegionName != null) {
leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
if (leaderRegion.getColocatedWith() == null) {
leaderRegionPath = leaderRegion.getFullPath();
break;
} else {
leaderRegionName = leaderRegion.getColocatedWith();
}
}
}
responseMsg.addObjPart(leaderRegionPath);
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class GetClientPartitionAttributesCommand66 method cmdExecute.
@SuppressWarnings("unchecked")
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);
if (!(region instanceof PartitionedRegion)) {
responseMsg.setNumberOfParts(2);
responseMsg.addObjPart(-1);
responseMsg.addObjPart(region.getFullPath());
} else {
PartitionedRegion prRgion = (PartitionedRegion) region;
PartitionResolver partitionResolver = prRgion.getPartitionResolver();
// MINUMUM PARTS
int numParts = 2;
if (partitionResolver != null) {
numParts++;
}
if (prRgion.isFixedPartitionedRegion()) {
numParts++;
}
responseMsg.setNumberOfParts(numParts);
// PART 1
responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());
// PART 2
String leaderRegionPath = null;
PartitionedRegion leaderRegion = null;
String leaderRegionName = prRgion.getColocatedWith();
if (leaderRegionName != null) {
Cache cache = prRgion.getCache();
while (leaderRegionName != null) {
leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
if (leaderRegion.getColocatedWith() == null) {
leaderRegionPath = leaderRegion.getFullPath();
break;
} else {
leaderRegionName = leaderRegion.getColocatedWith();
}
}
}
responseMsg.addObjPart(leaderRegionPath);
// PART 3
if (partitionResolver != null) {
responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
}
// PART 4
if (prRgion.isFixedPartitionedRegion()) {
Set<FixedPartitionAttributes> fpaSet = null;
if (leaderRegion != null) {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(leaderRegion);
} else {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(prRgion);
}
responseMsg.addObjPart(fpaSet);
}
}
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
use of org.apache.geode.cache.PartitionResolver 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.cache.PartitionResolver in project geode by apache.
the class CacheXmlParser method endPartitionResolver.
/**
* When a <code>partition-resolver</code> element is finished, the {@link Parameter}s and class
* names are popped off the stack. The <code>PartitionResolver</code> is instantiated and
* initialized with the parameters, if appropriate.
*/
private void endPartitionResolver() {
Declarable d = createDeclarable();
if (!(d instanceof PartitionResolver)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_1.toLocalizedString(new Object[] { d.getClass().getName(), "PartitionResolver" }));
}
PartitionAttributesImpl pai = peekPartitionAttributesImpl(PARTITION_ATTRIBUTES);
pai.setPartitionResolver((PartitionResolver) d);
}
Aggregations