use of org.apache.geode.internal.cache.partitioned.PutAllPRMessage in project geode by apache.
the class PartitionedRegion method tryToSendOnePutAllMessage.
public VersionedObjectList tryToSendOnePutAllMessage(PutAllPRMessage prMsg, InternalDistributedMember currentTarget) throws DataLocationException {
boolean putResult = false;
VersionedObjectList versions = null;
final boolean isLocal = (this.localMaxMemory > 0) && currentTarget.equals(getMyId());
if (isLocal) {
// local
// It might throw retry exception when one key failed
// InternalDS has to be set for each msg
prMsg.initMessage(this, null, false, null);
putResult = prMsg.doLocalPutAll(this, this.getDistributionManager().getDistributionManagerId(), 0L);
versions = prMsg.getVersions();
} else {
PutAllPRMessage.PutAllResponse response = (PutAllPRMessage.PutAllResponse) prMsg.send(currentTarget, this);
PutAllPRMessage.PutAllResult pr = null;
if (response != null) {
this.prStats.incPartitionMessagesSent();
try {
pr = response.waitForResult();
putResult = pr.returnValue;
versions = pr.versions;
} catch (RegionDestroyedException rde) {
if (logger.isDebugEnabled()) {
logger.debug("prMsg.send: caught RegionDestroyedException", rde);
}
throw new RegionDestroyedException(toString(), getFullPath());
} catch (CacheException ce) {
// Fix for bug 36014
throw new PartitionedRegionDistributionException("prMsg.send on " + currentTarget + " failed", ce);
}
} else {
// follow the same behavior of putRemotely()
putResult = true;
}
}
if (!putResult) {
// retry exception when msg failed in waitForResult()
ForceReattemptException fre = new ForceReattemptException("false result in PutAllMessage.send - retrying");
fre.setHash(0);
throw fre;
}
return versions;
}
use of org.apache.geode.internal.cache.partitioned.PutAllPRMessage in project geode by apache.
the class PartitionedTXRegionStub method postPutAll.
/**
* Create PutAllPRMsgs for each bucket, and send them.
*
* @param putallO DistributedPutAllOperation object.
*/
public void postPutAll(DistributedPutAllOperation putallO, VersionedObjectList successfulPuts, LocalRegion r) throws TransactionException {
if (r.getCache().isCacheAtShutdownAll()) {
throw new CacheClosedException("Cache is shutting down");
}
PartitionedRegion pr = (PartitionedRegion) r;
final long startTime = PartitionedRegionStats.startTime();
// build all the msgs by bucketid
HashMap prMsgMap = putallO.createPRMessages();
PutAllPartialResult partialKeys = new PutAllPartialResult(putallO.putAllDataSize);
// this is rebuilt by this method
successfulPuts.clear();
Iterator itor = prMsgMap.entrySet().iterator();
while (itor.hasNext()) {
Map.Entry mapEntry = (Map.Entry) itor.next();
Integer bucketId = (Integer) mapEntry.getKey();
PutAllPRMessage prMsg = (PutAllPRMessage) mapEntry.getValue();
pr.checkReadiness();
try {
VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
// prMsg.saveKeySet(partialKeys);
partialKeys.addKeysAndVersions(versions);
successfulPuts.addAll(versions);
} catch (PutAllPartialResultException pre) {
// sendMsgByBucket applied partial keys
partialKeys.consolidate(pre.getResult());
} catch (Exception ex) {
// If failed at other exception
@Released EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
try {
partialKeys.saveFailedKey(firstEvent.getKey(), ex);
} finally {
firstEvent.release();
}
}
}
pr.prStats.endPutAll(startTime);
if (partialKeys.hasFailure()) {
pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
if (putallO.isBridgeOperation()) {
if (partialKeys.getFailure() instanceof CancelException) {
throw (CancelException) partialKeys.getFailure();
} else {
throw new PutAllPartialResultException(partialKeys);
}
} else {
if (partialKeys.getFailure() instanceof RuntimeException) {
throw (RuntimeException) partialKeys.getFailure();
} else {
throw new RuntimeException(partialKeys.getFailure());
}
}
}
}
use of org.apache.geode.internal.cache.partitioned.PutAllPRMessage in project geode by apache.
the class DistributedPutAllOperation method createPRMessagesNotifyOnly.
/**
* Create PutAllPRMessage for notify only (to adjunct nodes)
*
* @param bucketId create message to send to this bucket
* @return PutAllPRMessage
*/
public PutAllPRMessage createPRMessagesNotifyOnly(int bucketId) {
final EntryEventImpl event = getBaseEvent();
PutAllPRMessage prMsg = new PutAllPRMessage(bucketId, putAllDataSize, true, event.isPossibleDuplicate(), !event.isGenerateCallbacks(), event.getCallbackArgument());
if (event.getContext() != null) {
prMsg.setBridgeContext(event.getContext());
}
// will not recover event id here
for (int i = 0; i < putAllDataSize; i++) {
prMsg.addEntry(putAllData[i]);
}
return prMsg;
}
use of org.apache.geode.internal.cache.partitioned.PutAllPRMessage in project geode by apache.
the class DistributedPutAllOperation method createPRMessages.
/**
* Create PutAllPRMessages for primary buckets out of dpao
*
* @return a HashMap contain PutAllPRMessages, key is bucket id
*/
public HashMap createPRMessages() {
// getFilterRecipients(Collections.EMPTY_SET); // establish filter recipient routing information
HashMap prMsgMap = new HashMap();
final EntryEventImpl event = getBaseEvent();
for (int i = 0; i < putAllDataSize; i++) {
Integer bucketId = putAllData[i].bucketId;
PutAllPRMessage prMsg = (PutAllPRMessage) prMsgMap.get(bucketId);
if (prMsg == null) {
prMsg = new PutAllPRMessage(bucketId.intValue(), putAllDataSize, false, event.isPossibleDuplicate(), !event.isGenerateCallbacks(), event.getCallbackArgument());
prMsg.setTransactionDistributed(event.getRegion().getCache().getTxManager().isDistributed());
// dpao's event's context could be null if it's P2P putAll in PR
if (event.getContext() != null) {
prMsg.setBridgeContext(event.getContext());
}
}
// Modify the event id, assign new thread id and new sequence id
// We have to set fake event id here, because we cannot derive old event id from baseId+idx as
// we
// did in DR's PutAllMessage.
putAllData[i].setFakeEventID();
// we only save the reference in prMsg. No duplicate copy
prMsg.addEntry(putAllData[i]);
prMsgMap.put(bucketId, prMsg);
}
return prMsgMap;
}
use of org.apache.geode.internal.cache.partitioned.PutAllPRMessage in project geode by apache.
the class BucketRegion method performPutAllAdjunctMessaging.
/**
* create a PutAllPRMessage for notify-only and send it to all adjunct nodes. return a set of
* members that should be attached to the operation's reply processor (if any)
*
* @param dpao DistributedPutAllOperation object for PutAllMessage
* @param cacheOpRecipients set of receiver which got cacheUpdateOperation.
* @param adjunctRecipients recipients that must unconditionally get the event
* @param filterRoutingInfo routing information for all members having the region
* @param processor the reply processor, or null if there isn't one
* @return the set of failed recipients
*/
public Set performPutAllAdjunctMessaging(DistributedPutAllOperation dpao, Set cacheOpRecipients, Set adjunctRecipients, FilterRoutingInfo filterRoutingInfo, DirectReplyProcessor processor) {
// create a PutAllPRMessage out of PutAllMessage to send to adjunct nodes
PutAllPRMessage prMsg = dpao.createPRMessagesNotifyOnly(getId());
prMsg.initMessage(this.partitionedRegion, adjunctRecipients, true, processor);
prMsg.setSender(this.partitionedRegion.getDistributionManager().getDistributionManagerId());
// find members who have clients subscribed to this event and add them
// to the recipients list. Also determine if there are any FilterInfo
// routing tables for any of the receivers
// boolean anyWithRouting = false;
Set recipients = null;
Set membersWithRouting = filterRoutingInfo.getMembers();
for (Iterator it = membersWithRouting.iterator(); it.hasNext(); ) {
Object mbr = it.next();
if (!cacheOpRecipients.contains(mbr)) {
// anyWithRouting = true;
if (!adjunctRecipients.contains(mbr)) {
if (recipients == null) {
recipients = new HashSet();
recipients.add(mbr);
}
}
}
}
if (recipients == null) {
recipients = adjunctRecipients;
} else {
recipients.addAll(adjunctRecipients);
}
// Set failures = Collections.EMPTY_SET;
// if (!anyWithRouting) {
Set failures = this.partitionedRegion.getDistributionManager().putOutgoing(prMsg);
return failures;
}
Aggregations