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;
}
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();
}
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());
}
}
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;
}
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;
}
Aggregations