Search in sources :

Example 41 with RegionDestroyedException

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

the class PartitionedRegion method containsKeyInBucket.

boolean containsKeyInBucket(final InternalDistributedMember targetNode, final Integer bucketIdInt, final Object key, boolean valueCheck) {
    final int retryAttempts = calcRetry();
    if (logger.isDebugEnabled()) {
        logger.debug("containsKeyInBucket: {}{} ({}) from: {} bucketId={}", (valueCheck ? "ValueForKey key=" : "Key key="), key, key.hashCode(), targetNode, bucketStringForLogs(bucketIdInt));
    }
    boolean ret;
    int count = 0;
    RetryTimeKeeper retryTime = null;
    InternalDistributedMember retryNode = targetNode;
    while (count <= retryAttempts) {
        // Every continuation should check for DM cancellation
        if (retryNode == null) {
            checkReadiness();
            if (retryTime == null) {
                retryTime = new RetryTimeKeeper(this.retryTimeout);
            }
            if (retryTime.overMaximum()) {
                break;
            }
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            // No storage found for bucket, early out preventing hot loop, bug 36819
            if (retryNode == null) {
                // Prefer closed style exceptions over empty result
                checkShutdown();
                return false;
            }
            continue;
        }
        // retryNode != null
        try {
            final boolean loc = retryNode.equals(getMyId());
            if (loc) {
                if (valueCheck) {
                    ret = this.dataStore.containsValueForKeyLocally(bucketIdInt, key);
                } else {
                    ret = this.dataStore.containsKeyLocally(bucketIdInt, key);
                }
            } else {
                if (valueCheck) {
                    ret = containsValueForKeyRemotely(retryNode, bucketIdInt, key);
                } else {
                    ret = containsKeyRemotely(retryNode, bucketIdInt, key);
                }
            }
            return ret;
        } catch (PRLocallyDestroyedException pde) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: Encountered PRLocallyDestroyedException", pde);
            }
            checkReadiness();
        } catch (ForceReattemptException prce) {
            prce.checkKey(key);
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
            }
            checkReadiness();
            InternalDistributedMember lastNode = retryNode;
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            if (lastNode.equals(retryNode)) {
                if (retryTime == null) {
                    retryTime = new RetryTimeKeeper(this.retryTimeout);
                }
                if (retryTime.overMaximum()) {
                    break;
                }
                retryTime.waitToRetryNode();
            }
        } catch (PrimaryBucketException notPrimary) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
            }
            getRegionAdvisor().notPrimary(bucketIdInt, retryNode);
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
        } catch (RegionDestroyedException rde) {
            if (!rde.getRegionFullPath().equals(getFullPath())) {
                throw new RegionDestroyedException(toString(), getFullPath(), rde);
            }
        }
        // It's possible this is a GemFire thread e.g. ServerConnection
        // which got to this point because of a distributed system shutdown or
        // region closure which uses interrupt to break any sleep() or wait()
        // calls
        // e.g. waitForPrimary
        checkShutdown();
        count++;
        if (count == 1) {
            this.prStats.incContainsKeyValueOpsRetried();
        }
        this.prStats.incContainsKeyValueRetries();
    }
    StringId msg = null;
    if (valueCheck) {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_VALUE_FOR_KEY_IN_1_ATTEMPTS;
    } else {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_KEY_IN_1_ATTEMPTS;
    }
    Integer countInteger = count;
    // Fix for bug 36014
    PartitionedRegionDistributionException e = null;
    if (logger.isDebugEnabled()) {
        e = new PartitionedRegionDistributionException(msg.toLocalizedString(countInteger));
    }
    logger.warn(LocalizedMessage.create(msg, countInteger), e);
    return false;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) StringId(org.apache.geode.i18n.StringId) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 42 with RegionDestroyedException

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

the class PartitionedRegion method getDataRegionForWrite.

@Override
public LocalRegion getDataRegionForWrite(KeyInfo keyInfo) {
    BucketRegion br = null;
    final Object entryKey = keyInfo.getKey();
    try {
        final int retryAttempts = calcRetry();
        // TODO provide appropriate Operation and arg
        int bucketId = keyInfo.getBucketId();
        if (bucketId == KeyInfo.UNKNOWN_BUCKET) {
            bucketId = PartitionedRegionHelper.getHashKey(this, null, entryKey, keyInfo.getValue(), keyInfo.getCallbackArg());
            keyInfo.setBucketId(bucketId);
        }
        int count = 0;
        while (count <= retryAttempts) {
            try {
                PartitionedRegionDataStore ds = getDataStore();
                if (ds == null) {
                    throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_ON_DATASTORE.toLocalizedString());
                }
                br = ds.getInitializedBucketWithKnownPrimaryForId(entryKey, bucketId);
                break;
            } catch (ForceReattemptException ignore) {
                // create a new bucket
                InternalDistributedMember member = createBucket(bucketId, 0, null);
                if (!getMyId().equals(member) && keyInfo.isCheckPrimary()) {
                    throw new PrimaryBucketException("Bucket " + bucketId + " is not primary. Current primary holder is " + member);
                }
                count++;
            }
        }
        Assert.assertTrue(br != null, "Could not create storage for Entry");
        if (keyInfo.isCheckPrimary()) {
            br.checkForPrimary();
        }
    } catch (PrimaryBucketException pbe) {
        throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(), pbe);
    } catch (RegionDestroyedException ignore) {
        // TODO: why is this purposely not wrapping the original cause?
        throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(entryKey));
    }
    return br;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 43 with RegionDestroyedException

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

the class PartitionMessage method process.

/**
   * Upon receipt of the message, both process the message and send an acknowledgement, not
   * necessarily in that order. Note: Any hang in this message may cause a distributed deadlock for
   * those threads waiting for an acknowledgement.
   * 
   * @throws PartitionedRegionException if the region does not exist (typically, if it has been
   *         destroyed)
   */
@Override
public void process(final DistributionManager dm) {
    Throwable thr = null;
    boolean sendReply = true;
    PartitionedRegion pr = null;
    long startTime = 0;
    EntryLogger.setSource(getSender(), "PR");
    try {
        if (checkCacheClosing(dm) || checkDSClosing(dm)) {
            thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
            return;
        }
        pr = getPartitionedRegion();
        if (pr == null && failIfRegionMissing()) {
            // if the distributed system is disconnecting, don't send a reply saying
            // the partitioned region can't be found (bug 36585)
            thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_0_COULD_NOT_FIND_PARTITIONED_REGION_WITH_ID_1.toLocalizedString(dm.getDistributionManagerId(), regionId));
            // reply sent in finally block below
            return;
        }
        if (pr != null) {
            startTime = getStartPartitionMessageProcessingTime(pr);
        }
        thr = UNHANDLED_EXCEPTION;
        InternalCache cache = getInternalCache();
        if (cache == null) {
            throw new ForceReattemptException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString());
        }
        TXManagerImpl txMgr = getTXManagerImpl(cache);
        TXStateProxy tx = txMgr.masqueradeAs(this);
        if (tx == null) {
            sendReply = operateOnPartitionedRegion(dm, pr, startTime);
        } else {
            try {
                if (txMgr.isClosed()) {
                    // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
                    sendReply = false;
                } else if (tx.isInProgress()) {
                    sendReply = operateOnPartitionedRegion(dm, pr, startTime);
                    tx.updateProxyServer(this.getSender());
                }
            } finally {
                txMgr.unmasquerade(tx);
            }
        }
        thr = null;
    } catch (ForceReattemptException fre) {
        thr = fre;
    } catch (DataLocationException fre) {
        thr = new ForceReattemptException(fre.getMessage(), fre);
    } catch (DistributedSystemDisconnectedException se) {
        // bug 37026: this is too noisy...
        // throw new CacheClosedException("remote system shutting down");
        // thr = se; cache is closed, no point trying to send a reply
        thr = null;
        sendReply = false;
        if (logger.isDebugEnabled()) {
            logger.debug("shutdown caught, abandoning message: {}", se.getMessage(), se);
        }
    } catch (RegionDestroyedException | RegionNotFoundException rde) {
        // [bruce] RDE does not always mean that the sender's region is also
        // destroyed, so we must send back an exception. If the sender's
        // region is also destroyed, who cares if we send it an exception
        // if (pr != null && pr.isClosed) {
        thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_REGION_IS_DESTROYED_IN_0.toLocalizedString(dm.getDistributionManagerId()), rde);
    // }
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        // log the exception at fine level if there is no reply to the message
        thr = null;
        if (sendReply) {
            if (!checkDSClosing(dm)) {
                thr = t;
            } else {
                // don't pass arbitrary runtime exceptions and errors back if this
                // cache/vm is closing
                thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_DISTRIBUTED_SYSTEM_IS_DISCONNECTING.toLocalizedString());
            }
        }
        if (logger.isTraceEnabled(LogMarker.DM) && t instanceof RuntimeException) {
            logger.trace(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
        }
    } finally {
        if (sendReply) {
            ReplyException rex = null;
            if (thr != null) {
                // don't transmit the exception if this message was to a listener
                // and this listener is shutting down
                boolean excludeException = this.notificationOnly && ((thr instanceof CancelException) || (thr instanceof ForceReattemptException));
                if (!excludeException) {
                    rex = new ReplyException(thr);
                }
            }
            // Send the reply if the operateOnPartitionedRegion returned true
            sendReply(getSender(), this.processorId, dm, rex, pr, startTime);
            EntryLogger.clearSource();
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) DataLocationException(org.apache.geode.internal.cache.DataLocationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException)

Example 44 with RegionDestroyedException

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

the class IndexCreationMsg method process.

/**
   * Process this index creation message on the receiver.
   */
@Override
public void process(final DistributionManager dm) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    Throwable thr = null;
    boolean sendReply = true;
    PartitionedRegion pr = null;
    try {
        if (isDebugEnabled) {
            logger.debug("Trying to get pr with id: {}", this.regionId);
        }
        try {
            if (isDebugEnabled) {
                logger.debug("Again trying to get pr with id : {}", this.regionId);
            }
            pr = PartitionedRegion.getPRFromId(this.regionId);
            if (isDebugEnabled) {
                logger.debug("Index creation message got the pr {}", pr);
            }
            if (null == pr) {
                boolean wait = true;
                int attempts = 0;
                while (wait && attempts < 30) {
                    // max 30 seconds of wait.
                    dm.getCancelCriterion().checkCancelInProgress(null);
                    if (isDebugEnabled) {
                        logger.debug("Waiting for Partitioned Region to be intialized with id {}for processing index creation messages", this.regionId);
                    }
                    try {
                        boolean interrupted = Thread.interrupted();
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            interrupted = true;
                            dm.getCancelCriterion().checkCancelInProgress(e);
                        } finally {
                            if (interrupted)
                                Thread.currentThread().interrupt();
                        }
                        pr = PartitionedRegion.getPRFromId(this.regionId);
                        if (null != pr) {
                            wait = false;
                            if (isDebugEnabled) {
                                logger.debug("Indexcreation message got the pr {}", pr);
                            }
                        }
                        attempts++;
                    } catch (CancelException ignorAndLoopWait) {
                        if (isDebugEnabled) {
                            logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
                        }
                    }
                }
            }
        } catch (CancelException letPRInitialized) {
            // to the PR being initialized.
            if (logger.isDebugEnabled()) {
                logger.debug("Waiting for notification from pr being properly created on {}", this.regionId);
            }
            boolean wait = true;
            while (wait) {
                dm.getCancelCriterion().checkCancelInProgress(null);
                try {
                    boolean interrupted = Thread.interrupted();
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        interrupted = true;
                        dm.getCancelCriterion().checkCancelInProgress(e);
                    } finally {
                        if (interrupted)
                            Thread.currentThread().interrupt();
                    }
                    pr = PartitionedRegion.getPRFromId(this.regionId);
                    wait = false;
                    if (logger.isDebugEnabled()) {
                        logger.debug("Indexcreation message got the pr {}", pr);
                    }
                } catch (CancelException ignorAndLoopWait) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
                    }
                }
            }
        }
        if (pr == null) /* && failIfRegionMissing() */
        {
            String msg = LocalizedStrings.IndexCreationMsg_COULD_NOT_GET_PARTITIONED_REGION_FROM_ID_0_FOR_MESSAGE_1_RECEIVED_ON_MEMBER_2_MAP_3.toLocalizedString(new Object[] { Integer.valueOf(this.regionId), this, dm.getId(), PartitionedRegion.dumpPRId() });
            throw new PartitionedRegionException(msg, new RegionNotFoundException(msg));
        }
        sendReply = operateOnPartitionedRegion(dm, pr, 0);
    } catch (PRLocallyDestroyedException pre) {
        if (isDebugEnabled) {
            logger.debug("Region is locally Destroyed ");
        }
        thr = pre;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        // log the exception at fine level if there is no reply to the message
        if (this.processorId == 0) {
            logger.debug("{} exception while processing message:{}", this, t.getMessage(), t);
        } else if (logger.isDebugEnabled(LogMarker.DM) && (t instanceof RuntimeException)) {
            logger.debug(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
        }
        if (t instanceof RegionDestroyedException && pr != null) {
            if (pr.isClosed) {
                logger.info(LocalizedMessage.create(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_THROWING_REGIONDESTROYEDEXCEPTION_FOR__0, pr));
                thr = new RegionDestroyedException(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_ON_0.toLocalizedString(dm.getId()), pr.getFullPath());
            }
        } else {
            thr = t;
        }
    } finally {
        if (sendReply && this.processorId != 0) {
            ReplyException rex = null;
            if (thr != null) {
                rex = new ReplyException(thr);
            }
            sendReply(getSender(), this.processorId, dm, rex, pr, 0);
        }
    }
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException)

Example 45 with RegionDestroyedException

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

the class DumpB2NRegion method process.

@Override
public void process(final DistributionManager dm) {
    PartitionedRegion pr = null;
    // Get the region, or die trying...
    final long finish = System.currentTimeMillis() + 10 * 1000;
    try {
        for (; ; ) {
            dm.getCancelCriterion().checkCancelInProgress(null);
            // pr = null; (redundant assignment)
            pr = PartitionedRegion.getPRFromId(this.regionId);
            if (pr != null) {
                break;
            }
            if (System.currentTimeMillis() > finish) {
                ReplyException rex = new ReplyException(new TimeoutException("Waited too long for region to initialize"));
                sendReply(getSender(), this.processorId, dm, rex, null, 0);
                return;
            }
            // wait a little
            boolean interrupted = Thread.interrupted();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                interrupted = true;
                pr.checkReadiness();
            } finally {
                if (interrupted)
                    Thread.currentThread().interrupt();
            }
        }
        // Now, wait for the PR to finish initializing
        pr.waitForData();
        // OK, now it's safe to process this.
        super.process(dm);
    } catch (CancelException e) {
        sendReply(this.sender, this.processorId, dm, new ReplyException(e), pr, 0);
    } catch (PRLocallyDestroyedException e) {
        sendReply(this.sender, this.processorId, dm, new ReplyException(e), pr, 0);
        return;
    } catch (RegionDestroyedException rde) {
        sendReply(this.sender, this.processorId, dm, new ReplyException(rde), pr, 0);
        return;
    }
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException) TimeoutException(org.apache.geode.cache.TimeoutException)

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