Search in sources :

Example 1 with EmptyRegionFunctionException

use of org.apache.geode.cache.execute.EmptyRegionFunctionException in project geode by apache.

the class PartitionedRegion method executeOnBucketSet.

public ResultCollector executeOnBucketSet(final Function function, PartitionedRegionFunctionExecutor execution, ResultCollector rc, Set<Integer> bucketSet) {
    Set<Integer> actualBucketSet = this.getRegionAdvisor().getBucketSet();
    try {
        bucketSet.retainAll(actualBucketSet);
    } catch (NoSuchElementException ignore) {
    // done
    }
    HashMap<InternalDistributedMember, HashSet<Integer>> memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
    if (memberToBuckets.isEmpty()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing on bucketset : {} executeOnBucketSet Member to buckets map is : {} bucketSet is empty", bucketSet, memberToBuckets);
        }
        throw new EmptyRegionFunctionException(LocalizedStrings.PartitionedRegion_FUNCTION_NOT_EXECUTED_AS_REGION_IS_EMPTY.toLocalizedString());
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing on bucketset : {} executeOnBucketSet Member to buckets map is : {}", bucketSet, memberToBuckets);
        }
    }
    if (memberToBuckets.size() > 1) {
        for (InternalDistributedMember targetNode : memberToBuckets.keySet()) {
            if (!targetNode.equals(getMyId())) {
                for (Integer bucketId : memberToBuckets.get(targetNode)) {
                    Set<ServerBucketProfile> profiles = this.getRegionAdvisor().getClientBucketProfiles(bucketId);
                    if (profiles != null) {
                        for (ServerBucketProfile profile : profiles) {
                            if (profile.getDistributedMember().equals(targetNode)) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("FunctionServiceSingleHop: Found multiple nodes for executing on bucket set.{}", getMyId());
                                }
                                throw new InternalFunctionInvocationTargetException(LocalizedStrings.PartitionedRegion_MULTIPLE_TARGET_NODE_FOUND_FOR.toLocalizedString());
                            }
                        }
                    }
                }
            }
        }
    }
    execution = (PartitionedRegionFunctionExecutor) execution.withFilter(new HashSet());
    while (!execution.getFailedNodes().isEmpty()) {
        Set memberKeySet = memberToBuckets.keySet();
        RetryTimeKeeper retryTime = new RetryTimeKeeper(this.retryTimeout);
        Iterator iterator = memberKeySet.iterator();
        boolean hasRemovedNode = false;
        while (iterator.hasNext()) {
            if (execution.getFailedNodes().contains(((DistributedMember) iterator.next()).getId())) {
                hasRemovedNode = true;
            }
        }
        if (hasRemovedNode) {
            if (retryTime.overMaximum()) {
                PRHARedundancyProvider.timedOut(this, null, null, "doing function execution", this.retryTimeout);
            // NOTREACHED
            }
            retryTime.waitToRetryNode();
            memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
        } else {
            execution.clearFailedNodes();
        }
    }
    Set<InternalDistributedMember> dest = memberToBuckets.keySet();
    if (function.optimizeForWrite() && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(dest) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, dest);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
    }
    boolean isSelf = false;
    execution.setExecutionNodes(dest);
    final Set localBucketSet = memberToBuckets.remove(getMyId());
    if (localBucketSet != null) {
        isSelf = true;
    }
    final HashMap<InternalDistributedMember, FunctionRemoteContext> recipMap = new HashMap<InternalDistributedMember, FunctionRemoteContext>();
    for (InternalDistributedMember recip : dest) {
        FunctionRemoteContext context = new FunctionRemoteContext(function, execution.getArgumentsForMember(recip.getId()), null, memberToBuckets.get(recip), execution.isReExecute(), execution.isFnSerializationReqd());
        recipMap.put(recip, context);
    }
    final LocalResultCollector<?, ?> localRC = execution.getLocalResultCollector(function, rc);
    final DM dm = getDistributionManager();
    final PartitionedRegionFunctionResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this, 0L, localRC, execution.getServerResultSender(), recipMap.isEmpty(), !isSelf, execution.isForwardExceptions(), function, localBucketSet);
    // execute locally and collect the result
    if (isSelf && this.dataStore != null) {
        final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), PartitionedRegion.this, execution.getArgumentsForMember(getMyId().getId()), null, ColocationHelper.constructAndGetAllColocatedLocalDataSet(PartitionedRegion.this, localBucketSet), localBucketSet, resultSender, execution.isReExecute());
        execution.executeFunctionOnLocalNode(function, prContext, resultSender, dm, isTX());
    }
    PartitionedRegionFunctionResultWaiter resultReciever = new PartitionedRegionFunctionResultWaiter(getSystem(), this.getPRId(), localRC, function, resultSender);
    return resultReciever.getPartitionedDataFrom(recipMap, this, execution);
}
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) FunctionRemoteContext(org.apache.geode.internal.cache.execute.FunctionRemoteContext) DM(org.apache.geode.distributed.internal.DM) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException) LowMemoryException(org.apache.geode.cache.LowMemoryException) HashSet(java.util.HashSet) PartitionedRegionFunctionResultWaiter(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultWaiter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionFunctionContextImpl(org.apache.geode.internal.cache.execute.RegionFunctionContextImpl) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with EmptyRegionFunctionException

use of org.apache.geode.cache.execute.EmptyRegionFunctionException in project geode by apache.

the class PartitionedRegion method executeOnAllBuckets.

/**
   * Executes function on all bucket nodes
   * 
   * @return ResultCollector
   * @since GemFire 6.0
   */
private ResultCollector executeOnAllBuckets(final Function function, final PartitionedRegionFunctionExecutor execution, ResultCollector rc, boolean isPRSingleHop) {
    Set<Integer> bucketSet = new HashSet<Integer>();
    Iterator<Integer> itr = this.getRegionAdvisor().getBucketSet().iterator();
    while (itr.hasNext()) {
        try {
            bucketSet.add(itr.next());
        } catch (NoSuchElementException ignore) {
        }
    }
    HashMap<InternalDistributedMember, HashSet<Integer>> memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
    if (memberToBuckets.isEmpty()) {
        throw new EmptyRegionFunctionException(LocalizedStrings.PartitionedRegion_FUNCTION_NOT_EXECUTED_AS_REGION_IS_EMPTY.toLocalizedString());
    }
    while (!execution.getFailedNodes().isEmpty()) {
        Set memberKeySet = memberToBuckets.keySet();
        RetryTimeKeeper retryTime = new RetryTimeKeeper(this.retryTimeout);
        Iterator iterator = memberKeySet.iterator();
        boolean hasRemovedNode = false;
        while (iterator.hasNext()) {
            if (execution.getFailedNodes().contains(((DistributedMember) iterator.next()).getId())) {
                hasRemovedNode = true;
            }
        }
        if (hasRemovedNode) {
            if (retryTime.overMaximum()) {
                PRHARedundancyProvider.timedOut(this, null, null, "doing function execution", this.retryTimeout);
            // NOTREACHED
            }
            retryTime.waitToRetryNode();
            memberToBuckets = FunctionExecutionNodePruner.groupByMemberToBuckets(this, bucketSet, function.optimizeForWrite());
        } else {
            execution.clearFailedNodes();
        }
    }
    Set<InternalDistributedMember> dest = memberToBuckets.keySet();
    execution.validateExecution(function, dest);
    execution.setExecutionNodes(dest);
    boolean isSelf = false;
    final Set<Integer> localBucketSet = memberToBuckets.remove(getMyId());
    if (localBucketSet != null) {
        isSelf = true;
    }
    final HashMap<InternalDistributedMember, FunctionRemoteContext> recipMap = new HashMap<InternalDistributedMember, FunctionRemoteContext>();
    for (InternalDistributedMember recip : memberToBuckets.keySet()) {
        FunctionRemoteContext context = new FunctionRemoteContext(function, execution.getArgumentsForMember(recip.getId()), null, memberToBuckets.get(recip), execution.isReExecute(), execution.isFnSerializationReqd());
        recipMap.put(recip, context);
    }
    final LocalResultCollector<?, ?> localResultCollector = execution.getLocalResultCollector(function, rc);
    final DM dm = getDistributionManager();
    final PartitionedRegionFunctionResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this, 0L, localResultCollector, execution.getServerResultSender(), recipMap.isEmpty(), !isSelf, execution.isForwardExceptions(), function, localBucketSet);
    // execute locally and collect the result
    if (isSelf && this.dataStore != null) {
        final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), PartitionedRegion.this, execution.getArgumentsForMember(getMyId().getId()), null, ColocationHelper.constructAndGetAllColocatedLocalDataSet(PartitionedRegion.this, localBucketSet), localBucketSet, resultSender, execution.isReExecute());
        execution.executeFunctionOnLocalPRNode(function, prContext, resultSender, dm, isTX());
    }
    PartitionedRegionFunctionResultWaiter resultReciever = new PartitionedRegionFunctionResultWaiter(getSystem(), this.getPRId(), localResultCollector, function, resultSender);
    return resultReciever.getPartitionedDataFrom(recipMap, this, execution);
}
Also used : PartitionedRegionFunctionResultWaiter(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultWaiter) 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) FunctionRemoteContext(org.apache.geode.internal.cache.execute.FunctionRemoteContext) DM(org.apache.geode.distributed.internal.DM) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionFunctionContextImpl(org.apache.geode.internal.cache.execute.RegionFunctionContextImpl) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender) NoSuchElementException(java.util.NoSuchElementException) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 NoSuchElementException (java.util.NoSuchElementException)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EmptyRegionFunctionException (org.apache.geode.cache.execute.EmptyRegionFunctionException)2 ResultsSet (org.apache.geode.cache.query.internal.ResultsSet)2 DM (org.apache.geode.distributed.internal.DM)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 FunctionRemoteContext (org.apache.geode.internal.cache.execute.FunctionRemoteContext)2 PartitionedRegionFunctionResultSender (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender)2 PartitionedRegionFunctionResultWaiter (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultWaiter)2 RegionFunctionContextImpl (org.apache.geode.internal.cache.execute.RegionFunctionContextImpl)2 PREntriesIterator (org.apache.geode.internal.cache.partitioned.PREntriesIterator)2 LowMemoryException (org.apache.geode.cache.LowMemoryException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 ServerBucketProfile (org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile)1 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)1