Search in sources :

Example 1 with VersionSource

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

the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithParallelSender.

@Test
public void testUpdateVersionAfterCreateWithParallelSender() {
    Host host = Host.getHost(0);
    // server1 site1
    VM vm0 = host.getVM(0);
    // server2 site1
    VM vm1 = host.getVM(1);
    // server1 site2
    VM vm2 = host.getVM(2);
    // server2 site2
    VM vm3 = host.getVM(3);
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
    final String key = "key-1";
    vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
    vm0.invoke(() -> UpdateVersionDUnitTest.createSender("ln1", 2, true, 10, 1, false, false, null, true));
    vm0.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "ln1", 1, 1));
    vm0.invoke(() -> UpdateVersionDUnitTest.startSender("ln1"));
    vm0.invoke(() -> UpdateVersionDUnitTest.waitForSenderRunningState("ln1"));
    // Site 2
    Integer nyPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createFirstRemoteLocator(2, lnPort));
    Integer nyRecPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createReceiver(nyPort));
    vm2.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
    vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
    vm3.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
    final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Put a single entry and get its version") {

        @Override
        public Object call() throws CacheException {
            Cache cache = CacheFactory.getAnyInstance();
            Region region = cache.getRegion(regionName);
            assertTrue(region instanceof PartitionedRegion);
            region.put(key, "value-1");
            region.put(key, "value-2");
            Entry entry = region.getEntry(key);
            assertTrue(entry instanceof EntrySnapshot);
            RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            // Create a duplicate entry version tag from stamp with newer
            // time-stamp.
            VersionSource memberId = (VersionSource) cache.getDistributedSystem().getDistributedMember();
            VersionTag tag = VersionTag.create(memberId);
            int entryVersion = stamp.getEntryVersion() - 1;
            int dsid = stamp.getDistributedSystemId();
            long time = System.currentTimeMillis();
            tag.setEntryVersion(entryVersion);
            tag.setDistributedSystemId(dsid);
            tag.setVersionTimeStamp(time);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, entry.getKey(), "value-3");
            ((LocalRegion) region).basicUpdate(event, false, true, 0L, false);
            // Verify the new stamp
            entry = region.getEntry(key);
            assertTrue(entry instanceof EntrySnapshot);
            regionEntry = ((EntrySnapshot) entry).getRegionEntry();
            stamp = regionEntry.getVersionStamp();
            assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
            assertEquals(++entryVersion, stamp.getEntryVersion());
            assertEquals(dsid, stamp.getDistributedSystemId());
            return stamp.asVersionTag();
        }
    });
    VersionTag remoteTag = (VersionTag) vm3.invoke(new SerializableCallable("Get timestamp from remote site") {

        @Override
        public Object call() throws Exception {
            Cache cache = CacheFactory.getAnyInstance();
            final PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
            // wait for entry to be received
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    Entry<?, ?> entry = null;
                    try {
                        entry = region.getDataStore().getEntryLocally(0, key, false, false);
                    } catch (EntryNotFoundException e) {
                    // expected
                    } catch (ForceReattemptException e) {
                    // expected
                    } catch (PRLocallyDestroyedException e) {
                        throw new RuntimeException("unexpected exception", e);
                    }
                    if (entry != null) {
                        LogWriterUtils.getLogWriter().info("found entry " + entry);
                    }
                    return (entry != null);
                }

                public String description() {
                    return "Expected key-1 to be received on remote WAN site";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            wc = new WaitCriterion() {

                public boolean done() {
                    Entry entry = region.getEntry(key);
                    assertTrue(entry instanceof EntrySnapshot);
                    RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
                    return regionEntry.getVersionStamp().getVersionTimeStamp() == tag.getVersionTimeStamp();
                }

                public String description() {
                    return "waiting for timestamp to be updated";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            Entry entry = region.getEntry(key);
            assertTrue(entry instanceof EntrySnapshot);
            RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            return stamp.asVersionTag();
        }
    });
    assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
Also used : Host(org.apache.geode.test.dunit.Host) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) Entry(org.apache.geode.cache.Region.Entry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with VersionSource

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

the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithSerialSenderOnDR.

@Test
public void testUpdateVersionAfterCreateWithSerialSenderOnDR() {
    Host host = Host.getHost(0);
    // server1 site1
    VM vm0 = host.getVM(0);
    // server2 site1
    VM vm1 = host.getVM(1);
    // server1 site2
    VM vm2 = host.getVM(2);
    // server2 site2
    VM vm3 = host.getVM(3);
    final String key = "key-1";
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
    vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
    vm0.invoke(() -> UpdateVersionDUnitTest.createSender("ln1", 2, false, 10, 1, false, false, null, true));
    vm0.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, "ln1"));
    vm0.invoke(() -> UpdateVersionDUnitTest.startSender("ln1"));
    vm0.invoke(() -> UpdateVersionDUnitTest.waitForSenderRunningState("ln1"));
    // Site 2
    Integer nyPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createFirstRemoteLocator(2, lnPort));
    Integer nyRecPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createReceiver(nyPort));
    vm2.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
    vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
    vm3.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
    final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Update a single entry and get its version") {

        @Override
        public Object call() throws CacheException {
            Cache cache = CacheFactory.getAnyInstance();
            Region region = cache.getRegion(regionName);
            assertTrue(region instanceof DistributedRegion);
            region.put(key, "value-1");
            region.put(key, "value-2");
            Entry entry = region.getEntry(key);
            assertTrue(entry instanceof NonTXEntry);
            RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            // Create a duplicate entry version tag from stamp with newer
            // time-stamp.
            VersionSource memberId = (VersionSource) cache.getDistributedSystem().getDistributedMember();
            VersionTag tag = VersionTag.create(memberId);
            int entryVersion = stamp.getEntryVersion() - 1;
            int dsid = stamp.getDistributedSystemId();
            long time = System.currentTimeMillis();
            tag.setEntryVersion(entryVersion);
            tag.setDistributedSystemId(dsid);
            tag.setVersionTimeStamp(time);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = createNewEvent((DistributedRegion) region, tag, entry.getKey(), "value-3");
            ((LocalRegion) region).basicUpdate(event, false, true, 0L, false);
            // Verify the new stamp
            entry = region.getEntry(key);
            assertTrue(entry instanceof NonTXEntry);
            regionEntry = ((NonTXEntry) entry).getRegionEntry();
            stamp = regionEntry.getVersionStamp();
            assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
            assertEquals(entryVersion + 1, stamp.getEntryVersion());
            assertEquals(dsid, stamp.getDistributedSystemId());
            return stamp.asVersionTag();
        }
    });
    VersionTag remoteTag = (VersionTag) vm3.invoke(new SerializableCallable("Get timestamp from remote site") {

        @Override
        public Object call() throws Exception {
            Cache cache = CacheFactory.getAnyInstance();
            final Region region = cache.getRegion(regionName);
            // wait for entry to be received
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return (region.getEntry(key) != null);
                }

                public String description() {
                    return "Expected key-1 to be received on remote WAN site";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            wc = new WaitCriterion() {

                public boolean done() {
                    Entry entry = region.getEntry(key);
                    assertTrue(entry instanceof NonTXEntry);
                    RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
                    return regionEntry.getVersionStamp().getVersionTimeStamp() == tag.getVersionTimeStamp();
                }

                public String description() {
                    return "waiting for timestamp to be updated";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            Entry entry = region.getEntry(key);
            assertTrue(entry instanceof NonTXEntry);
            RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            return stamp.asVersionTag();
        }
    });
    assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Host(org.apache.geode.test.dunit.Host) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) Entry(org.apache.geode.cache.Region.Entry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 3 with VersionSource

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

the class UpdateVersionJUnitTest method testUpdateVersionAfterCreate.

/**
   * Tests for LocalRegion.
   */
@Test
public void testUpdateVersionAfterCreate() {
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
    Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
    try {
        region.create("key-1", "value-1");
        Entry entry = region.getEntry("key-1");
        assertTrue(entry instanceof NonTXEntry);
        RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
        VersionStamp stamp = regionEntry.getVersionStamp();
        // Create a duplicate entry version tag from stamp with newer time-stamp.
        VersionTag tag = VersionTag.create(stamp.getMemberID());
        int entryVersion = stamp.getEntryVersion();
        VersionSource member = stamp.getMemberID();
        int dsid = stamp.getDistributedSystemId();
        long time = System.currentTimeMillis() + 1;
        tag.setEntryVersion(entryVersion);
        tag.setDistributedSystemId(dsid);
        tag.setVersionTimeStamp(time);
        tag.setIsGatewayTag(true);
        assertTrue(region instanceof LocalRegion);
        EntryEventImpl event = createNewEvent((LocalRegion) region, tag, entry.getKey());
        ((LocalRegion) region).basicUpdateEntryVersion(event);
        // Verify the new stamp
        entry = region.getEntry("key-1");
        assertTrue(entry instanceof NonTXEntry);
        regionEntry = ((NonTXEntry) entry).getRegionEntry();
        stamp = regionEntry.getVersionStamp();
        assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
        assertEquals(++entryVersion, stamp.getEntryVersion());
        assertEquals(member, stamp.getMemberID());
        assertEquals(dsid, stamp.getDistributedSystemId());
    } finally {
        region.destroyRegion();
        cache.close();
    }
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Entry(org.apache.geode.cache.Region.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with VersionSource

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

the class UpdateVersionJUnitTest method testUpdateVersionAfterDestroyOnPR.

@Test
public void testUpdateVersionAfterDestroyOnPR() {
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
    Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
    try {
        region.create("key-1", "value-1");
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        region.destroy("key-1");
        assertTrue(region instanceof PartitionedRegion);
        Entry entry = ((PartitionedRegion) region).getEntry("key-1", true);
        assertTrue(entry instanceof EntrySnapshot);
        RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        VersionStamp stamp = regionEntry.getVersionStamp();
        // Create a duplicate entry version tag from stamp with newer time-stamp.
        VersionTag tag = VersionTag.create(stamp.getMemberID());
        int entryVersion = stamp.getEntryVersion();
        VersionSource member = stamp.getMemberID();
        int dsid = stamp.getDistributedSystemId();
        long time = System.currentTimeMillis();
        tag.setEntryVersion(entryVersion);
        tag.setDistributedSystemId(dsid);
        tag.setVersionTimeStamp(time);
        tag.setIsGatewayTag(true);
        assertTrue(region instanceof PartitionedRegion);
        EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, "key-1");
        ((PartitionedRegion) region).basicUpdateEntryVersion(event);
        // Verify the new stamp
        entry = ((PartitionedRegion) region).getEntry("key-1", true);
        assertTrue(entry instanceof EntrySnapshot);
        regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        stamp = regionEntry.getVersionStamp();
        assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
        assertEquals(++entryVersion, stamp.getEntryVersion());
        assertEquals(member, stamp.getMemberID());
        assertEquals(dsid, stamp.getDistributedSystemId());
    } finally {
        region.destroyRegion();
        cache.close();
    }
}
Also used : VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Entry(org.apache.geode.cache.Region.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with VersionSource

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

the class HAGIIDUnitTest method tombstonegc.

/** queue a tombstone GC message for the client. See bug #46832 */
public static void tombstonegc() throws Exception {
    LocalRegion r = (LocalRegion) cache.getRegion("/" + REGION_NAME);
    assertNotNull(r);
    DistributedMember id = r.getCache().getDistributedSystem().getDistributedMember();
    RegionEventImpl regionEvent = new RegionEventImpl(r, Operation.REGION_DESTROY, null, true, id);
    FilterInfo clientRouting = r.getFilterProfile().getLocalFilterRouting(regionEvent);
    assertTrue(clientRouting.getInterestedClients().size() > 0);
    regionEvent.setLocalFilterInfo(clientRouting);
    Map<VersionSource, Long> map = Collections.emptyMap();
    ClientTombstoneMessage message = ClientTombstoneMessage.gc(r, map, new EventID(r.getCache().getDistributedSystem()));
    CacheClientNotifier.notifyClients(regionEvent, message);
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) ClientTombstoneMessage(org.apache.geode.internal.cache.tier.sockets.ClientTombstoneMessage) RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Aggregations

VersionSource (org.apache.geode.internal.cache.versions.VersionSource)34 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)16 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)13 Entry (org.apache.geode.cache.Region.Entry)10 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)10 Test (org.junit.Test)10 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 Host (org.apache.geode.test.dunit.Host)5 VM (org.apache.geode.test.dunit.VM)5 HashMap (java.util.HashMap)4 Cache (org.apache.geode.cache.Cache)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Region (org.apache.geode.cache.Region)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 Map (java.util.Map)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 PRLocallyDestroyedException (org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)3