Search in sources :

Example 1 with BucketMovedException

use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.

the class SingleHopClientExecutor method submitAllHA.

static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    boolean reexecute = false;
    if (callableTasks != null && !callableTasks.isEmpty()) {
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            GemFireException functionExecutionException = null;
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    fut.get();
                    if (isDebugEnabled) {
                        logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
                    }
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        reexecute = true;
                        failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            rc.clearResults();
                        } else {
                            if (ee.getCause().getCause() != null) {
                                functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
                            } else {
                                functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
                            }
                        }
                    } else if (ee.getCause() instanceof FunctionException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
                        }
                        FunctionException fe = (FunctionException) ee.getCause();
                        if (isHA) {
                            throw fe;
                        } else {
                            functionExecutionException = fe;
                        }
                    } else if (ee.getCause() instanceof ServerOperationException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        if (isHA) {
                            throw soe;
                        } else {
                            functionExecutionException = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            reexecute = true;
                            rc.clearResults();
                        } else {
                            functionExecutionException = (ServerConnectivityException) ee.getCause();
                        }
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            if (functionExecutionException != null) {
                throw functionExecutionException;
            }
        }
    }
    return reexecute;
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalGemFireException(org.apache.geode.InternalGemFireException) GemFireException(org.apache.geode.GemFireException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BucketMovedException

use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.

the class PRFunctionStreamingResultCollector method getResult.

@Override
public Object getResult() throws FunctionException {
    if (this.resultCollected) {
        throw new FunctionException("Result already collected");
    }
    this.resultCollected = true;
    if (this.hasResult) {
        try {
            this.waitForCacheOrFunctionException(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();
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            // the function.
            if (!execution.getWaitOnExceptionFlag()) {
                if (!this.fn.isHA()) {
                    throw new FunctionException(fite);
                } else if (execution.isClientServerMode()) {
                    clearResults();
                    FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.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();
                }
            }
        } catch (BucketMovedException e) {
            if (!execution.getWaitOnExceptionFlag()) {
                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());
                    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();
                }
            }
        } catch (CacheClosedException e) {
            if (!execution.getWaitOnExceptionFlag()) {
                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();
                }
            }
        } 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();
            }
        }
    }
    return this.userRC.getResult();
}
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 3 with BucketMovedException

use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.

the class AbstractGatewaySender method waitUntilFlushed.

public boolean waitUntilFlushed(long timeout, TimeUnit unit) throws InterruptedException {
    boolean result = false;
    if (isParallel()) {
        try {
            WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this, timeout, unit, true);
            result = coordinator.waitUntilFlushed();
        } catch (BucketMovedException | CancelException | RegionDestroyedException e) {
            logger.warn(LocalizedStrings.AbstractGatewaySender_CAUGHT_EXCEPTION_ATTEMPTING_WAIT_UNTIL_FLUSHED_RETRYING.toLocalizedString(), e);
            throw e;
        } catch (Throwable t) {
            logger.warn(LocalizedStrings.AbstractGatewaySender_CAUGHT_EXCEPTION_ATTEMPTING_WAIT_UNTIL_FLUSHED_RETURNING.toLocalizedString(), t);
            throw new InternalGemFireError(t);
        }
        return result;
    } else {
        // Serial senders are currently not supported
        throw new UnsupportedOperationException(LocalizedStrings.AbstractGatewaySender_WAIT_UNTIL_FLUSHED_NOT_SUPPORTED_FOR_SERIAL_SENDERS.toLocalizedString());
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CancelException(org.apache.geode.CancelException) WaitUntilParallelGatewaySenderFlushedCoordinator(org.apache.geode.internal.cache.wan.parallel.WaitUntilParallelGatewaySenderFlushedCoordinator) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 4 with BucketMovedException

use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.

the class BucketRegionQueue method waitUntilFlushed.

public boolean waitUntilFlushed(long latestQueuedKey, long timeout, TimeUnit unit) throws InterruptedException {
    long then = System.currentTimeMillis();
    if (logger.isDebugEnabled()) {
        logger.debug("BucketRegionQueue: waitUntilFlushed bucket=" + getId() + "; latestQueuedKey=" + latestQueuedKey + "; timeout=" + timeout + "; unit=" + unit);
    }
    boolean result = false;
    // Wait until latestAcknowledgedKey > latestQueuedKey or the queue is empty
    if (this.initialized) {
        long nanosRemaining = unit.toNanos(timeout);
        long endTime = System.nanoTime() + nanosRemaining;
        while (nanosRemaining > 0) {
            try {
                if (latestAcknowledgedKey.get() > latestQueuedKey || isEmpty()) {
                    result = true;
                    break;
                }
            } catch (RegionDestroyedException e) {
                if (this.isBucketDestroyed()) {
                    getCancelCriterion().checkCancelInProgress(e);
                    throw new BucketMovedException(this.getFullPath());
                }
            }
            Thread.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(nanosRemaining) + 1, 100));
            nanosRemaining = endTime - System.nanoTime();
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("BucketRegionQueue: waitUntilFlushed completed bucket=" + getId() + "; duration=" + (System.currentTimeMillis() - then) + "; result=" + result);
    }
    return result;
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException)

Example 5 with BucketMovedException

use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.

the class PartitionedIndex method getBucketIndex.

/**
   * Returns the index for the bucket.
   */
public static AbstractIndex getBucketIndex(PartitionedRegion pr, String indexName, Integer bId) throws QueryInvocationTargetException {
    try {
        pr.checkReadiness();
    } catch (Exception ex) {
        throw new QueryInvocationTargetException(ex.getMessage());
    }
    PartitionedRegionDataStore prds = pr.getDataStore();
    BucketRegion bukRegion;
    bukRegion = (BucketRegion) prds.getLocalBucketById(bId);
    if (bukRegion == null) {
        throw new BucketMovedException("Bucket not found for the id :" + bId);
    }
    AbstractIndex index = null;
    if (bukRegion.getIndexManager() != null) {
        index = (AbstractIndex) (bukRegion.getIndexManager().getIndex(indexName));
    } else {
        if (pr.getCache().getLogger().fineEnabled()) {
            pr.getCache().getLogger().fine("Index Manager not found for the bucket region " + bukRegion.getFullPath() + " unable to fetch the index " + indexName);
        }
        throw new QueryInvocationTargetException("Index Manager not found, " + " unable to fetch the index " + indexName);
    }
    return index;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) QueryException(org.apache.geode.cache.query.QueryException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Aggregations

BucketMovedException (org.apache.geode.internal.cache.execute.BucketMovedException)8 FunctionException (org.apache.geode.cache.execute.FunctionException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)3 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)3 CacheException (org.apache.geode.cache.CacheException)2 ResultCollector (org.apache.geode.cache.execute.ResultCollector)2 QueryException (org.apache.geode.cache.query.QueryException)2 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)2 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)2 FunctionStreamingResultCollector (org.apache.geode.internal.cache.execute.FunctionStreamingResultCollector)2 InternalFunctionException (org.apache.geode.internal.cache.execute.InternalFunctionException)2 Iterator (java.util.Iterator)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CancelException (org.apache.geode.CancelException)1 GemFireException (org.apache.geode.GemFireException)1