Search in sources :

Example 6 with ReplyException

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

the class IndexCreationMsg method operateOnPartitionedRegion.

/**
   * This method actually operates on the partitioned region and creates given list of indexes from
   * a index creation message.
   * 
   * @param dm distribution manager.
   * @param pr partitioned region on which to create an index.
   * @throws CacheException indicating a cache level error
   * @throws ForceReattemptException if the peer is no longer available
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, ForceReattemptException {
    // region exists
    ReplyException replyEx = null;
    boolean result = false;
    List<Index> indexes = null;
    List<String> failedIndexNames = new ArrayList<String>();
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (IndexCreationData icd : indexDefinitions) {
            sb.append(icd.getIndexName()).append(" ");
        }
        logger.debug("Processing index creation message on this remote partitioned region vm for indexes: {}", sb);
    }
    try {
        indexes = pr.createIndexes(true, indexDefinitions);
    } catch (IndexCreationException e1) {
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), e1);
    } catch (MultiIndexCreationException exx) {
        failedIndexNames.addAll(exx.getExceptionsMap().keySet());
        if (logger.isDebugEnabled()) {
            StringBuffer exceptionMsgs = new StringBuffer();
            for (Exception ex : exx.getExceptionsMap().values()) {
                exceptionMsgs.append(ex.getMessage()).append("\n");
            }
            logger.debug("Got an MultiIndexCreationException with \n: {}", exceptionMsgs);
            logger.debug("{} indexes were created succesfully", failedIndexNames.size());
        }
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), exx);
    }
    if (null == replyEx) {
        result = true;
    }
    if (result) {
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (Index index : indexes) {
            PartitionedIndex prIndex = (PartitionedIndex) index;
            indexBucketsMap.put(prIndex.getName(), prIndex.getNumberOfIndexedBuckets());
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    } else {
        // add the indexes that were successfully created to the map
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (IndexCreationData icd : indexDefinitions) {
            // if the index was successfully created
            if (!failedIndexNames.contains(icd.getIndexName())) {
                PartitionedIndex prIndex = (PartitionedIndex) pr.getIndex(icd.getIndexName());
                indexBucketsMap.put(icd.getIndexName(), prIndex.getNumberOfIndexedBuckets());
            }
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Multi Index creation completed on remote host and has sent the reply to the originating vm.");
    }
    return false;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) ReplyException(org.apache.geode.distributed.internal.ReplyException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException)

Example 7 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException 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 8 with ReplyException

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

the class PRUpdateEntryVersionMessage method operateOnPartitionedRegion.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.partitioned.PartitionMessage# operateOnPartitionedRegion
   * (org.apache.geode.distributed.internal.DistributionManager,
   * org.apache.geode.internal.cache.PartitionedRegion, long)
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, QueryException, DataLocationException, InterruptedException, IOException {
    // release not needed because disallowOffHeapValues called
    final EntryEventImpl event = EntryEventImpl.create(pr, getOperation(), getKey(), null, /* newValue */
    null, /* callbackargs */
    false, /* originRemote - false to force distribution in buckets */
    getSender(), /* eventSender */
    false, /* generateCallbacks */
    false);
    event.disallowOffHeapValues();
    Assert.assertTrue(eventId != null);
    if (this.versionTag != null) {
        event.setVersionTag(this.versionTag);
    }
    event.setEventId(eventId);
    event.setPossibleDuplicate(this.posDup);
    event.setInvokePRCallbacks(false);
    event.setCausedByMessage(this);
    boolean sendReply = true;
    if (!notificationOnly) {
        PartitionedRegionDataStore ds = pr.getDataStore();
        Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
        try {
            Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
            pr.getDataView().updateEntryVersion(event);
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.debug("{}: updateEntryVersionLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
            }
        } catch (EntryNotFoundException eee) {
            // failed = true;
            if (logger.isDebugEnabled()) {
                logger.debug("{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
            }
            sendReply(getSender(), getProcessorId(), dm, null, /*
                                                           * No need to send exception back
                                                           */
            pr, startTime);
            // this prevents us from acknowledging later
            sendReply = false;
        } catch (PrimaryBucketException pbe) {
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), pr, startTime);
            return false;
        }
    }
    return sendReply;
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 9 with ReplyException

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

the class PutAllPRMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws EntryExistsException, ForceReattemptException, DataLocationException {
    boolean sendReply = true;
    InternalDistributedMember eventSender = getSender();
    long lastModified = 0L;
    try {
        result = doLocalPutAll(pr, eventSender, lastModified);
    } catch (ForceReattemptException fre) {
        sendReply(getSender(), getProcessorId(), dm, new ReplyException(fre), pr, startTime);
        return false;
    }
    if (sendReply) {
        sendReply(getSender(), getProcessorId(), dm, null, pr, startTime);
    }
    return false;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 10 with ReplyException

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

the class DestroyMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released EntryEventImpl event = null;
    try {
        if (this.bridgeContext != null) {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote */
            eventSender, true);
            event.setContext(this.bridgeContext);
        } else // bridgeContext != null
        {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
            eventSender, true, /* generateCallbacks */
            false);
        }
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        event.setInvokePRCallbacks(!notificationOnly);
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.posDup);
        PartitionedRegionDataStore ds = r.getDataStore();
        boolean sendReply = true;
        if (!notificationOnly) {
            Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
            try {
                Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(r, null, this.key, null, this.cbArg));
                // try {
                // // the event must show its true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // event.setPartitionMessage(this);
                // r.doCacheWriteBeforeDestroy(event);
                // }
                // finally {
                // event.setOriginRemote(false);
                // }
                event.setCausedByMessage(this);
                r.getDataView().destroyOnRemote(event, true, /* cacheWrite */
                this.expectedOldValue);
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    logger.trace(LogMarker.DM, "{} updated bucket: {} with key: {}", getClass().getName(), bucket, this.key);
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (EntryNotFoundException eee) {
                logger.trace(LogMarker.DM, "{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
                ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
                // this prevents us from acking later
                sendReply = false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                sendReply = false;
            } finally {
                this.versionTag = event.getVersionTag();
            }
        } else {
            @Released EntryEventImpl e2 = createListenerEvent(event, r, dm.getDistributionManagerId());
            try {
                r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != event) {
                    e2.release();
                }
            }
        }
        return sendReply;
    } finally {
        if (event != null) {
            event.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

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