Search in sources :

Example 1 with EntryOperation

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();
}
Also used : EntryOperationImpl(org.apache.geode.internal.cache.EntryOperationImpl) BucketServerLocation66(org.apache.geode.internal.cache.BucketServerLocation66) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionResolver(org.apache.geode.cache.PartitionResolver) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) EntryOperation(org.apache.geode.cache.EntryOperation)

Example 2 with EntryOperation

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);
}
Also used : EventID(org.apache.geode.internal.cache.EventID) EntryOperation(org.apache.geode.cache.EntryOperation) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 3 with EntryOperation

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;
}
Also used : EntryOperationImpl(org.apache.geode.internal.cache.EntryOperationImpl) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionResolver(org.apache.geode.cache.PartitionResolver) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) EntryOperation(org.apache.geode.cache.EntryOperation)

Example 4 with EntryOperation

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;
}
Also used : EntryOperationImpl(org.apache.geode.internal.cache.EntryOperationImpl) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionResolver(org.apache.geode.cache.PartitionResolver) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) EntryOperation(org.apache.geode.cache.EntryOperation)

Example 5 with EntryOperation

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) {
        }
    };
}
Also used : PartitionListener(org.apache.geode.cache.partition.PartitionListener) EntryOperation(org.apache.geode.cache.EntryOperation) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

EntryOperation (org.apache.geode.cache.EntryOperation)6 FixedPartitionResolver (org.apache.geode.cache.FixedPartitionResolver)3 PartitionResolver (org.apache.geode.cache.PartitionResolver)3 EntryOperationImpl (org.apache.geode.internal.cache.EntryOperationImpl)3 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)2 EventID (org.apache.geode.internal.cache.EventID)2 Properties (java.util.Properties)1 PartitionListener (org.apache.geode.cache.partition.PartitionListener)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 BucketServerLocation66 (org.apache.geode.internal.cache.BucketServerLocation66)1 Before (org.junit.Before)1