Search in sources :

Example 51 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class PRFunctionStreamingResultCollector method getResult.

@Override
public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
    long timeoutInMillis = unit.toMillis(timeout);
    if (this.resultCollected) {
        throw new FunctionException("Result already collected");
    }
    this.resultCollected = true;
    if (this.hasResult) {
        try {
            long timeBefore = System.currentTimeMillis();
            if (!this.waitForCacheOrFunctionException(timeoutInMillis)) {
                throw new FunctionException("All results not recieved in time provided.");
            }
            long timeAfter = System.currentTimeMillis();
            timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
            if (timeoutInMillis < 0) {
                timeoutInMillis = 0;
            }
            if (!this.execution.getFailedNodes().isEmpty() && !this.execution.isClientServerMode()) {
                // end the rc and clear it
                endResults();
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            if (!this.fn.isHA()) {
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fe = new InternalFunctionInvocationTargetException(fite.getMessage(), this.execution.getFailedNodes());
                throw new FunctionException(fe);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (BucketMovedException e) {
            if (!this.fn.isHA()) {
                // endResults();
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                // endResults();
                clearResults();
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                // endResults();
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (CacheClosedException e) {
            if (!this.fn.isHA()) {
                // endResults();
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                // endResults();
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
                throw new FunctionException(fite);
            } else {
                // endResults();
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (CacheException e) {
            // endResults();
            throw new FunctionException(e);
        } catch (ForceReattemptException e) {
            // the function.
            if (!this.fn.isHA()) {
                throw new FunctionException(e);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.fn);
                } else {
                    newRc = this.execution.execute(this.fn.getId());
                }
                return newRc.getResult();
            }
        }
    }
    // As we have already waited for timeout
    return this.userRC.getResult(timeoutInMillis, unit);
// earlier we expect results to be ready
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalFunctionException(org.apache.geode.internal.cache.execute.InternalFunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionStreamingResultCollector(org.apache.geode.internal.cache.execute.FunctionStreamingResultCollector) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 52 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FetchBulkEntriesMessage method send.

/**
   * Sends a PartitionedRegion message to fetch all the entries for a bucketId
   * 
   * @param recipient the member that the fetch keys message is sent to
   * @param r the PartitionedRegion that contains the bucket
   * @param bucketIds the identity of the buckets that contain the entries to be returned
   * @param regex the regular expression to be evaluated for selecting keys
   * @param allowTombstones
   * @return the processor used to read the returned entries
   * @throws ForceReattemptException if the peer is no longer available
   */
public static FetchBulkEntriesResponse send(InternalDistributedMember recipient, PartitionedRegion r, HashMap<Integer, HashSet> bucketKeys, HashSet<Integer> bucketIds, String regex, boolean allowTombstones) throws ForceReattemptException {
    Assert.assertTrue(recipient != null, "FetchBulkEntriesMessage NULL reply message");
    FetchBulkEntriesResponse p = new FetchBulkEntriesResponse(r.getSystem(), r, recipient);
    FetchBulkEntriesMessage m = new FetchBulkEntriesMessage(recipient, r.getPRId(), p, bucketKeys, bucketIds, regex, allowTombstones);
    Set failures = r.getDistributionManager().putOutgoing(m);
    if (failures != null && failures.size() > 0) {
        throw new ForceReattemptException(LocalizedStrings.FetchEntriesMessage_FAILED_SENDING_0.toLocalizedString(m));
    }
    return p;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException)

Example 53 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FetchEntryMessage method send.

/**
   * Sends a PartitionedRegion {@link org.apache.geode.cache.Region#getEntry(Object)} message
   * 
   * @param recipient the member that the getEntry message is sent to
   * @param r the PartitionedRegion for which getEntry was performed upon
   * @param key the object to which the value should be feteched
   * @return the processor used to fetch the returned value associated with the key
   * @throws ForceReattemptException if the peer is no longer available
   */
public static FetchEntryResponse send(InternalDistributedMember recipient, PartitionedRegion r, final Object key, boolean access) throws ForceReattemptException {
    Assert.assertTrue(recipient != null, "FetchEntryMessage NULL recipient");
    FetchEntryResponse p = new FetchEntryResponse(r.getSystem(), Collections.singleton(recipient), r, key);
    FetchEntryMessage m = new FetchEntryMessage(recipient, r.getPRId(), p, key, access);
    Set failures = r.getDistributionManager().putOutgoing(m);
    if (failures != null && failures.size() > 0) {
        throw new ForceReattemptException(LocalizedStrings.FetchEntryMessage_FAILED_SENDING_0.toLocalizedString(m));
    }
    return p;
}
Also used : Set(java.util.Set) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException)

Example 54 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FetchKeysMessage method sendInterestQuery.

/**
   * 
   * @param recipient
   * @param r
   * @param bucketId
   * @param itype
   * @param arg
   * @return the FetchKeysResponse
   * @throws ForceReattemptException if the peer is no longer available
   */
public static FetchKeysResponse sendInterestQuery(InternalDistributedMember recipient, PartitionedRegion r, Integer bucketId, int itype, Object arg, boolean allowTombstones) throws ForceReattemptException {
    Assert.assertTrue(recipient != null, "FetchKeysMessage NULL recipient");
    FetchKeysMessage tmp = new FetchKeysMessage();
    FetchKeysResponse p = (FetchKeysResponse) tmp.createReplyProcessor(r, Collections.singleton(recipient));
    FetchKeysMessage m = new FetchKeysMessage(recipient, r.getPRId(), p, bucketId, itype, arg, allowTombstones);
    Set failures = r.getDistributionManager().putOutgoing(m);
    if (failures != null && failures.size() > 0) {
        throw new ForceReattemptException(LocalizedStrings.FetchKeysMessage_FAILED_SENDING_0.toLocalizedString(m));
    }
    return p;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException)

Example 55 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FetchKeysMessage method send.

/**
   * Sends a PartitionedRegion message to fetch keys for a bucketId
   * 
   * @param recipient the member that the fetch keys message is sent to
   * @param r the PartitionedRegion that contains the bucket
   * @param bucketId the identity of the bucket that contains the keys to be returned
   * @param allowTombstones whether to include destroyed entries in the result
   * @return the processor used to read the returned keys
   * @throws ForceReattemptException if the peer is no longer available
   */
public static FetchKeysResponse send(InternalDistributedMember recipient, PartitionedRegion r, Integer bucketId, boolean allowTombstones) throws ForceReattemptException {
    Assert.assertTrue(recipient != null, "FetchKeysMessage NULL recipient");
    FetchKeysMessage tmp = new FetchKeysMessage();
    FetchKeysResponse p = (FetchKeysResponse) tmp.createReplyProcessor(r, Collections.singleton(recipient));
    FetchKeysMessage m = new FetchKeysMessage(recipient, r.getPRId(), p, bucketId, InterestType.REGULAR_EXPRESSION, ".*", allowTombstones);
    Set failures = r.getDistributionManager().putOutgoing(m);
    if (failures != null && failures.size() > 0) {
        throw new ForceReattemptException(LocalizedStrings.FetchKeysMessage_FAILED_SENDING_0.toLocalizedString(m));
    }
    return p;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException)

Aggregations

ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)62 Set (java.util.Set)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)13 FunctionException (org.apache.geode.cache.execute.FunctionException)12 ReplyException (org.apache.geode.distributed.internal.ReplyException)11 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)11 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)9 TransactionException (org.apache.geode.cache.TransactionException)8 HashSet (java.util.HashSet)7 CacheException (org.apache.geode.cache.CacheException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)5 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)5 Host (org.apache.geode.test.dunit.Host)5 VM (org.apache.geode.test.dunit.VM)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4