Search in sources :

Example 1 with Tombstone

use of org.apache.geode.internal.cache.Token.Tombstone in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method verifyTimestampAfterOp.

/*
   * For VM 5 in ds 3.
   */
public static void verifyTimestampAfterOp(long timestamp, int memberid) {
    Region region = cache.getRegion("repRegion");
    assertEquals(0, region.size());
    Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
    true);
    RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
    assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
    VersionTag tag = re.getVersionStamp().asVersionTag();
    assertEquals(timestamp, tag.getVersionTimeStamp());
    assertEquals(memberid, tag.getDistributedSystemId());
}
Also used : Tombstone(org.apache.geode.internal.cache.Token.Tombstone) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 2 with Tombstone

use of org.apache.geode.internal.cache.Token.Tombstone in project geode by apache.

the class PersistentRVVRecoveryDUnitTest method testConflictChecksDuringConcurrentDeltaGIIAndOtherOp.

/**
   * This test creates 2 VMs in a distributed system with a persistent PartitionedRegion and one VM
   * (VM1) puts an entry in region. Second VM (VM2) starts later and does a delta GII. During Delta
   * GII in VM2 a DESTROY operation happens in VM1 and gets propagated to VM2 concurrently with GII.
   * At this point if entry version is greater than the once received from GII then it must not get
   * applied. Which is Bug #45921.
   *
   */
@Test
public void testConflictChecksDuringConcurrentDeltaGIIAndOtherOp() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new CacheSerializableRunnable("Create PR and put an entry") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setPartitionAttributes(attrs);
            RegionAttributes rAttrs = factory.create();
            Region region = cache.createRegionFactory(rAttrs).create("prRegion");
            region.put("testKey", "testValue");
            assertEquals(1, region.size());
        }
    });
    // Create a cache and region, do an update to change the version no. and
    // restart the cache and region.
    vm1.invoke(new CacheSerializableRunnable("Create PR and put an entry") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setPartitionAttributes(attrs);
            RegionAttributes rAttrs = factory.create();
            Region region = cache.createRegionFactory(rAttrs).create("prRegion");
            region.put("testKey", "testValue2");
            cache.close();
            // Restart
            cache = getCache();
            region = cache.createRegionFactory(rAttrs).create("prRegion");
        }
    });
    // Do a DESTROY in vm0 when delta GII is in progress in vm1 (Hopefully, Not
    // guaranteed).
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("Detroy entry in region") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.getRegion("prRegion");
            while (!region.get("testKey").equals("testValue2")) {
                Wait.pause(100);
            }
            region.destroy("testKey");
        }
    });
    try {
        async.join(3000);
    } catch (InterruptedException e) {
        new AssertionError("VM1 entry destroy did not finish in 3000 ms");
    }
    vm1.invoke(new CacheSerializableRunnable("Verifying entry version in new node VM1") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.getRegion("prRegion");
            Region.Entry entry = ((PartitionedRegion) region).getEntry("testKey", true);
            RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
            LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
            assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
            VersionTag tag = re.getVersionStamp().asVersionTag();
            assertEquals(3, /* Two puts and a Destroy */
            tag.getEntryVersion());
        }
    });
    closeCache(vm0);
    closeCache(vm1);
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Tombstone(org.apache.geode.internal.cache.Token.Tombstone) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 3 with Tombstone

use of org.apache.geode.internal.cache.Token.Tombstone in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method getVersionTimestampAfterOp.

/*
   * For VM3 in ds 2.
   */
public static long getVersionTimestampAfterOp() {
    Region region = cache.getRegion("repRegion");
    assertEquals(1, region.size());
    region.destroy("testKey");
    Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
    true);
    RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
    LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
    assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
    VersionTag tag = re.getVersionStamp().asVersionTag();
    return tag.getVersionTimeStamp();
}
Also used : Tombstone(org.apache.geode.internal.cache.Token.Tombstone) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Aggregations

Region (org.apache.geode.cache.Region)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 RegionEntry (org.apache.geode.internal.cache.RegionEntry)3 Tombstone (org.apache.geode.internal.cache.Token.Tombstone)3 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)3 EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1 CacheException (org.apache.geode.cache.CacheException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 DiskRegion (org.apache.geode.internal.cache.DiskRegion)1 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 Host (org.apache.geode.test.dunit.Host)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1