Search in sources :

Example 66 with RegionDestroyedException

use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.

the class LocalRegion method basicInvalidateRegion.

void basicInvalidateRegion(RegionEventImpl event) {
    final TXStateProxy tx = this.cache.getTXMgr().internalSuspend();
    try {
        this.regionInvalid = true;
        getImageState().setRegionInvalidated(true);
        invalidateAllEntries(event);
        Set allSubregions = subregions(true);
        for (Object allSubregion : allSubregions) {
            LocalRegion region = (LocalRegion) allSubregion;
            region.regionInvalid = true;
            try {
                region.getImageState().setRegionInvalidated(true);
                region.invalidateAllEntries(event);
                if (!region.isInitialized()) {
                    // don't invoke callbacks if not initialized yet
                    continue;
                }
                if (region.hasListener()) {
                    RegionEventImpl event2 = (RegionEventImpl) event.clone();
                    event2.region = region;
                    region.dispatchListenerEvent(EnumListenerEvent.AFTER_REGION_INVALIDATE, event2);
                }
            } catch (RegionDestroyedException ignore) {
            // ignore subregions that have been destroyed to fix bug 33276
            }
        }
        if (!isInitialized()) {
            return;
        }
        event.setEventType(EnumListenerEvent.AFTER_REGION_INVALIDATE);
        notifyBridgeClients(event);
        boolean hasListener = hasListener();
        if (logger.isDebugEnabled()) {
            logger.debug("basicInvalidateRegion: hasListener = {}", hasListener);
        }
        if (hasListener) {
            dispatchListenerEvent(EnumListenerEvent.AFTER_REGION_INVALIDATE, event);
        }
    } finally {
        this.cache.getTXMgr().internalResume(tx);
    }
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) AbstractSet(java.util.AbstractSet) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 67 with RegionDestroyedException

use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.

the class FunctionStreamingResultCollector method waitForCacheOrFunctionException.

/**
   * Waits for the response from the recipient
   * 
   * @throws CacheException if the recipient threw a cache exception during message processing
   * @throws ForceReattemptException if the recipient left the distributed system before the
   *         response was received.
   * @throws RegionDestroyedException if the peer has closed its copy of the region
   */
public boolean waitForCacheOrFunctionException(long timeout) throws CacheException, ForceReattemptException {
    boolean timedOut = false;
    try {
        if (timeout == 0) {
            waitForRepliesUninterruptibly();
            timedOut = true;
        } else {
            timedOut = waitForRepliesUninterruptibly(timeout);
        }
    } catch (ReplyException e) {
        removeMember(e.getSender(), true);
        Throwable t = e.getCause();
        if (t instanceof CacheException) {
            throw (CacheException) t;
        } else if (t instanceof RegionDestroyedException) {
            throw (RegionDestroyedException) t;
        } else if (t instanceof ForceReattemptException) {
            throw new ForceReattemptException("Peer requests reattempt", t);
        } else if (t instanceof PrimaryBucketException) {
            throw new PrimaryBucketException("Peer failed primary test", t);
        }
        if (t instanceof CancelException) {
            this.execution.failedNodes.add(e.getSender().getId());
            String msg = "PartitionResponse got remote CacheClosedException, throwing PartitionedRegionCommunicationException";
            logger.debug("{}, throwing ForceReattemptException", msg, t);
            throw (CancelException) t;
        }
        if (e.getCause() instanceof FunctionException) {
            throw (FunctionException) e.getCause();
        }
        e.handleAsUnexpected();
    }
    return timedOut;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) FunctionException(org.apache.geode.cache.execute.FunctionException) CancelException(org.apache.geode.CancelException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 68 with RegionDestroyedException

use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.

the class AbstractGatewaySender method waitUntilFlushed.

public boolean waitUntilFlushed(long timeout, TimeUnit unit) throws InterruptedException {
    boolean result = false;
    if (isParallel()) {
        try {
            WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this, timeout, unit, true);
            result = coordinator.waitUntilFlushed();
        } catch (BucketMovedException | CancelException | RegionDestroyedException e) {
            logger.warn(LocalizedStrings.AbstractGatewaySender_CAUGHT_EXCEPTION_ATTEMPTING_WAIT_UNTIL_FLUSHED_RETRYING.toLocalizedString(), e);
            throw e;
        } catch (Throwable t) {
            logger.warn(LocalizedStrings.AbstractGatewaySender_CAUGHT_EXCEPTION_ATTEMPTING_WAIT_UNTIL_FLUSHED_RETURNING.toLocalizedString(), t);
            throw new InternalGemFireError(t);
        }
        return result;
    } else {
        // Serial senders are currently not supported
        throw new UnsupportedOperationException(LocalizedStrings.AbstractGatewaySender_WAIT_UNTIL_FLUSHED_NOT_SUPPORTED_FOR_SERIAL_SENDERS.toLocalizedString());
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CancelException(org.apache.geode.CancelException) WaitUntilParallelGatewaySenderFlushedCoordinator(org.apache.geode.internal.cache.wan.parallel.WaitUntilParallelGatewaySenderFlushedCoordinator) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 69 with RegionDestroyedException

use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.

the class AbstractGatewaySender method destroy.

public void destroy(boolean initiator) {
    try {
        this.getLifeCycleLock().writeLock().lock();
        // first, check if this sender is attached to any region. If so, throw
        // GatewaySenderException
        Set<LocalRegion> regions = this.cache.getApplicationRegions();
        Iterator regionItr = regions.iterator();
        while (regionItr.hasNext()) {
            LocalRegion region = (LocalRegion) regionItr.next();
            if (region.getAttributes().getGatewaySenderIds().contains(this.id)) {
                throw new GatewaySenderException(LocalizedStrings.GatewaySender_COULD_NOT_DESTROY_SENDER_AS_IT_IS_STILL_IN_USE.toLocalizedString(this));
            }
        }
        // close the GatewaySenderAdvisor
        GatewaySenderAdvisor advisor = this.getSenderAdvisor();
        if (advisor != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Stopping the GatewaySender advisor");
            }
            advisor.close();
        }
        // remove the sender from the cache
        this.cache.removeGatewaySender(this);
        // destroy the region underneath the sender's queue
        if (initiator) {
            Set<RegionQueue> regionQueues = getQueues();
            if (regionQueues != null) {
                for (RegionQueue regionQueue : regionQueues) {
                    try {
                        if (regionQueue instanceof ConcurrentParallelGatewaySenderQueue) {
                            Set<PartitionedRegion> queueRegions = ((ConcurrentParallelGatewaySenderQueue) regionQueue).getRegions();
                            for (PartitionedRegion queueRegion : queueRegions) {
                                queueRegion.destroyRegion();
                            }
                        } else {
                            // For SerialGatewaySenderQueue, do local destroy
                            regionQueue.getRegion().localDestroyRegion();
                        }
                    }// by several nodes simultaneously
                     catch (RegionDestroyedException e) {
                        // the region might have already been destroyed by other node. Just
                        // log
                        // the exception.
                        this.logger.info(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_REGION_0_UNDERLYING_GATEWAYSENDER_1_IS_ALREADY_DESTROYED, new Object[] { e.getRegionFullPath(), this }));
                    }
                }
            }
        // END if (regionQueues != null)
        }
    } finally {
        this.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 70 with RegionDestroyedException

use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.

the class AbstractGatewaySender method distribute.

public void distribute(EnumListenerEvent operation, EntryEventImpl event, List<Integer> allRemoteDSIds) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    // If this gateway is not running, return
    if (!isRunning()) {
        if (isDebugEnabled) {
            logger.debug("Returning back without putting into the gateway sender queue");
        }
        return;
    }
    final GatewaySenderStats stats = getStatistics();
    stats.incEventsReceived();
    if (!checkForDistribution(event, stats)) {
        stats.incEventsNotQueued();
        return;
    }
    // not considering this filter
    if (!this.filter.enqueueEvent(event)) {
        stats.incEventsFiltered();
        return;
    }
    // released by this method or transfers ownership to TmpQueueEvent
    @Released EntryEventImpl clonedEvent = new EntryEventImpl(event, false);
    boolean freeClonedEvent = true;
    try {
        Region region = event.getRegion();
        setModifiedEventId(clonedEvent);
        Object callbackArg = clonedEvent.getRawCallbackArgument();
        if (isDebugEnabled) {
            // We can't deserialize here for logging purposes so don't
            // call getNewValue.
            // event.getNewValue(); // to deserialize the value if necessary
            logger.debug("{} : About to notify {} to perform operation {} for {} callback arg {}", this.isPrimary(), getId(), operation, clonedEvent, callbackArg);
        }
        if (callbackArg instanceof GatewaySenderEventCallbackArgument) {
            GatewaySenderEventCallbackArgument seca = (GatewaySenderEventCallbackArgument) callbackArg;
            if (isDebugEnabled) {
                logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
            }
            if (seca.getOriginatingDSId() == DEFAULT_DISTRIBUTED_SYSTEM_ID) {
                if (isDebugEnabled) {
                    logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                }
                seca.setOriginatingDSId(this.getMyDSId());
                seca.initializeReceipientDSIds(allRemoteDSIds);
            } else {
                // if the dispatcher is GatewaySenderEventCallbackDispatcher (which is the case of WBCL),
                // skip the below check of remoteDSId.
                // Fix for #46517
                AbstractGatewaySenderEventProcessor ep = getEventProcessor();
                if (ep != null && !(ep.getDispatcher() instanceof GatewaySenderEventCallbackDispatcher)) {
                    if (seca.getOriginatingDSId() == this.getRemoteDSId()) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. It is being dropped as remote is originator.", this, seca.getOriginatingDSId(), getMyDSId());
                        }
                        return;
                    } else if (seca.getRecipientDSIds().contains(this.getRemoteDSId())) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}.. It is being dropped as remote ds is already a recipient. Recipients are: {}", this, seca.getOriginatingDSId(), getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                        }
                        return;
                    }
                }
                seca.getRecipientDSIds().addAll(allRemoteDSIds);
            }
        } else {
            GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(callbackArg, this.getMyDSId(), allRemoteDSIds);
            clonedEvent.setCallbackArgument(geCallbackArg);
        }
        if (!this.getLifeCycleLock().readLock().tryLock()) {
            synchronized (this.queuedEventsSync) {
                if (!this.enqueuedAllTempQueueEvents) {
                    if (!this.getLifeCycleLock().readLock().tryLock()) {
                        Object substituteValue = getSubstituteValue(clonedEvent, operation);
                        this.tmpQueuedEvents.add(new TmpQueueEvent(operation, clonedEvent, substituteValue));
                        freeClonedEvent = false;
                        stats.incTempQueueSize();
                        if (isDebugEnabled) {
                            logger.debug("Event : {} is added to TempQueue", clonedEvent);
                        }
                        return;
                    }
                }
            }
            if (this.enqueuedAllTempQueueEvents) {
                this.getLifeCycleLock().readLock().lock();
            }
        }
        try {
            // The sender may have stopped, after we have checked the status in the beginning.
            if (!isRunning()) {
                if (isDebugEnabled) {
                    logger.debug("Returning back without putting into the gateway sender queue");
                }
                return;
            }
            try {
                AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
                if (ev == null) {
                    getStopper().checkCancelInProgress(null);
                    this.getCache().getDistributedSystem().getCancelCriterion().checkCancelInProgress(null);
                    // connecting to the other site (bug #40681)
                    if (ev == null) {
                        throw new GatewayCancelledException("Event processor thread is gone");
                    }
                }
                // Get substitution value to enqueue if necessary
                Object substituteValue = getSubstituteValue(clonedEvent, operation);
                ev.enqueueEvent(operation, clonedEvent, substituteValue);
            } catch (CancelException e) {
                logger.debug("caught cancel exception", e);
                throw e;
            } catch (RegionDestroyedException e) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            }
        } finally {
            this.getLifeCycleLock().readLock().unlock();
        }
    } finally {
        if (freeClonedEvent) {
            // fix for bug 48035
            clonedEvent.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException)

Aggregations

RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)124 CancelException (org.apache.geode.CancelException)41 LocalRegion (org.apache.geode.internal.cache.LocalRegion)37 Region (org.apache.geode.cache.Region)35 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)28 IOException (java.io.IOException)25 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)19 QueryException (org.apache.geode.cache.query.QueryException)16 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)16 ReplyException (org.apache.geode.distributed.internal.ReplyException)16 CacheClosedException (org.apache.geode.cache.CacheClosedException)14 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)14 SelectResults (org.apache.geode.cache.query.SelectResults)13 EventID (org.apache.geode.internal.cache.EventID)13 Test (org.junit.Test)13 Iterator (java.util.Iterator)12 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)12 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)12 QueryService (org.apache.geode.cache.query.QueryService)11