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;
}
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;
}
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;
}
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.
}
}
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;
}
Aggregations