Search in sources :

Example 1 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class LuceneIndexForPartitionedRegion method destroyOnRemoteMembers.

private void destroyOnRemoteMembers() {
    PartitionedRegion pr = (PartitionedRegion) getDataRegion();
    DM dm = pr.getDistributionManager();
    Set<InternalDistributedMember> recipients = pr.getRegionAdvisor().adviseAllPRNodes();
    if (!recipients.isEmpty()) {
        if (logger.isDebugEnabled()) {
            logger.debug("LuceneIndexForPartitionedRegion: About to send destroy message recipients=" + recipients);
        }
        ReplyProcessor21 processor = new ReplyProcessor21(dm, recipients);
        DestroyLuceneIndexMessage message = new DestroyLuceneIndexMessage(recipients, processor.getProcessorId(), regionPath, indexName);
        dm.putOutgoing(message);
        if (logger.isDebugEnabled()) {
            logger.debug("LuceneIndexForPartitionedRegion: Sent message recipients=" + recipients);
        }
        try {
            processor.waitForReplies();
        } catch (ReplyException e) {
            if (!(e.getCause() instanceof CancelException)) {
                throw e;
            }
        } catch (InterruptedException e) {
            dm.getCancelCriterion().checkCancelInProgress(e);
            Thread.currentThread().interrupt();
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DM(org.apache.geode.distributed.internal.DM) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 2 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class PartitionedRegionAPIDUnitTest method partitionedRegionTest.

public void partitionedRegionTest(final String prName) {
    /*
     * Do put(), create(), invalidate() operations through VM with PR having both Accessor and
     * Datastore
     */
    // String exceptionStr = "";
    vm0.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations1") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            final Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail(prName + " not created");
            }
            int size = 0;
            // if (pr.getAttributes().getScope() == Scope.DISTRIBUTED_ACK) {
            size = pr.size();
            assertEquals("Size doesnt return expected value", 0, size);
            assertEquals("isEmpty doesnt return proper state of the PartitionedRegion", true, pr.isEmpty());
            assertEquals(0, pr.keySet().size());
            // }
            for (int i = putRange_1Start; i <= putRange_1End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put(Integer.toString(i), Integer.toString(i));
            }
            // if (pr.getAttributes().getScope() == Scope.DISTRIBUTED_ACK) {
            size = pr.size();
            assertEquals("Size doesn't return expected value", putRange_1End, size);
            assertEquals("isEmpty doesnt return proper state of the PartitionedRegion", false, pr.isEmpty());
            // Positive assertion of functionality in a distributed env.
            // For basic functional support (or lack of), please see
            // PartitionedRegionSingleNodeOperationsJUnitTest
            assertEquals(putRange_1End, pr.keySet().size());
            Set ks = pr.keySet();
            Iterator ksI = ks.iterator();
            while (ksI.hasNext()) {
                try {
                    ksI.remove();
                    fail("Expected key set iterator to be read only");
                } catch (Exception expected) {
                }
                Object key = ksI.next();
                assertEquals(String.class, key.getClass());
                Integer.parseInt((String) key);
            }
            try {
                ksI.remove();
                fail("Expected key set iterator to be read only");
            } catch (Exception expected) {
            }
            assertFalse(ksI.hasNext());
            try {
                ksI.next();
                fail("Expected no such element exception");
            } catch (NoSuchElementException expected) {
                assertFalse(ksI.hasNext());
            }
            // }
            String exceptionStr = ReplyException.class.getName() + "||" + EntryNotFoundException.class.getName();
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = putRange_1Start; i <= putRange_1End; i++) {
                // System.out.println("Putting entry for key = " + i);
                try {
                    pr.destroy(Integer.toString(i));
                } catch (EntryNotFoundException enfe) {
                    searchForKey((PartitionedRegion) pr, Integer.toString(i));
                    throw enfe;
                }
            }
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            // if (pr.getAttributes().getScope() == Scope.DISTRIBUTED_ACK) {
            size = pr.size();
            assertEquals("Size doesnt return expected value = 0 instead it returns" + size, size, 0);
            assertEquals("isEmpty doesnt return proper state of the PartitionedRegion", pr.isEmpty(), true);
            // }
            for (int i = putRange_1Start; i <= putRange_1End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put(Integer.toString(i), Integer.toString(i));
            }
            // createInvalidateChange
            for (int i = createRange_1Start; i <= createRange_1End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                pr.create(key, val);
            }
            final String expectedExceptions = EntryExistsException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
            exceptionStr = ReplyException.class.getName() + "||" + expectedExceptions;
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = createRange_1Start; i <= createRange_1End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // cache.getLogger().fine("EntryExistsException is properly thrown");
                }
            }
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
            // if (pr.getAttributes().getScope() == Scope.DISTRIBUTED_ACK) {
            size = pr.size();
            assertEquals("Size doesnt return expected value", size, 10);
            // }
            LogWriterUtils.getLogWriter().fine("All the puts done successfully for vm0.");
            {
                PartitionedRegion ppr = (PartitionedRegion) pr;
                try {
                    ppr.dumpAllBuckets(true);
                } catch (ReplyException re) {
                    fail();
                }
            }
        }
    });
    /*
     * Do put(), create(), invalidate() operations through VM with PR having only Accessor(no data
     * store)
     */
    vm1.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations2") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail("PR not created");
            }
            for (int i = putRange_2Start; i <= putRange_2End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put(Integer.toString(i), Integer.toString(i));
            }
            // createInvalidateChange
            for (int i = createRange_2Start; i <= createRange_2End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                pr.create(key, val);
            }
            final String entryExistsException = EntryExistsException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryExistsException + "</ExpectedException>");
            String exceptionStr = ReplyException.class.getName() + ":" + entryExistsException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = createRange_2Start; i <= createRange_2End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // cache.getLogger().fine("EntryExistsException is properly thrown");
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryExistsException + "</ExpectedException>");
            cache.getLogger().fine("All the puts done successfully for vm1.");
        }
    });
    /*
     * Do destroy() operations through VM with PR having only Accessor(no data store). It also
     * verifies that EntryNotFoundException is thrown if the entry is already destroyed.
     */
    vm1.invoke(new CacheSerializableRunnable("doRemoveOperations1") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail("PR not created");
            }
            for (int i = removeRange_1Start; i <= removeRange_1End; i++) {
                // System.out.println("destroying entry for key = " + i);
                final String key = Integer.toString(i);
                try {
                    pr.destroy(key);
                } catch (EntryNotFoundException enfe) {
                    searchForKey((PartitionedRegion) pr, key);
                    throw enfe;
                }
            }
            final String entryNotFoundException = EntryNotFoundException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryNotFoundException + "</ExpectedException>");
            String exceptionStr = ReplyException.class.getName() + "||" + entryNotFoundException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = removeRange_1Start; i <= removeRange_1End; i++) {
                final String key = Integer.toString(i);
                try {
                    pr.destroy(key);
                    fail("EntryNotFoundException is not thrown in destroy operation for key = " + i);
                } catch (EntryNotFoundException expected) {
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFoundException + "</ExpectedException>");
            LogWriterUtils.getLogWriter().fine("All the remove done successfully for vm0.");
        }
    });
    /*
     * Do more put(), create(), invalidate() operations through VM with PR having Accessor + data
     * store
     */
    vm2.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations3") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            assertNotNull("PR not created", pr);
            for (int i = putRange_3Start; i <= putRange_3End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put(Integer.toString(i), Integer.toString(i));
            }
            for (int i = createRange_3Start; i <= createRange_3End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                pr.create(key, val);
            }
            final String entryExistsException = EntryExistsException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryExistsException + "</ExpectedException>");
            String exceptionStr = ReplyException.class.getName() + "||" + entryExistsException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = createRange_3Start; i <= createRange_3End; i++) {
                Object val = null;
                Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // getLogWriter().fine("EntryExistsException is properly thrown");
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryExistsException + "</ExpectedException>");
        }
    });
    /*
     * Do more remove() operations through VM with PR having Accessor + data store
     */
    vm2.invoke(new CacheSerializableRunnable("doRemoveOperations2") {

        public void run2() throws CacheException {
            int i = 0;
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            assertNotNull("PR not created", pr);
            if (pr == null) {
                fail("PR not created");
            }
            String key;
            for (i = removeRange_2Start; i <= removeRange_2End; i++) {
                // System.out.println("destroying entry for key = " + i);
                key = Integer.toString(i);
                try {
                    pr.destroy(key);
                } catch (EntryNotFoundException enfe) {
                    searchForKey((PartitionedRegion) pr, key);
                    throw enfe;
                }
            }
            final String entryNotFound = EntryNotFoundException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryNotFound + "</ExpectedException>");
            String exceptionStr = ReplyException.class.getName() + "||" + entryNotFound;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (i = removeRange_2Start; i <= removeRange_2End; i++) {
                // System.out.println("destroying entry for key = " + i);
                try {
                    pr.destroy(Integer.toString(i));
                    fail("EntryNotFoundException is not thrown in destroy operation for key = " + (Integer.toString(i)));
                } catch (EntryNotFoundException expected) {
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFound + "</ExpectedException>");
        }
    });
    /*
     * Do more put() operations through VM with PR having only Accessor
     */
    vm3.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations4") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            assertNotNull("PR not created", pr);
            for (int i = putRange_4Start; i <= putRange_4End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put(Integer.toString(i), Integer.toString(i));
            }
            for (int i = createRange_4Start; i <= createRange_4End; i++) {
                Object val = null;
                final Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                pr.create(key, val);
            }
            final String entryExistsException = EntryExistsException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryExistsException + "</ExpectedException>");
            String exceptionStr = ReplyException.class.getName() + "||" + entryExistsException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = createRange_4Start; i <= createRange_4End; i++) {
                Object val = null;
                final Object key = Integer.toString(i);
                if (i % 2 == 0) {
                    val = Integer.toString(i);
                }
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // getLogWriter().fine("EntryExistsException is properly thrown");
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryExistsException + "</ExpectedException>");
        }
    });
    /*
     * validate the data in PartionedRegion at different VM's
     * 
     */
    CacheSerializableRunnable validateRegionAPIs = new CacheSerializableRunnable("validateInserts") {

        public void run2() {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            assertNotNull("PR not created", pr);
            // Validation with get() operation.
            for (int i = putRange_1Start; i <= putRange_4End; i++) {
                Object val = pr.get(Integer.toString(i));
                if ((i >= removeRange_1Start && i <= removeRange_1End) || (i >= removeRange_2Start && i <= removeRange_2End)) {
                    assertNull("Remove validation failed for key " + i, val);
                } else {
                    assertNotNull("put() not done for key " + i, val);
                }
            }
            // validation with containsKey() operation.
            for (int i = putRange_1Start; i <= putRange_4End; i++) {
                boolean conKey = pr.containsKey(Integer.toString(i));
                if ((i >= removeRange_1Start && i <= removeRange_1End) || (i >= removeRange_2Start && i <= removeRange_2End)) {
                    assertFalse("containsKey() remove validation failed for key = " + i, conKey);
                } else {
                    assertTrue("containsKey() Validation failed for key = " + i, conKey);
                }
                LogWriterUtils.getLogWriter().fine("containsKey() Validated entry for key = " + i);
            }
            // validation with containsValueForKey() operation
            for (int i = putRange_1Start; i <= putRange_4End; i++) {
                boolean conKey = pr.containsValueForKey(Integer.toString(i));
                if ((i >= removeRange_1Start && i <= removeRange_1End) || (i >= removeRange_2Start && i <= removeRange_2End)) {
                    assertFalse("containsValueForKey() remove validation failed for key = " + i, conKey);
                } else {
                    assertTrue("containsValueForKey() Validation failed for key = " + i, conKey);
                }
                LogWriterUtils.getLogWriter().fine("containsValueForKey() Validated entry for key = " + i);
            }
        }
    };
    // validate the data from all the VM's
    vm0.invoke(validateRegionAPIs);
    vm1.invoke(validateRegionAPIs);
    vm2.invoke(validateRegionAPIs);
    vm3.invoke(validateRegionAPIs);
    /*
     * destroy the Region.
     */
    vm0.invoke(new CacheSerializableRunnable("destroyRegionOp") {

        public void run2() {
            Cache cache = getCache();
            Region pr = cache.getRegion(prName);
            assertNotNull("Region already destroyed.", pr);
            pr.destroyRegion();
            assertTrue("Region isDestroyed false", pr.isDestroyed());
            assertNull("Region not destroyed.", cache.getRegion(prName));
        }
    });
    /*
     * validate the data after the region.destroy() operation.
     */
    CacheSerializableRunnable validateAfterRegionDestroy = new CacheSerializableRunnable("validateInsertsAfterRegionDestroy") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            Region pr = null;
            pr = cache.getRegion(prName);
            assertNull("Region not destroyed.", pr);
            Region rootRegion = cache.getRegion(Region.SEPARATOR + PartitionedRegionHelper.PR_ROOT_REGION_NAME);
            // Verify allPartitionedRegion.
            // Region allPrs = rootRegion
            // .getSubregion(PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME);
            Object configObj = rootRegion.get(prName.substring(1));
            if (configObj != null) {
                fail("PRConfig found in allPartitionedRegion Metadata for this PR.");
            }
            // Verify b2n region.
            // Region b2nReg = rootRegion
            // .getSubregion(PartitionedRegionHelper.BUCKET_2_NODE_TABLE_PREFIX);
            // if (b2nReg != null) {
            // fail("PRConfig found in allPartitionedRegion Metadata for this PR.");
            // }
            // Verify bucket Regions.
            Set subreg = rootRegion.subregions(false);
            for (java.util.Iterator itr = subreg.iterator(); itr.hasNext(); ) {
                Region reg = (Region) itr.next();
                String name = reg.getName();
                if ((name.indexOf(PartitionedRegionHelper.BUCKET_REGION_PREFIX)) != -1) {
                    fail("Bucket exists. Bucket = " + name);
                }
            }
            // verify prIdToPr Map.
            boolean con = PartitionedRegion.prIdToPR.containsKey("PR1");
            if (con == true) {
                fail("prIdToPR contains pr reference ");
            }
        }
    };
    // validateAfterRegionDestory from all VM's
    vm0.invoke(validateAfterRegionDestroy);
    vm1.invoke(validateAfterRegionDestroy);
    vm2.invoke(validateAfterRegionDestroy);
    vm3.invoke(validateAfterRegionDestroy);
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) CacheException(org.apache.geode.cache.CacheException) EntryExistsException(org.apache.geode.cache.EntryExistsException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) EntryExistsException(org.apache.geode.cache.EntryExistsException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) NoSuchElementException(java.util.NoSuchElementException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) NoSuchElementException(java.util.NoSuchElementException) Cache(org.apache.geode.cache.Cache)

Example 3 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class ElderInitProcessor method init.

////////// Public static entry point /////////
/**
   * Initializes ElderState map by recovering all existing grantors and crashed grantors in the
   * current ds.
   */
static void init(DM dm, HashMap map) {
    HashSet crashedGrantors = new HashSet();
    if (!dm.isAdam()) {
        Set others = dm.getOtherDistributionManagerIds();
        if (!others.isEmpty()) {
            ElderInitProcessor processor = new ElderInitProcessor(dm, others, map, crashedGrantors);
            ElderInitMessage.send(others, dm, processor);
            try {
                processor.waitForRepliesUninterruptibly();
            } catch (ReplyException e) {
                e.handleAsUnexpected();
            }
        }
    }
    // always recover from ourself
    GrantorRequestProcessor.readyForElderRecovery(dm.getSystem(), null, null);
    DLockService.recoverLocalElder(dm, map, crashedGrantors);
    {
        Iterator it = crashedGrantors.iterator();
        while (it.hasNext()) {
            map.put(it.next(), new GrantorInfo(null, 0, 0, true));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) ReplyException(org.apache.geode.distributed.internal.ReplyException) HashSet(java.util.HashSet)

Example 4 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class ShutdownAllRequest method send.

/**
   * Sends a shutdownAll request to all other members and performs local shutdownAll processing in
   * the waitingThreadPool.
   */
public static Set send(final DM dm, long timeout) {
    boolean hadCache = hasCache();
    DistributionManager dism = dm instanceof DistributionManager ? (DistributionManager) dm : null;
    InternalDistributedMember myId = dm.getDistributionManagerId();
    Set recipients = dm.getOtherNormalDistributionManagerIds();
    recipients.remove(myId);
    // now do shutdownall
    ShutdownAllRequest request = new ShutdownAllRequest();
    request.setRecipients(recipients);
    ShutDownAllReplyProcessor replyProcessor = new ShutDownAllReplyProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    if (!InternalLocator.isDedicatedLocator()) {
        if (hadCache && dism != null) {
            AdminResponse response;
            try {
                request.setSender(myId);
                response = request.createResponse(dism);
            } catch (Exception ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("caught exception while processing shutdownAll locally", ex);
                }
                response = AdminFailureResponse.create(dism, myId, ex);
            }
            response.setSender(myId);
            replyProcessor.process(response);
        }
    }
    boolean interrupted = false;
    try {
        if (!replyProcessor.waitForReplies(timeout)) {
            return null;
        }
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            e.handleAsUnexpected();
        }
    } catch (CancelException ignore) {
    // expected
    } catch (InterruptedException ignore) {
        interrupted = true;
    }
    // wait until all the recipients send response, shut down itself (if not a locator)
    if (hadCache) {
        // because the cache is closed at GemFireCacheImpl.getInstance().shutDownAll()
        if (!InternalLocator.isDedicatedLocator()) {
            InternalDistributedSystem ids = dm.getSystem();
            if (ids.isConnected()) {
                ids.disconnect();
            }
        }
    }
    if (interrupted) {
        Thread.currentThread().interrupt();
    }
    try {
        Thread.sleep(3 * SLEEP_TIME_BEFORE_DISCONNECT_DS);
    } catch (InterruptedException ignore) {
    }
    return replyProcessor.getResults();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) ReplyException(org.apache.geode.distributed.internal.ReplyException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 5 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class CompactRequest method send.

public static Map<DistributedMember, Set<PersistentID>> send(DM dm) {
    Set recipients = dm.getOtherDistributionManagerIds();
    CompactRequest request = new CompactRequest();
    request.setRecipients(recipients);
    CompactReplyProcessor replyProcessor = new CompactReplyProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    request.setSender(dm.getDistributionManagerId());
    request.process((DistributionManager) dm);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            throw e;
        }
    } catch (InterruptedException e) {
        logger.warn(e);
    }
    return replyProcessor.results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Aggregations

ReplyException (org.apache.geode.distributed.internal.ReplyException)75 CancelException (org.apache.geode.CancelException)24 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)20 Set (java.util.Set)16 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)16 HashSet (java.util.HashSet)12 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)10 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 IOException (java.io.IOException)7 CacheClosedException (org.apache.geode.cache.CacheClosedException)7 ReplyMessage (org.apache.geode.distributed.internal.ReplyMessage)7 Cache (org.apache.geode.cache.Cache)6 CacheException (org.apache.geode.cache.CacheException)6 Region (org.apache.geode.cache.Region)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 Released (org.apache.geode.internal.offheap.annotations.Released)6 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)5 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)5