use of org.apache.geode.cache.EntryOperation 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.EntryOperation in project geode by apache.
the class ParallelAsyncEventQueueImpl method setModifiedEventId.
@Override
protected void setModifiedEventId(EntryEventImpl clonedEvent) {
int bucketId = -1;
// merged from 42004
if (clonedEvent.getRegion() instanceof DistributedRegion) {
bucketId = PartitionedRegionHelper.getHashKey(clonedEvent.getKey(), getMaxParallelismForReplicatedRegion());
} else {
bucketId = PartitionedRegionHelper.getHashKey((EntryOperation) clonedEvent);
}
EventID originalEventId = clonedEvent.getEventId();
long originatingThreadId = ThreadIdentifier.getRealThreadID(originalEventId.getThreadID());
long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGSPrimaryBucket(bucketId, originatingThreadId, getEventIdIndex());
// In case of parallel as all events go through primary buckets
// we don't need to generate different threadId for secondary buckets
// as they will be rejected if seen at PR level itself
EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID(), bucketId);
if (logger.isDebugEnabled()) {
logger.debug("{}: Generated event id for event with key={}, bucketId={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, clonedEvent.getKey(), bucketId, originalEventId, originatingThreadId, newEventId, newThreadId);
}
clonedEvent.setEventId(newEventId);
}
use of org.apache.geode.cache.EntryOperation 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.EntryOperation 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.EntryOperation in project geode by apache.
the class PartitionAttributesImplJUnitTest method before.
@Before
public void before() {
this.colocatedRegionFullPath = "colocatedRegionFullPath";
this.globalProps = new Properties();
this.globalProps_key1 = "globalProps_key1";
this.globalProps_value1 = "globalProps_value1";
this.globalProps.setProperty(globalProps_key1, this.globalProps_value1);
this.localProps = new Properties();
this.localProps_key1 = "localProps_key1";
this.localProps_value1 = "localProps_value1";
this.localProps.setProperty(localProps_key1, this.localProps_value1);
this.localMaxMemory = 123;
this.offHeap = false;
this.partitionResolver = new PartitionResolver<Object, Object>() {
@Override
public void close() {
}
@Override
public Object getRoutingObject(EntryOperation opDetails) {
return "partitionResolver_getRoutingObject";
}
@Override
public String getName() {
return "partitionResolver_getName";
}
};
this.recoveryDelay = 234;
this.redundancy = 345;
this.startupRecoveryDelay = 456;
this.totalMaxMemory = 567;
this.maxNumberOfBuckets = 678;
this.newTestAvailableOffHeapMemory = 789;
this.greaterLocalMaxMemory = 890;
this.partitionListener = new PartitionListener() {
@Override
public void afterPrimary(int bucketId) {
}
@Override
public void afterRegionCreate(Region<?, ?> region) {
}
@Override
public void afterBucketRemoved(int bucketId, Iterable<?> keys) {
}
@Override
public void afterBucketCreated(int bucketId, Iterable<?> keys) {
}
};
}
Aggregations