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);
}
}
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;
}
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;
}
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;
}
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());
}
}
}
Aggregations