Search in sources :

Example 21 with VersionTag

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

the class DistributedRegionSearchLoadJUnitTest method testClientEventIsUpdatedWithCurrentEntryVersionTagAfterSearchConcurrencyException.

@Test
public void testClientEventIsUpdatedWithCurrentEntryVersionTagAfterSearchConcurrencyException() {
    DistributedRegion region = prepare(true);
    EntryEventImpl event = createDummyEvent(region);
    region.basicInvalidate(event);
    VersionTag tag = createVersionTag(true);
    RegionEntry re = mock(RegionEntry.class);
    VersionStamp stamp = mock(VersionStamp.class);
    doReturn(re).when(region).getRegionEntry(any());
    when(re.getVersionStamp()).thenReturn(stamp);
    when(stamp.asVersionTag()).thenReturn(tag);
    createSearchLoad();
    doThrow(new ConcurrentCacheModificationException()).when(region).basicPutEntry(any(EntryEventImpl.class), anyLong());
    KeyInfo ki = new KeyInfo(event.getKey(), null, null);
    region.findObjectInSystem(ki, false, null, false, null, false, false, null, event, false);
    assertNotNull("ClientEvent version tag is not set with region version tag.", event.getVersionTag());
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag 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 23 with VersionTag

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

the class MultiVMRegionTestCase method versionTestConcurrentEvents.

/**
   * This tests the concurrency versioning system to ensure that event conflation happens correctly
   * and that the statistic is being updated properly
   */
public void versionTestConcurrentEvents() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // create replicated regions in VM 0 and 1, then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final String name = this.getUniqueName() + "-CC";
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        @Override
        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
            } catch (CacheException ex) {
                fail("While creating region", ex);
            }
        }
    };
    vm0.invoke(createRegion);
    vm1.invoke(createRegion);
    SerializableRunnable performOps = new SerializableRunnable("perform concurrent ops") {

        @Override
        public void run() {
            try {
                doOpsLoop(5000, false);
                long events = CCRegion.getCachePerfStats().getConflatedEventsCount();
                if (!CCRegion.getScope().isGlobal()) {
                    assertTrue("expected some event conflation", events > 0);
                }
            } catch (CacheException e) {
                fail("while performing concurrent operations", e);
            }
        // } catch (InterruptedException e) {
        // fail("someone interrupted my sleep");
        // }
        }
    };
    AsyncInvocation a0 = vm0.invokeAsync(performOps);
    AsyncInvocation a1 = vm1.invokeAsync(performOps);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        fail("sleep was interrupted");
    }
    vm2.invoke(createRegion);
    boolean a0failed = waitForAsyncProcessing(a0, "expected some event conflation");
    boolean a1failed = waitForAsyncProcessing(a1, "expected some event conflation");
    if (a0failed && a1failed) {
        fail("neither member saw event conflation - check stats for " + name);
    }
    // check consistency of the regions
    Map r0Contents = (Map) vm0.invoke(() -> this.getCCRegionContents());
    Map r1Contents = (Map) vm1.invoke(() -> this.getCCRegionContents());
    Map r2Contents = (Map) vm2.invoke(() -> this.getCCRegionContents());
    for (int i = 0; i < 10; i++) {
        String key = "cckey" + i;
        assertEquals("region contents are not consistent for " + key, r0Contents.get(key), r1Contents.get(key));
        assertEquals("region contents are not consistent for " + key, r1Contents.get(key), r2Contents.get(key));
        for (int subi = 1; subi < 3; subi++) {
            String subkey = key + "-" + subi;
            if (r0Contents.containsKey(subkey)) {
                assertEquals("region contents are not consistent for " + subkey, r0Contents.get(subkey), r1Contents.get(subkey));
                assertEquals("region contents are not consistent for " + subkey, r1Contents.get(subkey), r2Contents.get(subkey));
            } else {
                assertTrue(!r1Contents.containsKey(subkey));
            }
        }
    }
    if (!getRegionAttributes().getScope().isDistributedNoAck()) {
        // no-ack doesn't support deltas
        vm0.invoke(() -> this.clearCCRegion());
        performOps = new SerializableRunnable("perform concurrent delta ops") {

            @Override
            public void run() {
                try {
                    long stopTime = System.currentTimeMillis() + 5000;
                    Random ran = new Random(System.currentTimeMillis());
                    while (System.currentTimeMillis() < stopTime) {
                        for (int i = 0; i < 10; i++) {
                            CCRegion.put("cckey" + i, new DeltaValue("ccvalue" + ran.nextInt()));
                        }
                    }
                    long events = CCRegion.getCachePerfStats().getDeltaFailedUpdates();
                    assertTrue("expected some failed deltas", events > 0);
                } catch (CacheException e) {
                    fail("while performing concurrent operations", e);
                }
            }
        };
        a0 = vm0.invokeAsync(performOps);
        a1 = vm1.invokeAsync(performOps);
        a0failed = waitForAsyncProcessing(a0, "expected some failed deltas");
        a1failed = waitForAsyncProcessing(a1, "expected some failed deltas");
        if (a0failed && a1failed) {
            fail("neither member saw failed deltas - check stats for " + name);
        }
        // check consistency of the regions
        r0Contents = (Map) vm0.invoke(() -> this.getCCRegionContents());
        r1Contents = (Map) vm1.invoke(() -> this.getCCRegionContents());
        r2Contents = (Map) vm2.invoke(() -> this.getCCRegionContents());
        for (int i = 0; i < 10; i++) {
            String key = "cckey" + i;
            assertEquals("region contents are not consistent", r0Contents.get(key), r1Contents.get(key));
            assertEquals("region contents are not consistent", r1Contents.get(key), r2Contents.get(key));
            for (int subi = 1; subi < 3; subi++) {
                String subkey = key + "-" + subi;
                if (r0Contents.containsKey(subkey)) {
                    assertEquals("region contents are not consistent", r0Contents.get(subkey), r1Contents.get(subkey));
                    assertEquals("region contents are not consistent", r1Contents.get(subkey), r2Contents.get(subkey));
                } else {
                    assertTrue(!r1Contents.containsKey(subkey));
                }
            }
        }
        // The region version vectors should now all be consistent with the version stamps in the
        // entries.
        InternalDistributedMember vm0Id = (InternalDistributedMember) vm0.invoke(() -> this.getMemberId());
        InternalDistributedMember vm1Id = (InternalDistributedMember) vm1.invoke(() -> this.getMemberId());
        InternalDistributedMember vm2Id = (InternalDistributedMember) vm2.invoke(() -> this.getMemberId());
        long start = System.currentTimeMillis();
        RegionVersionVector vm0vv = getVersionVector(vm0);
        long end = System.currentTimeMillis();
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("version vector transmission took " + (end - start) + " ms");
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm0 vector = " + vm0vv);
        RegionVersionVector vm1vv = getVersionVector(vm1);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm1 vector = " + vm1vv);
        RegionVersionVector vm2vv = getVersionVector(vm2);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm2 vector = " + vm2vv);
        Map<String, VersionTag> vm0Versions = (Map<String, VersionTag>) vm0.invoke(() -> this.getCCRegionVersions());
        Map<String, VersionTag> vm1Versions = (Map<String, VersionTag>) vm1.invoke(() -> this.getCCRegionVersions());
        Map<String, VersionTag> vm2Versions = (Map<String, VersionTag>) vm2.invoke(() -> this.getCCRegionVersions());
        for (Map.Entry<String, VersionTag> entry : vm0Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm0Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
        for (Map.Entry<String, VersionTag> entry : vm1Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm1Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
        for (Map.Entry<String, VersionTag> entry : vm2Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm2Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RegionFactory(org.apache.geode.cache.RegionFactory) Random(java.util.Random) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with VersionTag

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

the class AbstractDistributedRegionJUnitTest method testConcurrencyTrueTagValid.

@Test
public void testConcurrencyTrueTagValid() {
    // case 4: concurrencyCheckEanbled = true, version tag is valid: distribute
    DistributedRegion region = prepare(true, false);
    EntryEventImpl event = createDummyEvent(region);
    VersionTag tag = createVersionTag(true);
    event.setVersionTag(tag);
    assertTrue(tag.hasValidVersion());
    doTest(region, event, 1);
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test)

Example 25 with VersionTag

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

the class AbstractDistributedRegionJUnitTest method testConcurrencyTrueTagInvalid.

@Test
public void testConcurrencyTrueTagInvalid() {
    // case 3: concurrencyCheckEanbled = true, version tag is invalid: not to distribute
    DistributedRegion region = prepare(true, false);
    EntryEventImpl event = createDummyEvent(region);
    VersionTag tag = createVersionTag(false);
    event.setVersionTag(tag);
    assertFalse(tag.hasValidVersion());
    doTest(region, event, 0);
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test)

Aggregations

VersionTag (org.apache.geode.internal.cache.versions.VersionTag)225 Test (org.junit.Test)43 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 VM (org.apache.geode.test.dunit.VM)24 CacheException (org.apache.geode.cache.CacheException)22 LocalRegion (org.apache.geode.internal.cache.LocalRegion)22 Region (org.apache.geode.cache.Region)21 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)19 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)19 Host (org.apache.geode.test.dunit.Host)19 IOException (java.io.IOException)17 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)16 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)16 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)16 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)15 ArrayList (java.util.ArrayList)14 CancelException (org.apache.geode.CancelException)14