use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method createColoPR.
public void createColoPR() {
PartitionResolver testKeyBasedResolver = new QueryAPITestPartitionResolver();
cache = CacheFactory.getAnyInstance();
cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).create()).create(PartitionedRegionName1);
cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).setColocatedWith(PartitionedRegionName1).create()).create(PartitionedRegionName2);
cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).setColocatedWith(PartitionedRegionName2).create()).create(PartitionedRegionName3);
cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).create()).create(// not collocated
PartitionedRegionName4);
cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numOfBuckets).setPartitionResolver(testKeyBasedResolver).setColocatedWith(PartitionedRegionName4).create()).create(// collocated with 4
PartitionedRegionName5);
}
use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class ClientMetadataService method getResolver.
private PartitionResolver getResolver(Region r, Object key, Object callbackArgument) {
// First choice is one associated with the region
final String regionFullPath = r.getFullPath();
ClientPartitionAdvisor advisor = this.getClientPartitionAdvisor(regionFullPath);
PartitionResolver result = null;
if (advisor != null) {
result = advisor.getPartitionResolver();
}
if (result != null) {
return result;
}
// Second is the key
if (key != null && key instanceof PartitionResolver) {
return (PartitionResolver) key;
}
// Third is the callback argument
if (callbackArgument != null && callbackArgument instanceof PartitionResolver) {
return (PartitionResolver) callbackArgument;
}
// There is no resolver.
return null;
}
use of org.apache.geode.cache.PartitionResolver in project geode by apache.
the class ClientMetadataService method extractBucketID.
private int extractBucketID(Region region, ClientPartitionAdvisor prAdvisor, int totalNumberOfBuckets, Object key) {
int bucketId = -1;
final PartitionResolver resolver = getResolver(region, key, null);
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.FUNCTION_EXECUTION, key, null, null);
resolveKey = resolver.getRoutingObject(entryOp);
if (resolveKey == null) {
throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_THE_ROUTINGOBJECT_RETURNED_BY_PARTITIONRESOLVER_IS_NULL.toLocalizedString());
}
}
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);
// Do proactive scheduling of metadata fetch
if (bucketId == -1) {
scheduleGetPRMetaData((LocalRegion) region, true);
}
}
} else {
bucketId = PartitionedRegionHelper.getHashKey(resolveKey, totalNumberOfBuckets);
}
return bucketId;
}
use of org.apache.geode.cache.PartitionResolver 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.cache.PartitionResolver in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for a <code>PartitionAttributes</code>
*/
private void generate(PartitionAttributes pa) throws SAXException {
AttributesImpl atts = new AttributesImpl();
if (generateDefaults() || pa.getRedundantCopies() != 0)
atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies()));
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault())
atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory()));
if (generateDefaults() || pa.getTotalMaxMemory() != PartitionAttributesFactory.GLOBAL_MAX_MEMORY_DEFAULT)
atts.addAttribute("", "", TOTAL_MAX_MEMORY, "", String.valueOf(pa.getTotalMaxMemory()));
if (generateDefaults() || pa.getTotalNumBuckets() != PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT)
atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
if (pa.getColocatedWith() != null)
atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith());
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay()));
if (generateDefaults() || pa.getStartupRecoveryDelay() != PartitionAttributesFactory.STARTUP_RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", STARTUP_RECOVERY_DELAY, "", String.valueOf(pa.getStartupRecoveryDelay()));
}
if (!generateDefaults() && atts.getLength() == 0 && pa.getPartitionResolver() == null && pa.getPartitionListeners().length == 0 && (pa.getFixedPartitionAttributes() == null || pa.getFixedPartitionAttributes().isEmpty())) {
return;
}
handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts);
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
PartitionResolver rr = pa.getPartitionResolver();
if (rr != null) {
generate(PARTITION_RESOLVER, rr);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) {
PartitionListener[] listeners = pa.getPartitionListeners();
for (int i = 0; i < listeners.length; i++) {
PartitionListener listener = listeners[i];
if (listener != null) {
generate(PARTITION_LISTENER, listener);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes();
if (staticAttrs != null) {
generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) {
Properties p = pa.getLocalProperties();
generate(p, LOCAL_PROPERTIES);
p = pa.getGlobalProperties();
generate(p, GLOBAL_PROPERTIES);
}
handler.endElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES);
}
Aggregations