Search in sources :

Example 6 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)

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