Search in sources :

Example 56 with CancelException

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

the class RemotePutAllMessage method distribute.

/*
   * this is similar to send() but it selects an initialized replicate that is used to proxy the
   * message
   * 
   */
public static boolean distribute(EntryEventImpl event, PutAllEntryData[] data, int dataCount) {
    boolean successful = false;
    DistributedRegion r = (DistributedRegion) event.getRegion();
    Collection replicates = r.getCacheDistributionAdvisor().adviseInitializedReplicates();
    if (replicates.isEmpty()) {
        return false;
    }
    if (replicates.size() > 1) {
        ArrayList l = new ArrayList(replicates);
        Collections.shuffle(l);
        replicates = l;
    }
    int attempts = 0;
    for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
        InternalDistributedMember replicate = it.next();
        try {
            attempts++;
            final boolean posDup = (attempts > 1);
            PutAllResponse response = send(replicate, event, data, dataCount, false, DistributionManager.SERIAL_EXECUTOR, posDup);
            response.waitForCacheException();
            VersionedObjectList result = response.getResponse();
            // Set successful version tags in PutAllEntryData.
            List successfulKeys = result.getKeys();
            List<VersionTag> versions = result.getVersionTags();
            for (PutAllEntryData putAllEntry : data) {
                Object key = putAllEntry.getKey();
                if (successfulKeys.contains(key)) {
                    int index = successfulKeys.indexOf(key);
                    putAllEntry.versionTag = versions.get(index);
                }
            }
            return true;
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (CancelException e) {
            event.getRegion().getCancelCriterion().checkCancelInProgress(e);
        } catch (CacheException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("RemotePutMessage caught CacheException during distribution", e);
            }
            // not a cancel-exception, so don't complain any more about it
            successful = true;
        } catch (RemoteOperationException e) {
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "RemotePutMessage caught an unexpected exception during distribution", e);
            }
        }
    }
    return successful;
}
Also used : CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Collection(java.util.Collection) EntryVersionsList(org.apache.geode.internal.cache.DistributedPutAllOperation.EntryVersionsList) ArrayList(java.util.ArrayList) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) CancelException(org.apache.geode.CancelException) PutAllEntryData(org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData)

Example 57 with CancelException

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

the class RemoteDestroyMessage method distribute.

public static boolean distribute(EntryEventImpl event, Object expectedOldValue, boolean onlyPersistent) {
    boolean successful = false;
    DistributedRegion r = (DistributedRegion) event.getRegion();
    Collection replicates = onlyPersistent ? r.getCacheDistributionAdvisor().adviseInitializedPersistentMembers().keySet() : r.getCacheDistributionAdvisor().adviseInitializedReplicates();
    if (replicates.isEmpty()) {
        return false;
    }
    if (replicates.size() > 1) {
        ArrayList l = new ArrayList(replicates);
        Collections.shuffle(l);
        replicates = l;
    }
    int attempts = 0;
    for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
        InternalDistributedMember replicate = it.next();
        try {
            attempts++;
            final boolean posDup = (attempts > 1);
            RemoteDestroyReplyProcessor processor = send(replicate, event.getRegion(), event, expectedOldValue, DistributionManager.SERIAL_EXECUTOR, false, posDup);
            processor.waitForCacheException();
            VersionTag versionTag = processor.getVersionTag();
            if (versionTag != null) {
                event.setVersionTag(versionTag);
                if (event.getRegion().getVersionVector() != null) {
                    event.getRegion().getVersionVector().recordVersion(versionTag.getMemberID(), versionTag);
                }
            }
            event.setInhibitDistribution(true);
            return true;
        } catch (EntryNotFoundException e) {
            throw new EntryNotFoundException("" + event.getKey());
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (CancelException e) {
            event.getRegion().getCancelCriterion().checkCancelInProgress(e);
        } catch (CacheException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("RemoteDestroyMessage caught CacheException during distribution", e);
            }
            // not a cancel-exception, so don't complain any more about it
            successful = true;
        } catch (RemoteOperationException e) {
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "RemoteDestroyMessage caught an unexpected exception during distribution", e);
            }
        }
    }
    return successful;
}
Also used : CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Collection(java.util.Collection) CancelException(org.apache.geode.CancelException)

Example 58 with CancelException

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

the class RemotePutMessage method distribute.

/**
   * this is similar to send() but it selects an initialized replicate that is used to proxy the
   * message
   * 
   * @param event represents the current operation
   * @param lastModified lastModified time
   * @param ifNew whether a new entry can be created
   * @param ifOld whether an old entry can be used (updates are okay)
   * @param expectedOldValue the value being overwritten is required to match this value
   * @param requireOldValue whether the old value should be returned
   * @param onlyPersistent send message to persistent members only
   * @return whether the message was successfully distributed to another member
   */
public static boolean distribute(EntryEventImpl event, long lastModified, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, boolean onlyPersistent) {
    boolean successful = false;
    DistributedRegion r = (DistributedRegion) event.getRegion();
    Collection replicates = onlyPersistent ? r.getCacheDistributionAdvisor().adviseInitializedPersistentMembers().keySet() : r.getCacheDistributionAdvisor().adviseInitializedReplicates();
    if (replicates.isEmpty()) {
        return false;
    }
    if (replicates.size() > 1) {
        ArrayList l = new ArrayList(replicates);
        Collections.shuffle(l);
        replicates = l;
    }
    int attempts = 0;
    if (logger.isDebugEnabled()) {
        logger.debug("performing remote put messaging for {}", event);
    }
    for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
        InternalDistributedMember replicate = it.next();
        try {
            attempts++;
            final boolean posDup = (attempts > 1);
            RemotePutResponse response = send(replicate, event.getRegion(), event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue, false, DistributionManager.SERIAL_EXECUTOR, posDup);
            PutResult result = response.waitForResult();
            event.setOldValue(result.oldValue, true);
            event.setOperation(result.op);
            if (result.versionTag != null) {
                event.setVersionTag(result.versionTag);
                if (event.getRegion().getVersionVector() != null) {
                    event.getRegion().getVersionVector().recordVersion(result.versionTag.getMemberID(), result.versionTag);
                }
            }
            event.setInhibitDistribution(true);
            return true;
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (CancelException e) {
            event.getRegion().getCancelCriterion().checkCancelInProgress(e);
        } catch (CacheException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("RemotePutMessage caught CacheException during distribution", e);
            }
            // not a cancel-exception, so don't complain any more about it
            successful = true;
        } catch (RemoteOperationException e) {
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "RemotePutMessage caught an unexpected exception during distribution", e);
            }
        }
    }
    return successful;
}
Also used : CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) Collection(java.util.Collection) CancelException(org.apache.geode.CancelException)

Example 59 with CancelException

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

the class TXRegionState method buildCompleteMessage.

void buildCompleteMessage(LocalRegion r, TXCommitMessage msg) {
    try {
        if (!this.entryMods.isEmpty()) {
            msg.startRegion(r, entryMods.size());
            Iterator it = this.entryMods.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
                Object eKey = me.getKey();
                TXEntryState txes = (TXEntryState) me.getValue();
                txes.buildCompleteMessage(r, eKey, msg, this.otherMembers);
            }
            msg.finishRegionComplete();
        }
    } catch (RegionDestroyedException ex) {
    // region was destroyed out from under us; after conflict checking
    // passed. So act as if the region destroy happened right after the
    // commit. We act this way by doing nothing; including distribution
    // of this region's commit data.
    } catch (CancelException ex) {
    // cache was closed out from under us; after conflict checking
    // passed. So do nothing.
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) CancelException(org.apache.geode.CancelException)

Example 60 with CancelException

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

the class TXRegionState method populateDistTxEntryStateList.

public boolean populateDistTxEntryStateList(ArrayList<DistTxThinEntryState> entryStateList) {
    String regionFullPath = this.getRegion().getFullPath();
    try {
        if (!this.entryMods.isEmpty()) {
            // [DISTTX] TODO Sort this first
            for (Entry<Object, TXEntryState> em : this.entryMods.entrySet()) {
                Object mKey = em.getKey();
                TXEntryState txes = em.getValue();
                DistTxThinEntryState thinEntryState = txes.getDistTxEntryStates();
                entryStateList.add(thinEntryState);
                if (logger.isDebugEnabled()) {
                    logger.debug("TXRegionState.populateDistTxEntryStateList Added " + thinEntryState + " for key=" + mKey + " ,op=" + txes.opToString() + " ,region=" + regionFullPath);
                }
            }
        }
        return true;
    } catch (RegionDestroyedException ex) {
    // region was destroyed out from under us; after conflict checking
    // passed. So act as if the region destroy happened right after the
    // commit. We act this way by doing nothing; including distribution
    // of this region's commit data.
    } catch (CancelException ex) {
    // cache was closed out from under us; after conflict checking
    // passed. So do nothing.
    }
    if (logger.isDebugEnabled()) {
        logger.debug("TXRegionState.populateDistTxEntryStateList Got exception for region " + regionFullPath);
    }
    return false;
}
Also used : CancelException(org.apache.geode.CancelException) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

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