Search in sources :

Example 1 with PutAllPRMessage

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;
}
Also used : PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 2 with PutAllPRMessage

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());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) CancelException(org.apache.geode.CancelException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) Entry(org.apache.geode.cache.Region.Entry) PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PutAllPRMessage

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;
}
Also used : PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage)

Example 4 with PutAllPRMessage

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;
}
Also used : HashMap(java.util.HashMap) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage)

Example 5 with PutAllPRMessage

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;
}
Also used : PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) LockObject(org.apache.geode.internal.cache.partitioned.LockObject)

Aggregations

PutAllPRMessage (org.apache.geode.internal.cache.partitioned.PutAllPRMessage)6 HashMap (java.util.HashMap)3 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 CancelException (org.apache.geode.CancelException)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 CacheException (org.apache.geode.cache.CacheException)2 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 PartitionedRegionDistributionException (org.apache.geode.cache.PartitionedRegionDistributionException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)2 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)2 TransactionException (org.apache.geode.cache.TransactionException)2 PutAllPartialResult (org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult)2 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1