Search in sources :

Example 1 with VMVersionTag

use of org.apache.geode.internal.cache.versions.VMVersionTag in project geode by apache.

the class RRSynchronizationDUnitTest method createEntry2.

private boolean createEntry2(VM vm, final InternalDistributedMember forMember, final VersionSource memberVersionID) {
    return (Boolean) vm.invoke(new SerializableCallable("create entry2") {

        public Object call() {
            // create a fake event that looks like it came from the lost member and apply it to
            // this cache
            DistributedRegion dr = (DistributedRegion) TestRegion;
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(memberVersionID);
            tag.setRegionVersion(2);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "Object3", true, forMember, true, false);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            event.setNewValue(new VMCachedDeserializable("value3", 12));
            event.setVersionTag(tag);
            dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            // now create a tombstone so we can be sure these are transferred in delta-GII
            tag = new VMVersionTag();
            tag.setMemberID(memberVersionID);
            tag.setRegionVersion(3);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            event = EntryEventImpl.create(dr, Operation.CREATE, "Object5", true, forMember, true, false);
            event.setNewValue(Token.TOMBSTONE);
            event.setVersionTag(tag);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            dr.dumpBackingMap();
            LogWriterUtils.getLogWriter().info("version vector is now " + dr.getVersionVector().fullToString());
            assertTrue("should hold entry Object3 now", dr.containsKey("Object3"));
            return true;
        }
    });
}
Also used : VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag)

Example 2 with VMVersionTag

use of org.apache.geode.internal.cache.versions.VMVersionTag in project geode by apache.

the class ClientsWithVersioningRetryDUnitTest method testRetryPut.

/**
   * Test that we can successfully retry a distributed put all and get the version information.
   * second failure in bug 44951
   */
@Test
public void testRetryPut() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    createServerRegion(vm0, RegionShortcut.REPLICATE);
    createServerRegion(vm1, RegionShortcut.REPLICATE);
    // create an event tag in vm0 and then replay that event in vm1
    final DistributedMember memberID = (DistributedMember) vm0.invoke(new SerializableCallable("get id") {

        public Object call() {
            return ((DistributedRegion) getCache().getRegion("region")).getDistributionManager().getDistributionManagerId();
        }
    });
    vm0.invoke(new SerializableCallable("create entry with fake event ID") {

        @Override
        public Object call() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(dr.getVersionMember());
            tag.setRegionVersion(123);
            tag.setEntryVersion(9);
            tag.setVersionTimeStamp(System.currentTimeMillis());
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setVersionTag(tag);
            event.setContext(new ClientProxyMembershipID(memberID));
            dr.recordEvent(event);
            event.release();
            return memberID;
        }
    });
    vm1.invoke(new SerializableRunnable("recover event tag in vm1 from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            try {
                event.setContext(new ClientProxyMembershipID(memberID));
                boolean recovered = ((BaseCommand) Put70.getCommand()).recoverVersionTagForRetriedOperation(event);
                assertTrue("Expected to recover the version for this event ID", recovered);
                assertEquals("Expected the region version to be 123", 123, event.getVersionTag().getRegionVersion());
            } finally {
                event.release();
            }
        }
    });
    // bug #48205 - a retried op in PR nodes not owning the primary bucket
    // may already have a version assigned to it in another backup bucket
    vm1.invoke(new SerializableRunnable("recover posdup event tag in vm1 event tracker from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setPossibleDuplicate(true);
            try {
                dr.hasSeenEvent(event);
                assertTrue("Expected to recover the version for the event ID", event.getVersionTag() != null);
            } finally {
                event.release();
            }
        }
    });
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedMember(org.apache.geode.distributed.DistributedMember) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 3 with VMVersionTag

use of org.apache.geode.internal.cache.versions.VMVersionTag in project geode by apache.

the class DistributedAckRegionCCEDUnitTest method testEntryVersionRollover.

@Test
public void testEntryVersionRollover() throws Exception {
    assumeTrue(getClass() == DistributedAckRegionCCEDUnitTest.class);
    final String name = this.getUniqueName() + "-CC";
    final int numEntries = 1;
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
                for (int i = 0; i < numEntries; i++) {
                    CCRegion.put("cckey" + i, "ccvalue");
                }
                assertEquals("expected no conflated events", 0, CCRegion.getCachePerfStats().getConflatedEventsCount());
            } catch (CacheException ex) {
                org.apache.geode.test.dunit.Assert.fail("While creating region", ex);
            }
        }
    };
    VM vm0 = Host.getHost(0).getVM(0);
    vm0.invoke(createRegion);
    try {
        createRegion.run();
        VersionTag tag = new VMVersionTag();
        // set the version to the max - it should make the system think there's a rollover and reject
        // the change. Then apply it to the cache as if it is a replayed client operation. That should
        // cause the cache to apply the op locally
        tag.setEntryVersion(0xFFFFFF);
        tag.setDistributedSystemId(1);
        tag.setRegionVersion(CCRegion.getVersionVector().getNextVersion());
        VersionTagHolder holder = new VersionTagHolder(tag);
        ClientProxyMembershipID id = ClientProxyMembershipID.getNewProxyMembership(CCRegion.getDistributionManager().getSystem());
        CCRegion.basicBridgePut("cckey0", "newvalue", null, true, null, id, true, holder);
        vm0.invoke(new SerializableRunnable("check conflation count") {

            public void run() {
                assertEquals("expected one conflated event", 1, CCRegion.getCachePerfStats().getConflatedEventsCount());
            }
        });
    } finally {
        disconnectAllFromDS();
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) RegionFactory(org.apache.geode.cache.RegionFactory) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with VMVersionTag

use of org.apache.geode.internal.cache.versions.VMVersionTag in project geode by apache.

the class PRBucketSynchronizationDUnitTest method createEntry2.

private boolean createEntry2(VM vm, final InternalDistributedMember primary, final VersionSource primaryVersionID) {
    return (Boolean) vm.invoke(new SerializableCallable("create entry2") {

        public Object call() {
            // create a fake event that looks like it came from the primary and apply it to
            // this cache
            PartitionedRegion pr = (PartitionedRegion) TestRegion;
            BucketRegion bucket = pr.getDataStore().getLocalBucketById(0);
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(primaryVersionID);
            tag.setRegionVersion(2);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = EntryEventImpl.create(bucket, Operation.CREATE, "Object3", true, primary, true, false);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            event.setNewValue(new VMCachedDeserializable("value3", 12));
            event.setVersionTag(tag);
            bucket.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            // now create a tombstone so we can be sure these are transferred in delta-GII
            tag = new VMVersionTag();
            tag.setMemberID(primaryVersionID);
            tag.setRegionVersion(3);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            event = EntryEventImpl.create(bucket, Operation.CREATE, "Object5", true, primary, true, false);
            event.setNewValue(Token.TOMBSTONE);
            event.setVersionTag(tag);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            bucket.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            bucket.dumpBackingMap();
            LogWriterUtils.getLogWriter().info("bucket version vector is now " + bucket.getVersionVector().fullToString());
            assertTrue("bucket should hold entry Object3 now", bucket.containsKey("Object3"));
            return true;
        }
    });
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VMCachedDeserializable(org.apache.geode.internal.cache.VMCachedDeserializable)

Aggregations

VMVersionTag (org.apache.geode.internal.cache.versions.VMVersionTag)4 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)2 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 CacheException (org.apache.geode.cache.CacheException)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 EventID (org.apache.geode.internal.cache.EventID)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 VMCachedDeserializable (org.apache.geode.internal.cache.VMCachedDeserializable)1 VersionTagHolder (org.apache.geode.internal.cache.VersionTagHolder)1 Host (org.apache.geode.test.dunit.Host)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1