Search in sources :

Example 6 with DistributedRegion

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

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

the class MemoryThresholdsOffHeapDUnitTest method doDistributedRegionRemotePutRejection.

/**
   * test that puts in a server are rejected when a remote VM crosses critical threshold
   * 
   * @throws Exception
   */
private void doDistributedRegionRemotePutRejection(boolean localDestroy, boolean cacheClose) throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final String regionName = "offHeapDRRemotePutRejection";
    // set port to 0 in-order for system to pickup a random port.
    startCacheServer(server1, 0f, 0f, regionName, false, /* createPR */
    false, /* notifyBySubscription */
    0);
    startCacheServer(server2, 0f, 90f, regionName, false, /* createPR */
    false, /* notifyBySubscription */
    0);
    registerTestMemoryThresholdListener(server1);
    registerTestMemoryThresholdListener(server2);
    doPuts(server1, regionName, false, /* catchRejectedException */
    false);
    doPutAlls(server1, regionName, false, /* catchRejectedException */
    false, /* catchLowMemoryException */
    Range.DEFAULT);
    // make server2 critical
    setUsageAboveCriticalThreshold(server2, regionName);
    verifyListenerValue(server1, MemoryState.CRITICAL, 1, true);
    verifyListenerValue(server2, MemoryState.CRITICAL, 1, true);
    // make sure that local server1 puts are rejected
    doPuts(server1, regionName, false, /* catchRejectedException */
    true);
    Range r1 = new Range(Range.DEFAULT, Range.DEFAULT.width() + 1);
    doPutAlls(server1, regionName, false, /* catchRejectedException */
    true, /* catchLowMemoryException */
    r1);
    if (localDestroy) {
        // local destroy the region on sick member
        server2.invoke(new SerializableCallable("local destroy") {

            public Object call() throws Exception {
                Region r = getRootRegion().getSubregion(regionName);
                r.localDestroyRegion();
                return null;
            }
        });
    } else if (cacheClose) {
        server2.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                getCache().close();
                return null;
            }
        });
    } else {
        setUsageBelowEviction(server2, regionName);
    }
    // wait for remote region destroyed message to be processed
    server1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "remote localRegionDestroyed message not received";
                }

                public boolean done() {
                    DistributedRegion dr = (DistributedRegion) getRootRegion().getSubregion(regionName);
                    return dr.getMemoryThresholdReachedMembers().size() == 0;
                }
            };
            Wait.waitForCriterion(wc, 10000, 10, true);
            return null;
        }
    });
    // make sure puts succeed
    doPuts(server1, regionName, false, /* catchRejectedException */
    false);
    Range r2 = new Range(r1, r1.width() + 1);
    doPutAlls(server1, regionName, false, /* catchRejectedException */
    false, /* catchLowMemoryException */
    r2);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) 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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) Host(org.apache.geode.test.dunit.Host) Range(org.apache.geode.cache.management.MemoryThresholdsDUnitTest.Range) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheException(org.apache.geode.cache.CacheException)

Example 8 with DistributedRegion

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

the class MemoryThresholdsDUnitTest method startCacheServer.

/**
   * Starts up a CacheServer.
   * 
   * @return a {@link ServerPorts} containing the CacheServer ports.
   */
private ServerPorts startCacheServer(VM server, final float evictionThreshold, final float criticalThreshold, final String regionName, final boolean createPR, final boolean notifyBySubscription, final int prRedundancy) throws Exception {
    return (ServerPorts) server.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getSystem(getServerProperties());
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            InternalResourceManager irm = cache.getInternalResourceManager();
            HeapMemoryMonitor hmm = irm.getHeapMonitor();
            hmm.setTestMaxMemoryBytes(1000);
            HeapMemoryMonitor.setTestBytesUsedForThresholdSet(500);
            irm.setEvictionHeapPercentage(evictionThreshold);
            irm.setCriticalHeapPercentage(criticalThreshold);
            AttributesFactory factory = new AttributesFactory();
            if (createPR) {
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(prRedundancy);
                paf.setTotalNumBuckets(11);
                factory.setPartitionAttributes(paf.create());
            } else {
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setDataPolicy(DataPolicy.REPLICATE);
            }
            Region region = createRegion(regionName, factory.create());
            if (createPR) {
                assertTrue(region instanceof PartitionedRegion);
            } else {
                assertTrue(region instanceof DistributedRegion);
            }
            CacheServer cacheServer = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailableTCPPorts(1)[0];
            cacheServer.setPort(port);
            cacheServer.setNotifyBySubscription(notifyBySubscription);
            cacheServer.start();
            return new ServerPorts(port);
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) HeapMemoryMonitor(org.apache.geode.internal.cache.control.HeapMemoryMonitor) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager)

Example 9 with DistributedRegion

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

the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.

@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect the DS before sending a prepare message
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        getSystem().disconnect();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    try {
        createPersistentRegion(vm1);
    } catch (Exception e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    closeRegion(vm0);
    // This wait for VM0 to come back
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    createPersistentRegion(vm0);
    async1.getResult();
    checkForEntry(vm1);
    vm0.invoke(new SerializableRunnable("check for offline members") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
            DiskRegion dr = region.getDiskRegion();
            assertEquals(Collections.emptySet(), dr.getOfflineMembers());
            assertEquals(1, dr.getOnlineMembers().size());
        }
    });
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 10 with DistributedRegion

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

the class MembershipViewRequest method process.

@Override
protected void process(DistributionManager dm) {
    int initLevel = this.targetReinitializing ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
    PersistentMembershipView view = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            view = persistenceAdvisor.getMembershipView();
        }
    } catch (RegionDestroyedException e) {
        // exception = new ReplyException(e);
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        // exception = new ReplyException(e);
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        MembershipViewReplyMessage replyMsg = new MembershipViewReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        replyMsg.view = view;
        if (logger.isDebugEnabled()) {
            logger.debug("MembershipViewRequest returning view {} for region {}", view, this.regionPath);
        }
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Aggregations

DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)36 Region (org.apache.geode.cache.Region)25 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 Cache (org.apache.geode.cache.Cache)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 IOException (java.io.IOException)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 CacheException (org.apache.geode.cache.CacheException)5 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)5 Set (java.util.Set)4 CancelException (org.apache.geode.CancelException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4