Search in sources :

Example 6 with TransactionDataNotColocatedException

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

the class MultiRegionFunctionExecutor method validateExecution.

@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = null;
    for (Region r : regions) {
        cache = (InternalCache) r.getCache();
        break;
    }
    if (cache != null && cache.getTxManager().getTXState() != null) {
        if (targetMembers.size() > 1) {
            throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_ON_MORE_THAN_ONE_NODE.toLocalizedString());
        } else {
            assert targetMembers.size() == 1;
            DistributedMember funcTarget = (DistributedMember) targetMembers.iterator().next();
            DistributedMember target = cache.getTxManager().getTXState().getTarget();
            if (target == null) {
                cache.getTxManager().getTXState().setTarget(funcTarget);
            } else if (!target.equals(funcTarget)) {
                throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_EXECUTION_NOT_COLOCATED_0_1.toLocalizedString(target, funcTarget));
            }
        }
    }
    if (function.optimizeForWrite() && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(targetMembers) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, targetMembers);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 7 with TransactionDataNotColocatedException

use of org.apache.geode.cache.TransactionDataNotColocatedException 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 8 with TransactionDataNotColocatedException

use of org.apache.geode.cache.TransactionDataNotColocatedException 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 9 with TransactionDataNotColocatedException

use of org.apache.geode.cache.TransactionDataNotColocatedException 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 10 with TransactionDataNotColocatedException

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

the class PartitionedRegion method destroyRemotely.

/**
   * Destroy the entry on the remote node.
   * 
   * @param recipient the member id of the receiver of the message
   * @param bucketId the idenity of the bucket
   * @param event the event prompting this request
   * @param expectedOldValue if not null, then destroy only if entry exists and current value is
   *        equal to expectedOldValue
   * @throws EntryNotFoundException if entry not found OR if expectedOldValue is non-null and
   *         doesn't equal the current value
   * @throws PrimaryBucketException if the bucket on that node is not the primary copy
   * @throws ForceReattemptException if the peer is no longer available
   */
public void destroyRemotely(DistributedMember recipient, Integer bucketId, EntryEventImpl event, Object expectedOldValue) throws EntryNotFoundException, PrimaryBucketException, ForceReattemptException {
    DestroyResponse response = DestroyMessage.send(recipient, this, event, expectedOldValue);
    if (response != null) {
        this.prStats.incPartitionMessagesSent();
        try {
            response.waitForCacheException();
            event.setVersionTag(response.getVersionTag());
        } catch (EntryNotFoundException enfe) {
            throw enfe;
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (TransactionDataRebalancedException e) {
            throw e;
        } catch (CacheException ce) {
            throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
        } catch (RegionDestroyedException ignore) {
            throw new RegionDestroyedException(toString(), getFullPath());
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) DestroyResponse(org.apache.geode.internal.cache.partitioned.DestroyMessage.DestroyResponse) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Aggregations

TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)27 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)11 CacheException (org.apache.geode.cache.CacheException)10 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)10 TransactionException (org.apache.geode.cache.TransactionException)10 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 ArrayList (java.util.ArrayList)8 CustId (org.apache.geode.internal.cache.execute.data.CustId)7 CommitConflictException (org.apache.geode.cache.CommitConflictException)6 Region (org.apache.geode.cache.Region)6 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)6 RemoteOperationException (org.apache.geode.internal.cache.RemoteOperationException)6 Customer (org.apache.geode.internal.cache.execute.data.Customer)6 Collection (java.util.Collection)5 CancelException (org.apache.geode.CancelException)5 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)5 NamingException (javax.naming.NamingException)4 RollbackException (javax.transaction.RollbackException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4