Search in sources :

Example 31 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class AbstractRegionEntry method generateVersionTag.

/**
   * This generates version tags for outgoing messages for all subclasses supporting concurrency
   * versioning. It also sets the entry's version stamp to the tag's values.
   */
@Override
public VersionTag generateVersionTag(VersionSource member, boolean withDelta, LocalRegion region, EntryEventImpl event) {
    VersionStamp stamp = this.getVersionStamp();
    if (stamp != null && region.getServerProxy() == null) {
        // clients do not generate versions
        int v = stamp.getEntryVersion() + 1;
        if (v > 0xFFFFFF) {
            // roll-over
            v -= 0x1000000;
        }
        VersionSource previous = stamp.getMemberID();
        // space.
        if (member == null) {
            VersionSource regionMember = region.getVersionMember();
            if (regionMember instanceof DiskStoreID) {
                member = regionMember;
            }
        }
        VersionTag tag = VersionTag.create(member);
        tag.setEntryVersion(v);
        if (region.getVersionVector() != null) {
            // Use region version if already provided, else generate
            long nextRegionVersion = event.getNextRegionVersion();
            if (nextRegionVersion != -1) {
                // Set on the tag and record it locally
                tag.setRegionVersion(nextRegionVersion);
                RegionVersionVector rvv = region.getVersionVector();
                rvv.recordVersion(rvv.getOwnerId(), nextRegionVersion);
                if (logger.isDebugEnabled()) {
                    logger.debug("recorded region version {}; region={}", nextRegionVersion, region.getFullPath());
                }
            } else {
                tag.setRegionVersion(region.getVersionVector().getNextVersion());
            }
        }
        if (withDelta) {
            tag.setPreviousMemberID(previous);
        }
        VersionTag remoteTag = event.getVersionTag();
        if (remoteTag != null && remoteTag.isGatewayTag()) {
            // if this event was received from a gateway we use the remote system's
            // timestamp and dsid.
            tag.setVersionTimeStamp(remoteTag.getVersionTimeStamp());
            tag.setDistributedSystemId(remoteTag.getDistributedSystemId());
            tag.setAllowedByResolver(remoteTag.isAllowedByResolver());
        } else {
            long time = region.cacheTimeMillis();
            int dsid = region.getDistributionManager().getDistributedSystemId();
            // one received from a wan gateway, so fake a timestamp if necessary
            if (time <= stamp.getVersionTimeStamp() && dsid != tag.getDistributedSystemId()) {
                time = stamp.getVersionTimeStamp() + 1;
            }
            tag.setVersionTimeStamp(time);
            tag.setDistributedSystemId(dsid);
        }
        stamp.setVersions(tag);
        stamp.setMemberID(member);
        event.setVersionTag(tag);
        if (logger.isDebugEnabled()) {
            logger.debug("generated tag {}; key={}; oldvalue={} newvalue={} client={} region={}; rvv={}", tag, event.getKey(), event.getOldValueStringForm(), event.getNewValueStringForm(), event.getContext() == null ? "none" : event.getContext().getDistributedMember().getName(), region.getFullPath(), region.getVersionVector());
        }
        return tag;
    }
    return null;
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp)

Example 32 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class CacheDistributionAdvisor method removeId.

@Override
public boolean removeId(ProfileId memberId, boolean crashed, boolean destroyed, boolean fromMembershipListener) {
    boolean isPersistent = false;
    DiskStoreID persistentId = null;
    CacheDistributionAdvisee advisee = (CacheDistributionAdvisee) getAdvisee();
    if (advisee.getAttributes().getDataPolicy().withPersistence()) {
        isPersistent = true;
        CacheProfile profile = (CacheProfile) getProfile(memberId);
        if (profile != null && profile.persistentID != null) {
            persistentId = ((CacheProfile) getProfile(memberId)).persistentID.diskStoreId;
        }
    }
    boolean result = super.removeId(memberId, crashed, destroyed, fromMembershipListener);
    // bug #48962 - record members that leave during GII so IIOp knows about them
    if (advisee instanceof DistributedRegion) {
        DistributedRegion r = (DistributedRegion) advisee;
        if (!r.isInitialized() && !r.isUsedForPartitionedRegionBucket()) {
            if (logger.isDebugEnabled()) {
                logger.debug("recording that {} has left during initialization of {}", memberId, r.getName());
            }
            ImageState state = r.getImageState();
            if (isPersistent) {
                if (persistentId != null) {
                    state.addLeftMember(persistentId);
                }
            } else {
                state.addLeftMember((InternalDistributedMember) memberId);
            }
        }
    }
    return result;
}
Also used : DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Example 33 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method createConflictOperationsP2R3.

private void createConflictOperationsP2R3() {
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] blocklist = { 2, 3 };
    P.invoke(() -> GIIDeltaDUnitTest.slowGII(blocklist));
    R.invoke(() -> GIIDeltaDUnitTest.slowGII(blocklist));
    AsyncInvocation async1 = doOnePutAsync(P, 2, "key1");
    AsyncInvocation async2 = doOnePutAsync(R, 3, "key1");
    // wait for the local puts are done at P & R before distribution
    // P's rvv=p2, gc=0
    waitForToVerifyRVV(P, memberP, 2, null, 0);
    // P's rvv=r2, gc=0
    waitForToVerifyRVV(P, memberR, 2, null, 0);
    // P's rvv=p2, gc=0
    waitForToVerifyRVV(R, memberP, 1, null, 0);
    // P's rvv=r2, gc=0
    waitForToVerifyRVV(R, memberR, 3, null, 0);
    // new Object[] { memberP, 2, 3, 0, 0, false }
    P.invoke(() -> GIIDeltaDUnitTest.resetSlowGII());
    R.invoke(() -> GIIDeltaDUnitTest.resetSlowGII());
    // should wait for async calls to finish before going on
    checkAsyncCall(async1);
    checkAsyncCall(async2);
    // verify RVVs
    // P's rvv=p2, gc=0
    waitForToVerifyRVV(P, memberP, 2, null, 0);
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(P, memberR, 3, null, 0);
    // P's rvv=p2, gc=0
    waitForToVerifyRVV(R, memberP, 2, null, 0);
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(R, memberR, 3, null, 0);
    // verify P won the conflict check
    waitToVerifyKey(P, "key1", generateValue(P));
    waitToVerifyKey(R, "key1", generateValue(P));
}
Also used : DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Example 34 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method testExpiredTombstoneSkippedAtProviderOnly.

/**
   * vm0 and vm1 are peers, each holds a DR. Let P and R have the same RVV and RVVGC: P7,R6, RVVGC
   * is P0,R0. vm1 becomes offline then restarts. Use testHook to pause the GII, then do tombstone
   * GC triggered by expireBatch (not by forceGC) at R only. The tombstone GC will be executed at R,
   * but igored at P. The deltaGII should send nothing to R since the RVVs are the same. So after
   * GII, P and R will have different tombstone number. But P's tombstones should be expired.
   */
@Test
public void testExpiredTombstoneSkippedAtProviderOnly() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    // let r4,r5,r6 to succeed
    doOnePut(R, 4, "key4");
    doOneDestroy(R, 5, "key5");
    doOnePut(R, 6, "key1");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(R, memberP, 6, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // now the rvv and rvvgc at P and R should be the same
    // save R's rvv in byte array, check if it will be fullGII
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    // shutdown R and restart
    closeCache(R);
    // let p7 to succeed
    doOnePut(P, 7, "key1");
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // add test hook
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myDuringPackingImage = new Mycallback(GIITestHookType.DuringPackingImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myDuringPackingImage);
        }
    });
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    // restart R and gii, it will be blocked at test hook
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // 8
    waitForCallbackStarted(P, GIITestHookType.DuringPackingImage);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            int count = getDeltaGIICount(P);
            return (count == 1);
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 30000, 200, true);
    int count = getDeltaGIICount(P);
    assertEquals(1, count);
    // let tombstone expired at R to trigger tombstoneGC.
    // Wait for tombstone is GCed at R, but still exists in P
    changeTombstoneTimout(R, MAX_WAIT);
    changeTombstoneTimout(P, MAX_WAIT);
    Wait.pause((int) MAX_WAIT);
    forceGC(R, 3);
    forceGC(P, 3);
    // let GII continue
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, true));
    async3.join(MAX_WAIT * 2);
    count = getDeltaGIICount(P);
    assertEquals(0, count);
    // deltaGII, key1 in delta
    verifyDeltaSizeFromStats(R, 1, 1);
    // tombstone key2, key5 should be GCed at R
    verifyTombstoneExist(R, "key2", false, false);
    verifyTombstoneExist(R, "key5", false, false);
    // tombstone key2, key5 should still exist and expired at P
    verifyTombstoneExist(P, "key2", true, true);
    verifyTombstoneExist(P, "key5", true, true);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    System.out.println("GGG:p_rvv=" + p_rvv.fullToString() + ":r_rvv=" + r_rvv.fullToString());
    // R's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // R's rvv=r6, gc=5
    waitForToVerifyRVV(R, memberR, 6, null, 5);
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 35 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method testFullGIIAfterClear.

/**
   * P and R are peers, each holds a DR. Each does a few operations to make RVV=P7,R6, RVVGC=P0,R0
   * for both members. R offline, then P8 is clear() operation. Run P9 is a put. Restart R. R will
   * do fullGII since R missed a clear
   */
@Test
public void testFullGIIAfterClear() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    createUnfinishedOperationsR4R5();
    doOnePut(P, 7, "key1");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // R's rvv=P7, gc=0
    waitForToVerifyRVV(R, memberP, 7, null, 0);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // shutdown R before clear
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    doOneClear(P, 8);
    // clear() increased P's version with 1 to P8
    // after clear, P and R's RVVGC == RVV, no more exception
    // P's rvv=r6, gc=8
    waitForToVerifyRVV(P, memberP, 8, null, 8);
    // P's rvv=r6, gc=6
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // do a put at P to get some delta
    doOnePut(P, 9, "key3");
    waitForToVerifyRVV(P, memberP, 9, null, 8);
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // restart R to deltaGII
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, true);
    createDistributedRegion(R);
    waitForToVerifyRVV(R, memberP, 9, null, 8);
    waitForToVerifyRVV(R, memberR, 6, null, 6);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    verifyDeltaSizeFromStats(R, 1, 0);
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)53 Test (org.junit.Test)38 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)26 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)26 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)19 UnitTest (org.apache.geode.test.junit.categories.UnitTest)11 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)10 HashMap (java.util.HashMap)5 Category (org.junit.experimental.categories.Category)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DiskAccessException (org.apache.geode.cache.DiskAccessException)3 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)3 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)2 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)2