Search in sources :

Example 1 with RemoveAllPRMessage

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

Example 2 with RemoveAllPRMessage

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

Example 3 with RemoveAllPRMessage

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) RemoveAllPRMessage(org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) TimeoutException(org.apache.geode.cache.TimeoutException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) ReplyException(org.apache.geode.distributed.internal.ReplyException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) LowMemoryException(org.apache.geode.cache.LowMemoryException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) TransactionException(org.apache.geode.cache.TransactionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashMap(java.util.HashMap)

Example 4 with RemoveAllPRMessage

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

Example 5 with RemoveAllPRMessage

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());
            }
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) RemoveAllPRMessage(org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage) 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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RemoveAllPRMessage (org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage)6 HashMap (java.util.HashMap)3 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 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1