Search in sources :

Example 1 with CancelException

use of org.apache.geode.CancelException 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 CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class GatewaySenderEventRemoteDispatcher method readAcknowledgement.

protected GatewayAck readAcknowledgement() {
    SenderProxy sp = new SenderProxy(this.processor.getSender().getProxy());
    GatewayAck ack = null;
    Exception ex;
    try {
        connection = getConnection(false);
        if (logger.isDebugEnabled()) {
            logger.debug(" Receiving ack on the thread {}", connection);
        }
        this.connectionLifeCycleLock.readLock().lock();
        try {
            if (connection != null && !processor.isStopped()) {
                ack = (GatewayAck) sp.receiveAckFromReceiver(connection);
            }
        } finally {
            this.connectionLifeCycleLock.readLock().unlock();
        }
    } catch (Exception e) {
        Throwable t = e.getCause();
        if (t instanceof BatchException70) {
            // A BatchException has occurred.
            // Do not process the connection as dead since it is not dead.
            ex = (BatchException70) t;
        } else if (e instanceof GatewaySenderException) {
            // This Exception is thrown from
            // getConnection
            ex = (Exception) e.getCause();
        } else {
            ex = e;
            // keep using the connection if we had a batch exception. Else, destroy
            // it
            destroyConnection();
        }
        if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
        // if our pool is shutdown then just be silent
        } else if (ex instanceof IOException || (ex instanceof ServerConnectivityException && !(ex.getCause() instanceof PdxRegistryMismatchException)) || ex instanceof ConnectionDestroyedException) {
            // Sleep for a bit and recheck.
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
        } else {
            if (!(ex instanceof CancelException)) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_STOPPING_THE_PROCESSOR_BECAUSE_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_PROCESSING_A_BATCH), ex);
            }
            this.processor.setIsStopped(true);
        }
    }
    return ack;
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException) CancelException(org.apache.geode.CancelException) SenderProxy(org.apache.geode.cache.client.internal.SenderProxy) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) GemFireIOException(org.apache.geode.GemFireIOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException) IOException(java.io.IOException) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 3 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class Bug39356DUnitTest method testCrashWhileCreatingABucket.

/**
   * This tests the case where the VM forcing other VMs to create a bucket crashes while creating
   * the bucket.
   */
@Test
public void testCrashWhileCreatingABucket() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    SerializableRunnable createParReg = new SerializableRunnable("Create parReg") {

        public void run() {
            DistributionMessageObserver.setInstance(new MyRegionObserver(vm0));
            Cache cache = getCache();
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory pf = new PartitionAttributesFactory();
            pf.setRedundantCopies(1);
            pf.setRecoveryDelay(0);
            af.setDataPolicy(DataPolicy.PARTITION);
            af.setPartitionAttributes(pf.create());
            cache.createRegion(REGION_NAME, af.create());
        }
    };
    vm1.invoke(createParReg);
    vm2.invoke(createParReg);
    SerializableRunnable createParRegAccessor = new SerializableRunnable("Create parReg") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory pf = new PartitionAttributesFactory();
            pf.setRedundantCopies(1);
            pf.setLocalMaxMemory(0);
            af.setDataPolicy(DataPolicy.PARTITION);
            af.setPartitionAttributes(pf.create());
            Region r = cache.createRegion(REGION_NAME, af.create());
            // trigger the creation of a bucket, which should trigger the destruction of this VM.
            try {
                r.put("ping", "pong");
                fail("Should have gotten a CancelException");
            } catch (CancelException e) {
            // this is ok, we expect our observer to close this cache.
            }
        }
    };
    vm0.invoke(createParRegAccessor);
    SerializableRunnable verifyBuckets = new SerializableRunnable("Verify buckets") {

        public void run() {
            LogWriter log = org.apache.geode.test.dunit.LogWriterUtils.getLogWriter();
            Cache cache = getCache();
            PartitionedRegion r = (PartitionedRegion) cache.getRegion(REGION_NAME);
            for (int i = 0; i < r.getAttributes().getPartitionAttributes().getTotalNumBuckets(); i++) {
                List owners = null;
                while (owners == null) {
                    try {
                        owners = r.getBucketOwnersForValidation(i);
                    } catch (ForceReattemptException e) {
                        log.info(Bug39356DUnitTest.class + " verify buckets Caught a ForceReattemptException");
                        Wait.pause(1000);
                    }
                }
                if (owners.isEmpty()) {
                    log.info("skipping bucket " + i + " because it has no data");
                    continue;
                }
                assertEquals("Expecting bucket " + i + " to have two copies", 2, owners.size());
                log.info("bucket " + i + " had two copies");
            }
        }
    };
    vm1.invoke(verifyBuckets);
    vm2.invoke(verifyBuckets);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) LogWriter(org.apache.geode.LogWriter) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class RootRegionResponse method create.

/**
   * Returns a {@code RootRegionResponse} that will be returned to the specified recipient. The
   * message will contains a copy of the local manager's system config.
   */
public static RootRegionResponse create(DistributionManager dm, InternalDistributedMember recipient) {
    RootRegionResponse m = new RootRegionResponse();
    try {
        InternalCache cache = (InternalCache) CacheFactory.getInstance(dm.getSystem());
        final Collection roots;
        if (!Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRDebug")) {
            roots = cache.rootRegions();
        } else {
            roots = cache.rootRegions(true);
        }
        List regionNames = new ArrayList();
        List userAttributes = new ArrayList();
        for (Object root : roots) {
            Region r = (Region) root;
            regionNames.add(r.getName());
            userAttributes.add(CacheDisplay.getCachedObjectDisplay(r.getUserAttribute(), GemFireVM.LIGHTWEIGHT_CACHE_VALUE));
        }
        String[] temp = new String[0];
        m.regions = (String[]) regionNames.toArray(temp);
        m.userAttrs = (String[]) userAttributes.toArray(temp);
        ;
    } catch (CancelException ignore) {
    /* no cache yet */
    }
    m.setRecipient(recipient);
    return m;
}
Also used : ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Collection(java.util.Collection) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) CancelException(org.apache.geode.CancelException)

Example 5 with CancelException

use of org.apache.geode.CancelException 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)

Aggregations

CancelException (org.apache.geode.CancelException)135 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)46 IOException (java.io.IOException)40 ReplyException (org.apache.geode.distributed.internal.ReplyException)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CacheClosedException (org.apache.geode.cache.CacheClosedException)23 Region (org.apache.geode.cache.Region)22 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 Set (java.util.Set)16 Cache (org.apache.geode.cache.Cache)16 CacheException (org.apache.geode.cache.CacheException)16 HashSet (java.util.HashSet)15 Iterator (java.util.Iterator)15 QueryException (org.apache.geode.cache.query.QueryException)15 ArrayList (java.util.ArrayList)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)13 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13