use of org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage in project geode by apache.
the class DistributedRemoveAllOperation method createPRMessagesNotifyOnly.
/**
* Create RemoveAllPRMessage for notify only (to adjunct nodes)
*
* @param bucketId create message to send to this bucket
* @return RemoveAllPRMessage
*/
public RemoveAllPRMessage createPRMessagesNotifyOnly(int bucketId) {
final EntryEventImpl event = getBaseEvent();
RemoveAllPRMessage prMsg = new RemoveAllPRMessage(bucketId, removeAllDataSize, 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 < removeAllDataSize; i++) {
prMsg.addEntry(removeAllData[i]);
}
return prMsg;
}
use of org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage in project geode by apache.
the class DistributedRemoveAllOperation method createPRMessages.
/**
* Create RemoveAllPRMessages for primary buckets out of this op
*
* @return a HashMap contain RemoveAllPRMessages, key is bucket id
*/
public HashMap<Integer, RemoveAllPRMessage> createPRMessages() {
// getFilterRecipients(Collections.EMPTY_SET); // establish filter recipient routing information
HashMap<Integer, RemoveAllPRMessage> prMsgMap = new HashMap<Integer, RemoveAllPRMessage>();
final EntryEventImpl event = getBaseEvent();
for (int i = 0; i < removeAllDataSize; i++) {
Integer bucketId = removeAllData[i].getBucketId();
RemoveAllPRMessage prMsg = prMsgMap.get(bucketId);
if (prMsg == null) {
prMsg = new RemoveAllPRMessage(bucketId.intValue(), removeAllDataSize, 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.
removeAllData[i].setFakeEventID();
// we only save the reference in prMsg. No duplicate copy
prMsg.addEntry(removeAllData[i]);
prMsgMap.put(bucketId, prMsg);
}
return prMsgMap;
}
use of org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage in project geode by apache.
the class PartitionedRegion method postRemoveAllSend.
@Override
public long postRemoveAllSend(DistributedRemoveAllOperation op, VersionedObjectList successfulOps) {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (cache.isCacheAtShutdownAll()) {
throw new CacheClosedException("Cache is shutting down");
}
final long startTime = PartitionedRegionStats.startTime();
// build all the msgs by bucketid
HashMap<Integer, RemoveAllPRMessage> prMsgMap = op.createPRMessages();
PutAllPartialResult partialKeys = new PutAllPartialResult(op.removeAllDataSize);
// clear the successfulOps list since we're actually doing the removes here
// and the basicRemoveAll work was just a way to build the "op" object
Map<Object, VersionTag> keyToVersionMap = new HashMap<Object, VersionTag>(successfulOps.size());
successfulOps.clearVersions();
Iterator<Map.Entry<Integer, RemoveAllPRMessage>> itor = prMsgMap.entrySet().iterator();
while (itor.hasNext()) {
Map.Entry<Integer, RemoveAllPRMessage> mapEntry = itor.next();
Integer bucketId = (Integer) mapEntry.getKey();
RemoveAllPRMessage prMsg = mapEntry.getValue();
checkReadiness();
long then = 0;
if (isDebugEnabled) {
then = System.currentTimeMillis();
}
try {
VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg);
if (versions.size() > 0) {
partialKeys.addKeysAndVersions(versions);
versions.saveVersions(keyToVersionMap);
} else if (!this.concurrencyChecksEnabled) {
// no keys returned if not versioned
Set keys = prMsg.getKeys();
partialKeys.addKeys(keys);
}
} catch (PutAllPartialResultException pre) {
// sendMsgByBucket applied partial keys
if (isDebugEnabled) {
logger.debug("PR.postRemoveAll encountered BulkOpPartialResultException, ", pre);
}
partialKeys.consolidate(pre.getResult());
} catch (Exception ex) {
// If failed at other exception
if (isDebugEnabled) {
logger.debug("PR.postRemoveAll encountered exception at sendMsgByBucket, ", ex);
}
@Released EntryEventImpl firstEvent = prMsg.getFirstEvent(this);
try {
partialKeys.saveFailedKey(firstEvent.getKey(), ex);
} finally {
firstEvent.release();
}
}
if (isDebugEnabled) {
long now = System.currentTimeMillis();
if ((now - then) >= 10000) {
logger.debug("PR.sendMsgByBucket took {} ms", (now - then));
}
}
}
this.prStats.endRemoveAll(startTime);
if (!keyToVersionMap.isEmpty()) {
for (Iterator it = successfulOps.getKeys().iterator(); it.hasNext(); ) {
successfulOps.addVersion(keyToVersionMap.get(it.next()));
}
keyToVersionMap.clear();
}
if (partialKeys.hasFailure()) {
logger.info(LocalizedMessage.create(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { getFullPath(), partialKeys }));
if (op.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());
}
}
}
return -1;
}
use of org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage in project geode by apache.
the class BucketRegion method performRemoveAllAdjunctMessaging.
/**
* create a RemoveAllPRMessage 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 op DistributedRemoveAllOperation object for RemoveAllMessage
* @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 performRemoveAllAdjunctMessaging(DistributedRemoveAllOperation op, Set cacheOpRecipients, Set adjunctRecipients, FilterRoutingInfo filterRoutingInfo, DirectReplyProcessor processor) {
// create a RemoveAllPRMessage out of RemoveAllMessage to send to adjunct nodes
RemoveAllPRMessage prMsg = op.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
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 = this.partitionedRegion.getDistributionManager().putOutgoing(prMsg);
return failures;
}
use of org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage in project geode by apache.
the class PartitionedTXRegionStub method postRemoveAll.
@Override
public void postRemoveAll(DistributedRemoveAllOperation op, VersionedObjectList successfulOps, LocalRegion r) {
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<Integer, RemoveAllPRMessage> prMsgMap = op.createPRMessages();
PutAllPartialResult partialKeys = new PutAllPartialResult(op.removeAllDataSize);
// this is rebuilt by this method
successfulOps.clear();
Iterator<Map.Entry<Integer, RemoveAllPRMessage>> itor = prMsgMap.entrySet().iterator();
while (itor.hasNext()) {
Map.Entry<Integer, RemoveAllPRMessage> mapEntry = itor.next();
Integer bucketId = mapEntry.getKey();
RemoveAllPRMessage prMsg = mapEntry.getValue();
pr.checkReadiness();
try {
VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
// prMsg.saveKeySet(partialKeys);
partialKeys.addKeysAndVersions(versions);
successfulOps.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.endRemoveAll(startTime);
if (partialKeys.hasFailure()) {
pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_RemoveAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
if (op.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());
}
}
}
}
Aggregations