use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class PartitionMessage method process.
/**
* Upon receipt of the message, both process the message and send an acknowledgement, not
* necessarily in that order. Note: Any hang in this message may cause a distributed deadlock for
* those threads waiting for an acknowledgement.
*
* @throws PartitionedRegionException if the region does not exist (typically, if it has been
* destroyed)
*/
@Override
public void process(final DistributionManager dm) {
Throwable thr = null;
boolean sendReply = true;
PartitionedRegion pr = null;
long startTime = 0;
EntryLogger.setSource(getSender(), "PR");
try {
if (checkCacheClosing(dm) || checkDSClosing(dm)) {
thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
return;
}
pr = getPartitionedRegion();
if (pr == null && failIfRegionMissing()) {
// if the distributed system is disconnecting, don't send a reply saying
// the partitioned region can't be found (bug 36585)
thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_0_COULD_NOT_FIND_PARTITIONED_REGION_WITH_ID_1.toLocalizedString(dm.getDistributionManagerId(), regionId));
// reply sent in finally block below
return;
}
if (pr != null) {
startTime = getStartPartitionMessageProcessingTime(pr);
}
thr = UNHANDLED_EXCEPTION;
InternalCache cache = getInternalCache();
if (cache == null) {
throw new ForceReattemptException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString());
}
TXManagerImpl txMgr = getTXManagerImpl(cache);
TXStateProxy tx = txMgr.masqueradeAs(this);
if (tx == null) {
sendReply = operateOnPartitionedRegion(dm, pr, startTime);
} else {
try {
if (txMgr.isClosed()) {
// NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
sendReply = false;
} else if (tx.isInProgress()) {
sendReply = operateOnPartitionedRegion(dm, pr, startTime);
tx.updateProxyServer(this.getSender());
}
} finally {
txMgr.unmasquerade(tx);
}
}
thr = null;
} catch (ForceReattemptException fre) {
thr = fre;
} catch (DataLocationException fre) {
thr = new ForceReattemptException(fre.getMessage(), fre);
} catch (DistributedSystemDisconnectedException se) {
// bug 37026: this is too noisy...
// throw new CacheClosedException("remote system shutting down");
// thr = se; cache is closed, no point trying to send a reply
thr = null;
sendReply = false;
if (logger.isDebugEnabled()) {
logger.debug("shutdown caught, abandoning message: {}", se.getMessage(), se);
}
} catch (RegionDestroyedException | RegionNotFoundException rde) {
// [bruce] RDE does not always mean that the sender's region is also
// destroyed, so we must send back an exception. If the sender's
// region is also destroyed, who cares if we send it an exception
// if (pr != null && pr.isClosed) {
thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_REGION_IS_DESTROYED_IN_0.toLocalizedString(dm.getDistributionManagerId()), rde);
// }
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
// log the exception at fine level if there is no reply to the message
thr = null;
if (sendReply) {
if (!checkDSClosing(dm)) {
thr = t;
} else {
// don't pass arbitrary runtime exceptions and errors back if this
// cache/vm is closing
thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_DISTRIBUTED_SYSTEM_IS_DISCONNECTING.toLocalizedString());
}
}
if (logger.isTraceEnabled(LogMarker.DM) && t instanceof RuntimeException) {
logger.trace(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
}
} finally {
if (sendReply) {
ReplyException rex = null;
if (thr != null) {
// don't transmit the exception if this message was to a listener
// and this listener is shutting down
boolean excludeException = this.notificationOnly && ((thr instanceof CancelException) || (thr instanceof ForceReattemptException));
if (!excludeException) {
rex = new ReplyException(thr);
}
}
// Send the reply if the operateOnPartitionedRegion returned true
sendReply(getSender(), this.processorId, dm, rex, pr, startTime);
EntryLogger.clearSource();
}
}
}
use of org.apache.geode.cache.CacheClosedException 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.cache.CacheClosedException in project geode by apache.
the class DataCommands method importData.
@CliCommand(value = CliStrings.IMPORT_DATA, help = CliStrings.IMPORT_DATA__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
public Result importData(@CliOption(key = CliStrings.IMPORT_DATA__REGION, optionContext = ConverterHint.REGION_PATH, mandatory = true, help = CliStrings.IMPORT_DATA__REGION__HELP) String regionName, @CliOption(key = CliStrings.IMPORT_DATA__FILE, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.IMPORT_DATA__FILE__HELP) String filePath, @CliOption(key = CliStrings.IMPORT_DATA__MEMBER, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId, @CliOption(key = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, unspecifiedDefaultValue = "false", help = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS__HELP) boolean invokeCallbacks) {
this.securityService.authorizeRegionWrite(regionName);
Result result;
try {
final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (!filePath.endsWith(CliStrings.GEODE_DATA_FILE_EXTENSION)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, CliStrings.GEODE_DATA_FILE_EXTENSION));
}
if (targetMember != null) {
final Object[] args = { regionName, filePath, invokeCallbacks };
ResultCollector<?, ?> rc = CliUtil.executeFunction(importDataFunction, args, targetMember);
List<Object> results = (List<Object>) rc.getResult();
if (results != null) {
Object resultObj = results.get(0);
if (resultObj instanceof String) {
result = ResultBuilder.createInfoResult((String) resultObj);
} else if (resultObj instanceof Exception) {
result = ResultBuilder.createGemFireErrorResult(((Exception) resultObj).getMessage());
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.IMPORT_DATA__MEMBER__NOT__FOUND, memberNameOrId));
}
} catch (CacheClosedException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
return result;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class ExecutionHandlerContext method getExceptionResponse.
private ByteBuf getExceptionResponse(ChannelHandlerContext ctx, Throwable cause) {
ByteBuf response;
if (cause instanceof RedisDataTypeMismatchException)
response = Coder.getWrongTypeResponse(this.byteBufAllocator, cause.getMessage());
else if (cause instanceof DecoderException && cause.getCause() instanceof RedisCommandParserException)
response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.PARSING_EXCEPTION_MESSAGE);
else if (cause instanceof RegionCreationException) {
this.logger.error(cause);
response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_REGION_CREATION);
} else if (cause instanceof InterruptedException || cause instanceof CacheClosedException)
response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.SERVER_ERROR_SHUTDOWN);
else if (cause instanceof IllegalStateException) {
response = Coder.getErrorResponse(this.byteBufAllocator, cause.getMessage());
} else {
if (this.logger.errorEnabled())
this.logger.error("GeodeRedisServer-Unexpected error handler for " + ctx.channel(), cause);
response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.SERVER_ERROR_MESSAGE);
}
return response;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class BucketAdvisor method waitForPrimaryMember.
/**
* Wait briefly for a primary member to be identified.
*
* @param timeout time in milliseconds to wait for a primary
* @return the primary bucket host
*/
protected InternalDistributedMember waitForPrimaryMember(long timeout) {
synchronized (this) {
// let's park this thread and wait for a primary!
StopWatch timer = new StopWatch(true);
long warnTime = getDistributionManager().getConfig().getAckWaitThreshold() * 1000L;
boolean loggedWarning = false;
try {
for (; ; ) {
// bail out if the system starts closing
this.getAdvisee().getCancelCriterion().checkCancelInProgress(null);
final InternalCache cache = getBucket().getCache();
if (cache != null && cache.isCacheAtShutdownAll()) {
throw new CacheClosedException("Cache is shutting down");
}
if (getBucketRedundancy() == -1) {
// there are no real buckets in other vms... no reason to wait
return null;
}
getProxyBucketRegion().getPartitionedRegion().checkReadiness();
if (isClosed()) {
break;
}
long elapsed = timer.elapsedTimeMillis();
long timeLeft = timeout - elapsed;
if (timeLeft <= 0) {
break;
}
if (getBucketRedundancy() == -1 || isClosed()) {
// early out... all bucket regions are gone or we closed
break;
}
InternalDistributedMember primary = basicGetPrimaryMember();
if (primary != null) {
return primary;
}
if (logger.isDebugEnabled()) {
logger.debug("Waiting for bucket {}. Time left :{} ms", this, timeLeft);
}
// Log a warning if we have waited for the ack wait threshold time.
if (!loggedWarning) {
long timeUntilWarning = warnTime - elapsed;
if (timeUntilWarning <= 0) {
logger.warn(LocalizedMessage.create(LocalizedStrings.BucketAdvisor_WAITING_FOR_PRIMARY, new Object[] { warnTime / 1000L, this, this.adviseInitialized() }));
// log a warning;
loggedWarning = true;
} else {
timeLeft = timeLeft > timeUntilWarning ? timeUntilWarning : timeLeft;
}
}
// spurious wakeup ok
this.wait(timeLeft);
}
} catch (InterruptedException e) {
// abort and return null
Thread.currentThread().interrupt();
} finally {
if (loggedWarning) {
logger.info(LocalizedMessage.create(LocalizedStrings.BucketAdvisor_WAITING_FOR_PRIMARY_DONE));
}
}
return null;
}
}
Aggregations