Search in sources :

Example 1 with RegionMap

use of org.apache.geode.internal.cache.RegionMap in project geode by apache.

the class ConcurrentLeaveDuringGIIDUnitTest method testBug48962.

/**
   * In #48962 a member X has replicated region and is updating it. Members A and B are started up
   * in parallel. At the same time X decides to close the region. Member A manages to tell X that
   * it's creating the region and receives an update that B does not see. B finishes GII with no
   * content and then A gets its initial image from B, leaving an inconsistency between them.
   * <p>
   * The test installs a GII hook in A that causes it to pause after announcing creation of the
   * region.
   * <p>
   * X then creates its region and does an operation and closes its cache.
   * <p>
   * B then starts and creates its region, not doing a GII from A since A is still initializing.
   * <p>
   * A is then allowed to start its GII and pulls an image from B.
   * 
   */
@Ignore
@Test
public void testBug48962() throws Exception {
    VM X = Host.getHost(0).getVM(1);
    VM A = Host.getHost(0).getVM(2);
    VM B = Host.getHost(0).getVM(3);
    final String regionName = getUniqueName() + "_Region";
    SerializableCallable createRegionXB = new SerializableCallable("create region in X and B") {

        public Object call() {
            Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            Object result = null;
            if (VM.getCurrentVMNum() == 1) {
                // VM X
                r.put("keyFromX", "valueFromX");
                result = getCache().getDistributedSystem().getDistributedMember();
                r.getCache().getDistributedSystem().disconnect();
            } else {
                // VM B
                // B will not do a GII and X never knows about B
                assertFalse(r.containsKey("keyFromX"));
                result = getCache().getDistributedSystem().getDistributedMember();
            }
            return result;
        }
    };
    SerializableCallable createRegionA = new SerializableCallable("create region in A") {

        public Object call() {
            final GiiCallback cb = new GiiCallback(InitialImageOperation.GIITestHookType.BeforeGetInitialImage, regionName);
            InitialImageOperation.setGIITestHook(cb);
            Thread t = new Thread("create region in a thread that will block before GII") {

                public void run() {
                    Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
                }
            };
            t.start();
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return cb.isRunning;
                }

                public String description() {
                    return "waiting for GII test hook to be invoked";
                }
            };
            Wait.waitForCriterion(wc, 20000, 500, true);
            return getCache().getDistributedSystem().getDistributedMember();
        }
    };
    A.invoke(createRegionA);
    final InternalDistributedMember Xid = (InternalDistributedMember) X.invoke(createRegionXB);
    A.invoke(new SerializableRunnable("make sure A got keyFromX from X") {

        public void run() {
            // use internal methods to get the region since it's still initializing
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            final RegionMap r = cache.getRegionByPathForProcessing(regionName).getRegionMap();
            // X's update should have been propagated to A and put into the cache.
            // If this throws an assertion error then there's no point in
            // continuing the test because we didn't set up the initial
            // condition needed for the next step.
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return r.containsKey("keyFromX");
                }

                public String description() {
                    return "waiting for region " + regionName + " to contain keyFromX";
                }
            };
            Wait.waitForCriterion(wc, 20000, 1000, true);
        }
    });
    // create in B and make sure the key isn't there
    B.invoke(createRegionXB);
    A.invoke(new SerializableRunnable("allow A to continue GII from B") {

        public void run() {
            GiiCallback cb = (GiiCallback) InitialImageOperation.getGIITestHookForCheckingPurpose(InitialImageOperation.GIITestHookType.BeforeGetInitialImage);
            synchronized (cb.lockObject) {
                cb.lockObject.notify();
            }
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return getCache().getRegion(regionName) != null;
                }

                public String description() {
                    return "waiting for region " + regionName + " to initialize";
                }
            };
            Wait.waitForCriterion(wc, 20000, 1000, true);
            // ensure that the RVV has recorded the event
            DistributedRegion r = (DistributedRegion) getCache().getRegion(regionName);
            if (!r.getVersionVector().contains(Xid, 1)) {
                LogWriterUtils.getLogWriter().info("r's version vector is " + r.getVersionVector().fullToString());
                ((LocalRegion) r).dumpBackingMap();
            }
            assertTrue(r.containsKey("keyFromX"));
            // if the test fails here then the op received from X was not correctly
            // picked up and recorded in the RVV
            assertTrue(r.getVersionVector().contains(Xid, 1));
        }
    });
    // Now ensure the B has done the sync and received the entry
    B.invoke(new SerializableRunnable("ensure B is now consistent") {

        public void run() {
            final Region r = getCache().getRegion(regionName);
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return r.containsKey("keyFromX");
                }

                public String description() {
                    return "waiting for region " + regionName + " to contain keyFromX";
                }
            };
            // if the test fails here then a sync from B to A was not performed
            Wait.waitForCriterion(wc, 20000, 500, true);
            // if the test fails here something is odd because the sync was done
            // but the RVV doesn't know about it
            assertTrue(((LocalRegion) r).getVersionVector().contains(Xid, 1));
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RegionMap(org.apache.geode.internal.cache.RegionMap) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Region (org.apache.geode.cache.Region)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 RegionMap (org.apache.geode.internal.cache.RegionMap)1 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1