Search in sources :

Example 1 with EntryOperationImpl

use of org.apache.geode.internal.cache.EntryOperationImpl 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 EntryOperationImpl

use of org.apache.geode.internal.cache.EntryOperationImpl 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 3 with EntryOperationImpl

use of org.apache.geode.internal.cache.EntryOperationImpl 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 4 with EntryOperationImpl

use of org.apache.geode.internal.cache.EntryOperationImpl in project geode by apache.

the class SerializableMonth method partitionedRegionTest.

public void partitionedRegionTest(final String prName) {
    /*
     * Do put() operations through VM with PR having both Accessor and Datastore
     */
    vm0.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations1") {

        public void run2() throws CacheException {
            Calendar cal = Calendar.getInstance();
            final Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            int size = 0;
            size = pr.size();
            assertEquals("Size doesnt return expected value", 0, size);
            assertEquals("isEmpty doesnt return proper state of the PartitionedRegion", true, pr.isEmpty());
            assertEquals(0, pr.keySet().size());
            for (int i = 0; i <= 11; i++) {
                int yr = (new Integer((int) (Math.random() * 2100))).intValue();
                int month = i;
                int date = (new Integer((int) (Math.random() * 30))).intValue();
                cal.set(yr, month, date);
                Object key = cal.getTime();
                listOfKeys1.add(key);
                assertNotNull(pr);
                pr.put(key, Integer.toString(i));
                assertEquals(Integer.toString(i), pr.get(key));
            }
            PartitionedRegion ppr = (PartitionedRegion) pr;
            try {
                ppr.dumpAllBuckets(false);
            } catch (ReplyException re) {
                Assert.fail("dumpAllBuckets", re);
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations2") {

        public void run2() throws CacheException {
            Calendar cal = Calendar.getInstance();
            final Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            for (int i = 0; i <= 11; i++) {
                int yr = (new Integer((int) (Math.random() * 2200))).intValue();
                int month = i;
                int date = (new Integer((int) (Math.random() * 30))).intValue();
                cal.set(yr, month, date);
                Object key = cal.getTime();
                listOfKeys2.add(key);
                assertNotNull(pr);
                pr.put(key, Integer.toString(i));
                assertEquals(Integer.toString(i), pr.get(key));
            }
            PartitionedRegion ppr = (PartitionedRegion) pr;
            try {
                ppr.dumpAllBuckets(false);
            } catch (ReplyException re) {
                Assert.fail("dumpAllBuckets", re);
            }
        }
    });
    vm2.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations2") {

        public void run2() throws CacheException {
            Calendar cal = Calendar.getInstance();
            final Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            for (int i = 0; i <= 11; i++) {
                int yr = (new Integer((int) (Math.random() * 2300))).intValue();
                int month = i;
                int date = (new Integer((int) (Math.random() * 30))).intValue();
                cal.set(yr, month, date);
                Object key = cal.getTime();
                listOfKeys3.add(key);
                assertNotNull(pr);
                pr.put(key, Integer.toString(i));
                assertEquals(Integer.toString(i), pr.get(key));
            }
            PartitionedRegion ppr = (PartitionedRegion) pr;
            try {
                ppr.dumpAllBuckets(false);
            } catch (ReplyException re) {
                Assert.fail("dumpAllBuckets", re);
            }
        }
    });
    vm3.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations3") {

        public void run2() throws CacheException {
            Calendar cal = Calendar.getInstance();
            final Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            for (int i = 0; i <= 11; i++) {
                int yr = (new Integer((int) (Math.random() * 2400))).intValue();
                int month = i;
                int date = (new Integer((int) (Math.random() * 30))).intValue();
                cal.set(yr, month, date);
                Object key = cal.getTime();
                listOfKeys4.add(key);
                assertNotNull(pr);
                pr.put(key, Integer.toString(i));
                assertEquals(Integer.toString(i), pr.get(key));
            }
            PartitionedRegion ppr = (PartitionedRegion) pr;
            try {
                ppr.dumpAllBuckets(false);
            } catch (ReplyException re) {
                Assert.fail("dumpAllBuckets", re);
            }
        }
    });
    vm0.invoke(new CacheSerializableRunnable("verifyKeysonVM0") {

        public void run2() throws CacheException {
            // Calendar cal = Calendar.getInstance();
            final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            Iterator itr = listOfKeys1.iterator();
            while (itr.hasNext()) {
                assertTrue(searchForKey(pr, (Date) itr.next()));
            }
            pr.getDataStore().visitBuckets(new BucketVisitor() {

                public void visit(Integer bucketId, Region r) {
                    Set s = pr.getBucketKeys(bucketId.intValue());
                    Iterator it = s.iterator();
                    while (it.hasNext()) {
                        EntryOperation eo = new EntryOperationImpl(pr, null, it.next(), null, null);
                        PartitionResolver rr = pr.getPartitionResolver();
                        Object o = rr.getRoutingObject(eo);
                        Integer i = new Integer(o.hashCode() % totalNumBuckets);
                        assertEquals(bucketId, i);
                    }
                // getLogWriter().severe("Key " + key + " found in bucket " + b);
                }
            });
        }
    });
    vm1.invoke(new CacheSerializableRunnable("verifyKeysonVM1") {

        public void run2() throws CacheException {
            // Calendar cal = Calendar.getInstance();
            final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            Iterator itr = listOfKeys2.iterator();
            while (itr.hasNext()) {
                assertTrue(searchForKey(pr, (Date) itr.next()));
            }
            pr.getDataStore().visitBuckets(new BucketVisitor() {

                public void visit(Integer bucketId, Region r) {
                    Set s = pr.getBucketKeys(bucketId.intValue());
                    Iterator it = s.iterator();
                    while (it.hasNext()) {
                        EntryOperation eo = new EntryOperationImpl(pr, null, it.next(), null, null);
                        PartitionResolver rr = pr.getPartitionResolver();
                        Object o = rr.getRoutingObject(eo);
                        Integer i = new Integer(o.hashCode() % totalNumBuckets);
                        assertEquals(bucketId, i);
                    }
                // getLogWriter().severe("Key " + key + " found in bucket " + b);
                }
            });
        }
    });
    vm2.invoke(new CacheSerializableRunnable("verifyKeysonVM2") {

        public void run2() throws CacheException {
            // Calendar cal = Calendar.getInstance();
            final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            Iterator itr = listOfKeys3.iterator();
            itr = listOfKeys3.iterator();
            while (itr.hasNext()) {
                assertTrue(searchForKey(pr, (Date) itr.next()));
            }
            pr.getDataStore().visitBuckets(new BucketVisitor() {

                public void visit(Integer bucketId, Region r) {
                    Set s = pr.getBucketKeys(bucketId.intValue());
                    Iterator it = s.iterator();
                    while (it.hasNext()) {
                        EntryOperation eo = new EntryOperationImpl(pr, null, it.next(), null, null);
                        PartitionResolver rr = pr.getPartitionResolver();
                        Object o = rr.getRoutingObject(eo);
                        Integer i = new Integer(o.hashCode() % totalNumBuckets);
                        // assertIndexDetailsEquals(bucketId, bucketId);
                        assertEquals(bucketId, i);
                    }
                // getLogWriter().severe("Key " + key + " found in bucket " + b);
                }
            });
        }
    });
    vm3.invoke(new CacheSerializableRunnable("verifyKeysonVM3") {

        public void run2() throws CacheException {
            // Calendar cal = Calendar.getInstance();
            final PartitionedRegion pr = (PartitionedRegion) cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            Iterator itr = listOfKeys4.iterator();
            itr = listOfKeys4.iterator();
            while (itr.hasNext()) {
                assertTrue(searchForKey(pr, (Date) itr.next()));
            }
            assertEquals(pr.getDataStore(), null);
        }
    });
}
Also used : BucketVisitor(org.apache.geode.internal.cache.PartitionedRegionDataStore.BucketVisitor) ReplyException(org.apache.geode.distributed.internal.ReplyException) EntryOperationImpl(org.apache.geode.internal.cache.EntryOperationImpl) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

EntryOperationImpl (org.apache.geode.internal.cache.EntryOperationImpl)4 EntryOperation (org.apache.geode.cache.EntryOperation)3 FixedPartitionResolver (org.apache.geode.cache.FixedPartitionResolver)3 PartitionResolver (org.apache.geode.cache.PartitionResolver)3 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 ReplyException (org.apache.geode.distributed.internal.ReplyException)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 BucketServerLocation66 (org.apache.geode.internal.cache.BucketServerLocation66)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 BucketVisitor (org.apache.geode.internal.cache.PartitionedRegionDataStore.BucketVisitor)1