use of org.apache.geode.CancelException in project geode by apache.
the class Oplog method readCrf.
/**
* Return number of bytes read
*/
private long readCrf(OplogEntryIdSet deletedIds, boolean recoverValues, boolean latestOplog) {
this.recoverNewEntryId = DiskStoreImpl.INVALID_ID;
this.recoverModEntryId = DiskStoreImpl.INVALID_ID;
this.recoverModEntryIdHWM = DiskStoreImpl.INVALID_ID;
boolean readLastRecord = true;
CountingDataInputStream dis = null;
try {
final LocalRegion currentRegion = LocalRegion.getInitializingRegion();
final Version version = getProductVersionIfOld();
final ByteArrayDataInput in = new ByteArrayDataInput();
final HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
int recordCount = 0;
boolean foundDiskStoreRecord = false;
FileInputStream fis = null;
try {
fis = new FileInputStream(this.crf.f);
dis = new CountingDataInputStream(new BufferedInputStream(fis, 1024 * 1024), this.crf.f.length());
boolean endOfLog = false;
while (!endOfLog) {
// long startPosition = byteCount;
if (dis.atEndOfFile()) {
endOfLog = true;
break;
}
readLastRecord = false;
byte opCode = dis.readByte();
if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
logger.trace(LogMarker.PERSIST_RECOVERY, "Oplog opCode={}", opCode);
}
switch(opCode) {
case OPLOG_EOF_ID:
// we are at the end of the oplog. So we need to back up one byte
dis.decrementCount();
endOfLog = true;
break;
case OPLOG_CONFLICT_VERSION:
this.readVersionTagOnlyEntry(dis, opCode);
break;
case OPLOG_NEW_ENTRY_BASE_ID:
{
long newEntryBase = dis.readLong();
if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
logger.trace(LogMarker.PERSIST_RECOVERY, "newEntryBase={}", newEntryBase);
}
readEndOfRecord(dis);
setRecoverNewEntryId(newEntryBase);
recordCount++;
}
break;
case OPLOG_NEW_ENTRY_0ID:
readNewEntry(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
recordCount++;
break;
case OPLOG_MOD_ENTRY_1ID:
case OPLOG_MOD_ENTRY_2ID:
case OPLOG_MOD_ENTRY_3ID:
case OPLOG_MOD_ENTRY_4ID:
case OPLOG_MOD_ENTRY_5ID:
case OPLOG_MOD_ENTRY_6ID:
case OPLOG_MOD_ENTRY_7ID:
case OPLOG_MOD_ENTRY_8ID:
readModifyEntry(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
recordCount++;
break;
case OPLOG_MOD_ENTRY_WITH_KEY_1ID:
case OPLOG_MOD_ENTRY_WITH_KEY_2ID:
case OPLOG_MOD_ENTRY_WITH_KEY_3ID:
case OPLOG_MOD_ENTRY_WITH_KEY_4ID:
case OPLOG_MOD_ENTRY_WITH_KEY_5ID:
case OPLOG_MOD_ENTRY_WITH_KEY_6ID:
case OPLOG_MOD_ENTRY_WITH_KEY_7ID:
case OPLOG_MOD_ENTRY_WITH_KEY_8ID:
readModifyEntryWithKey(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
recordCount++;
break;
case OPLOG_DISK_STORE_ID:
readDiskStoreRecord(dis, this.crf.f);
foundDiskStoreRecord = true;
recordCount++;
break;
case OPLOG_MAGIC_SEQ_ID:
readOplogMagicSeqRecord(dis, this.crf.f, OPLOG_TYPE.CRF);
break;
case OPLOG_GEMFIRE_VERSION:
readGemfireVersionRecord(dis, this.crf.f);
recordCount++;
break;
case OPLOG_RVV:
readRVVRecord(dis, this.drf.f, false, latestOplog);
recordCount++;
break;
default:
throw new DiskAccessException(LocalizedStrings.Oplog_UNKNOWN_OPCODE_0_FOUND_IN_DISK_OPERATION_LOG.toLocalizedString(opCode), getParent());
}
readLastRecord = true;
// @todo
// if (rgn.isDestroyed()) {
// break;
// }
}
// while
} finally {
if (dis != null) {
dis.close();
}
if (fis != null) {
fis.close();
}
}
if (!foundDiskStoreRecord && recordCount > 0) {
throw new DiskAccessException("The oplog file \"" + this.crf.f + "\" does not belong to the init file \"" + getParent().getInitFile() + "\". Crf did not contain a disk store id.", getParent());
}
} catch (EOFException ignore) {
// ignore since a partial record write can be caused by a crash
} catch (IOException ex) {
getParent().getCancelCriterion().checkCancelInProgress(ex);
throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0.toLocalizedString(this.crf.f.getPath()), ex, getParent());
} catch (CancelException e) {
if (logger.isDebugEnabled()) {
logger.debug("Oplog::readOplog:Error in recovery as Cache was closed", e);
}
} catch (RegionDestroyedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Oplog::readOplog:Error in recovery as Region was destroyed", e);
}
} catch (IllegalStateException e) {
throw e;
}
// Add the Oplog size to the Directory Holder which owns this oplog,
// so that available space is correctly calculated & stats updated.
long byteCount = 0;
if (!readLastRecord) {
// this means that there was a crash
// and hence we should not continue to read
// the next oplog
this.crashed = true;
if (dis != null) {
byteCount = dis.getFileLength();
}
} else {
if (dis != null) {
byteCount = dis.getCount();
}
}
return byteCount;
}
use of org.apache.geode.CancelException in project geode by apache.
the class PRHARedundancyProvider method scheduleRedundancyRecovery.
/**
* Schedule a task to perform redundancy recovery for a new node or for the node departed.
*/
public void scheduleRedundancyRecovery(Object failedMemId) {
final boolean isStartup = failedMemId == null ? true : false;
final InternalCache cache = this.prRegion.getCache();
final int redundantCopies = PRHARedundancyProvider.this.prRegion.getRedundantCopies();
final long delay;
final boolean movePrimaries;
if (isStartup) {
delay = this.prRegion.getPartitionAttributes().getStartupRecoveryDelay();
movePrimaries = !Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_MOVE_PRIMARIES_ON_STARTUP");
} else {
delay = this.prRegion.getPartitionAttributes().getRecoveryDelay();
movePrimaries = false;
}
final boolean requiresRedundancyRecovery = delay >= 0;
if (!requiresRedundancyRecovery) {
return;
}
if (!PRHARedundancyProvider.this.prRegion.isDataStore()) {
return;
}
Runnable task = new RecoveryRunnable(this) {
@Override
public void run2() {
try {
final boolean isFixedPartitionedRegion = PRHARedundancyProvider.this.prRegion.isFixedPartitionedRegion();
// Fix for 43582 - always replace offline data for fixed partitioned
// regions - this guarantees we create the buckets we are supposed to
// create on this node.
boolean replaceOfflineData = isFixedPartitionedRegion || !isStartup;
RebalanceDirector director;
if (isFixedPartitionedRegion) {
director = new FPRDirector(true, movePrimaries);
} else {
director = new CompositeDirector(true, true, false, movePrimaries);
}
final PartitionedRegionRebalanceOp rebalance = new PartitionedRegionRebalanceOp(PRHARedundancyProvider.this.prRegion, false, director, replaceOfflineData, false);
long start = PRHARedundancyProvider.this.prRegion.getPrStats().startRecovery();
if (isFixedPartitionedRegion) {
rebalance.executeFPA();
} else {
rebalance.execute();
}
PRHARedundancyProvider.this.prRegion.getPrStats().endRecovery(start);
PRHARedundancyProvider.this.recoveryFuture = null;
} catch (CancelException e) {
logger.debug("Cache closed while recovery in progress");
} catch (RegionDestroyedException e) {
logger.debug("Region destroyed while recovery in progress");
} catch (Exception e) {
logger.error(LocalizedMessage.create(LocalizedStrings.PRHARedundancyProvider_UNEXPECTED_EXCEPTION_DURING_BUCKET_RECOVERY), e);
}
}
};
synchronized (this.shutdownLock) {
// possible fix for bug 41094
if (!this.shutdown) {
try {
if (logger.isDebugEnabled()) {
if (isStartup) {
logger.debug(this.prRegion + " scheduling redundancy recovery in {} ms", delay);
} else {
logger.debug("prRegion scheduling redundancy recovery after departure/crash/error in {} in {} ms", failedMemId, delay);
}
}
recoveryFuture = this.recoveryExecutor.schedule(task, delay, TimeUnit.MILLISECONDS);
} catch (RejectedExecutionException e) {
// ok, the executor is shutting down.
}
}
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class Connection method processNIOBuffer.
/**
* processes the current NIO buffer. If there are complete messages in the buffer, they are
* deserialized and passed to TCPConduit for further processing
*/
private void processNIOBuffer() throws ConnectionException, IOException {
if (nioInputBuffer != null) {
nioInputBuffer.flip();
}
boolean done = false;
while (!done && connected) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(null);
// long startTime = DistributionStats.getStatTime();
int remaining = nioInputBuffer.remaining();
if (nioLengthSet || remaining >= MSG_HEADER_BYTES) {
if (!nioLengthSet) {
int headerStartPos = nioInputBuffer.position();
nioMessageLength = nioInputBuffer.getInt();
/* nioMessageVersion = */
calcHdrVersion(nioMessageLength);
nioMessageLength = calcMsgByteSize(nioMessageLength);
nioMessageType = nioInputBuffer.get();
nioMsgId = nioInputBuffer.getShort();
directAck = (nioMessageType & DIRECT_ACK_BIT) != 0;
if (directAck) {
// clear the ack bit
nioMessageType &= ~DIRECT_ACK_BIT;
}
// Following validation fixes bug 31145
if (!validMsgType(nioMessageType)) {
Integer nioMessageTypeInteger = Integer.valueOf(nioMessageType);
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNKNOWN_P2P_MESSAGE_TYPE_0, nioMessageTypeInteger));
this.readerShuttingDown = true;
requestClose(LocalizedStrings.Connection_UNKNOWN_P2P_MESSAGE_TYPE_0.toLocalizedString(nioMessageTypeInteger));
break;
}
nioLengthSet = true;
// keep the header "in" the buffer until we have read the entire msg.
// Trust me: this will reduce copying on large messages.
nioInputBuffer.position(headerStartPos);
}
if (remaining >= nioMessageLength + MSG_HEADER_BYTES) {
nioLengthSet = false;
nioInputBuffer.position(nioInputBuffer.position() + MSG_HEADER_BYTES);
// don't trust the message deserialization to leave the position in
// the correct spot. Some of the serialization uses buffered
// streams that can leave the position at the wrong spot
int startPos = nioInputBuffer.position();
int oldLimit = nioInputBuffer.limit();
nioInputBuffer.limit(startPos + nioMessageLength);
if (this.handshakeRead) {
if (nioMessageType == NORMAL_MSG_TYPE) {
this.owner.getConduit().stats.incMessagesBeingReceived(true, nioMessageLength);
ByteBufferInputStream bbis = remoteVersion == null ? new ByteBufferInputStream(nioInputBuffer) : new VersionedByteBufferInputStream(nioInputBuffer, remoteVersion);
DistributionMessage msg = null;
try {
ReplyProcessor21.initMessageRPId();
// add serialization stats
long startSer = this.owner.getConduit().stats.startMsgDeserialization();
msg = (DistributionMessage) InternalDataSerializer.readDSFID(bbis);
this.owner.getConduit().stats.endMsgDeserialization(startSer);
if (bbis.available() != 0) {
logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_MESSAGE_DESERIALIZATION_OF_0_DID_NOT_READ_1_BYTES, new Object[] { msg, Integer.valueOf(bbis.available()) }));
}
try {
if (!dispatchMessage(msg, nioMessageLength, directAck)) {
directAck = false;
}
} catch (MemberShunnedException e) {
// don't respond (bug39117)
directAck = false;
} catch (Exception de) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(de);
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DISPATCHING_MESSAGE), de);
} catch (ThreadDeath td) {
throw td;
} 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();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DISPATCHING_MESSAGE), t);
}
} 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();
sendFailureReply(ReplyProcessor21.getMessageRPId(), LocalizedStrings.Connection_ERROR_DESERIALIZING_MESSAGE.toLocalizedString(), t, directAck);
if (t instanceof ThreadDeath) {
throw (ThreadDeath) t;
}
if (t instanceof CancelException) {
if (!(t instanceof CacheClosedException)) {
// CacheClosedException; see bug 43543
throw (CancelException) t;
}
}
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_MESSAGE), t);
} finally {
ReplyProcessor21.clearMessageRPId();
}
} else if (nioMessageType == CHUNKED_MSG_TYPE) {
MsgDestreamer md = obtainMsgDestreamer(nioMsgId, remoteVersion);
this.owner.getConduit().stats.incMessagesBeingReceived(md.size() == 0, nioMessageLength);
try {
md.addChunk(nioInputBuffer, nioMessageLength);
} catch (IOException ex) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_FAILED_HANDLING_CHUNK_MESSAGE), ex);
}
} else /* (nioMessageType == END_CHUNKED_MSG_TYPE) */
{
// logger.info("END_CHUNK msgId="+nioMsgId);
MsgDestreamer md = obtainMsgDestreamer(nioMsgId, remoteVersion);
this.owner.getConduit().stats.incMessagesBeingReceived(md.size() == 0, nioMessageLength);
try {
md.addChunk(nioInputBuffer, nioMessageLength);
} catch (IOException ex) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_FAILED_HANDLING_END_CHUNK_MESSAGE), ex);
}
DistributionMessage msg = null;
int msgLength = 0;
String failureMsg = null;
Throwable failureEx = null;
int rpId = 0;
boolean interrupted = false;
try {
msg = md.getMessage();
} catch (ClassNotFoundException ex) {
this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
failureMsg = LocalizedStrings.Connection_CLASSNOTFOUND_DESERIALIZING_MESSAGE.toLocalizedString();
failureEx = ex;
rpId = md.getRPid();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_CLASSNOTFOUND_DESERIALIZING_MESSAGE_0, ex));
} catch (IOException ex) {
this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
failureMsg = LocalizedStrings.Connection_IOEXCEPTION_DESERIALIZING_MESSAGE.toLocalizedString();
failureEx = ex;
rpId = md.getRPid();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_IOEXCEPTION_DESERIALIZING_MESSAGE), failureEx);
} catch (InterruptedException ex) {
interrupted = true;
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable ex) {
// 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();
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
failureMsg = LocalizedStrings.Connection_UNEXPECTED_FAILURE_DESERIALIZING_MESSAGE.toLocalizedString();
failureEx = ex;
rpId = md.getRPid();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNEXPECTED_FAILURE_DESERIALIZING_MESSAGE), failureEx);
} finally {
msgLength = md.size();
releaseMsgDestreamer(nioMsgId, md);
if (interrupted) {
Thread.currentThread().interrupt();
}
}
if (msg != null) {
try {
if (!dispatchMessage(msg, msgLength, directAck)) {
directAck = false;
}
} catch (MemberShunnedException e) {
// not a member anymore - don't reply
directAck = false;
} catch (Exception de) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(de);
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DISPATCHING_MESSAGE), de);
} catch (ThreadDeath td) {
throw td;
} 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();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DISPATCHING_MESSAGE), t);
}
} else if (failureEx != null) {
sendFailureReply(rpId, failureMsg, failureEx, directAck);
}
}
} else {
// read HANDSHAKE
ByteBufferInputStream bbis = new ByteBufferInputStream(nioInputBuffer);
DataInputStream dis = new DataInputStream(bbis);
if (!this.isReceiver) {
try {
this.replyCode = dis.readUnsignedByte();
if (this.replyCode == REPLY_CODE_OK_WITH_ASYNC_INFO) {
this.asyncDistributionTimeout = dis.readInt();
this.asyncQueueTimeout = dis.readInt();
this.asyncMaxQueueSize = (long) dis.readInt() * (1024 * 1024);
if (this.asyncDistributionTimeout != 0) {
logger.info(LocalizedMessage.create(LocalizedStrings.Connection_0_ASYNC_CONFIGURATION_RECEIVED_1, new Object[] { p2pReaderName(), " asyncDistributionTimeout=" + this.asyncDistributionTimeout + " asyncQueueTimeout=" + this.asyncQueueTimeout + " asyncMaxQueueSize=" + (this.asyncMaxQueueSize / (1024 * 1024)) }));
}
// read the product version ordinal for on-the-fly serialization
// transformations (for rolling upgrades)
this.remoteVersion = Version.readVersion(dis, true);
}
} catch (Exception e) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_REPLY), e);
this.readerShuttingDown = true;
requestClose(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_REPLY.toLocalizedString());
return;
} catch (ThreadDeath td) {
throw td;
} 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();
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DESERIALIZING_P2P_HANDSHAKE_REPLY), t);
this.readerShuttingDown = true;
requestClose(LocalizedStrings.Connection_THROWABLE_DESERIALIZING_P2P_HANDSHAKE_REPLY.toLocalizedString());
return;
}
if (this.replyCode != REPLY_CODE_OK && this.replyCode != REPLY_CODE_OK_WITH_ASYNC_INFO) {
StringId err = LocalizedStrings.Connection_UNKNOWN_HANDSHAKE_REPLY_CODE_0_NIOMESSAGELENGTH_1_PROCESSORTYPE_2;
Object[] errArgs = new Object[] { Integer.valueOf(this.replyCode), Integer.valueOf(nioMessageLength) };
if (replyCode == 0 && logger.isDebugEnabled()) {
// bug 37113
logger.debug(err.toLocalizedString(errArgs) + " (peer probably departed ungracefully)");
} else {
logger.fatal(LocalizedMessage.create(err, errArgs));
}
this.readerShuttingDown = true;
requestClose(err.toLocalizedString(errArgs));
return;
}
notifyHandshakeWaiter(true);
} else {
try {
byte b = dis.readByte();
if (b != 0) {
throw new IllegalStateException(LocalizedStrings.Connection_DETECTED_OLD_VERSION_PRE_501_OF_GEMFIRE_OR_NONGEMFIRE_DURING_HANDSHAKE_DUE_TO_INITIAL_BYTE_BEING_0.toLocalizedString(new Byte(b)));
}
byte handShakeByte = dis.readByte();
if (handShakeByte != HANDSHAKE_VERSION) {
throw new IllegalStateException(LocalizedStrings.Connection_DETECTED_WRONG_VERSION_OF_GEMFIRE_PRODUCT_DURING_HANDSHAKE_EXPECTED_0_BUT_FOUND_1.toLocalizedString(new Object[] { new Byte(HANDSHAKE_VERSION), new Byte(handShakeByte) }));
}
InternalDistributedMember remote = DSFIDFactory.readInternalDistributedMember(dis);
setRemoteAddr(remote);
this.sharedResource = dis.readBoolean();
this.preserveOrder = dis.readBoolean();
this.uniqueId = dis.readLong();
// read the product version ordinal for on-the-fly serialization
// transformations (for rolling upgrades)
this.remoteVersion = Version.readVersion(dis, true);
int dominoNumber = 0;
if (this.remoteVersion == null || (this.remoteVersion.compareTo(Version.GFE_80) >= 0)) {
dominoNumber = dis.readInt();
if (this.sharedResource) {
dominoNumber = 0;
}
dominoCount.set(dominoNumber);
// this.senderName = dis.readUTF();
}
if (!this.sharedResource) {
if (tipDomino()) {
logger.info(LocalizedMessage.create(LocalizedStrings.Connection_THREAD_OWNED_RECEIVER_FORCING_ITSELF_TO_SEND_ON_THREAD_OWNED_SOCKETS));
// bug #49565 - if domino count is >= 2 use shared resources.
// Also see DistributedCacheOperation#supportsDirectAck
} else {
// if (dominoNumber < 2) {
ConnectionTable.threadWantsOwnResources();
if (logger.isDebugEnabled()) {
logger.debug("thread-owned receiver with domino count of {} will prefer sending on thread-owned sockets", dominoNumber);
}
// } else {
// ConnectionTable.threadWantsSharedResources();
}
this.conduit.stats.incThreadOwnedReceivers(1L, dominoNumber);
// Because this thread is not shared resource, it will be used for direct
// ack. Direct ack messages can be large. This call will resize the send
// buffer.
setSendBufferSize(this.socket);
}
// String name = owner.getDM().getConfig().getName();
// if (name == null) {
// name = "pid="+OSProcess.getId();
// }
setThreadName(dominoNumber);
} catch (Exception e) {
// bug 37101
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_MESSAGE), e);
this.readerShuttingDown = true;
requestClose(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_MESSAGE.toLocalizedString());
return;
}
if (logger.isDebugEnabled()) {
logger.debug("P2P handshake remoteAddr is {}{}", this.remoteAddr, (this.remoteVersion != null ? " (" + this.remoteVersion + ')' : ""));
}
try {
String authInit = System.getProperty(DistributionConfigImpl.SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT);
boolean isSecure = authInit != null && authInit.length() != 0;
if (isSecure) {
if (owner.getConduit().waitForMembershipCheck(this.remoteAddr)) {
// fix for bug 33224
sendOKHandshakeReply();
notifyHandshakeWaiter(true);
} else {
// ARB: check if we need notifyHandshakeWaiter() call.
notifyHandshakeWaiter(false);
logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_0_TIMED_OUT_DURING_A_MEMBERSHIP_CHECK, p2pReaderName()));
return;
}
} else {
// fix for bug 33224
sendOKHandshakeReply();
try {
notifyHandshakeWaiter(true);
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNCAUGHT_EXCEPTION_FROM_LISTENER), e);
}
}
} catch (IOException ex) {
final String err = LocalizedStrings.Connection_FAILED_SENDING_HANDSHAKE_REPLY.toLocalizedString();
if (logger.isDebugEnabled()) {
logger.debug(err, ex);
}
this.readerShuttingDown = true;
requestClose(err + ": " + ex);
return;
}
}
}
if (!connected) {
continue;
}
accessed();
nioInputBuffer.limit(oldLimit);
nioInputBuffer.position(startPos + nioMessageLength);
} else {
done = true;
compactOrResizeBuffer(nioMessageLength);
}
} else {
done = true;
if (nioInputBuffer.position() != 0) {
nioInputBuffer.compact();
} else {
nioInputBuffer.position(nioInputBuffer.limit());
nioInputBuffer.limit(nioInputBuffer.capacity());
}
}
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class Connection method runNioPusher.
/**
* have the pusher thread check for queue overflow and for idle time exceeded
*/
protected void runNioPusher() {
try {
final DMStats stats = this.owner.getConduit().stats;
final long threadStart = stats.startAsyncThread();
try {
stats.incAsyncQueues(1);
stats.incAsyncThreads(1);
try {
int flushId = 0;
while (this.asyncQueuingInProgress && this.connected) {
if (SystemFailure.getFailure() != null) {
// Allocate no objects here!
Socket s = this.socket;
if (s != null) {
try {
s.close();
} catch (IOException e) {
// don't care
}
}
// throws
SystemFailure.checkFailure();
}
if (this.owner.getConduit().getCancelCriterion().isCancelInProgress()) {
break;
}
flushId++;
long flushStart = stats.startAsyncQueueFlush();
try {
long curQueuedBytes = this.queuedBytes;
if (curQueuedBytes > this.asyncMaxQueueSize) {
logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_QUEUED_BYTES_0_EXCEEDS_MAX_OF_1_ASKING_SLOW_RECEIVER_2_TO_DISCONNECT, new Object[] { curQueuedBytes, this.asyncMaxQueueSize, this.remoteAddr }));
stats.incAsyncQueueSizeExceeded(1);
disconnectSlowReceiver();
return;
}
SocketChannel channel = getSocket().getChannel();
ByteBuffer bb = takeFromOutgoingQueue();
if (bb == null) {
if (logger.isDebugEnabled() && flushId == 1) {
logger.debug("P2P pusher found empty queue");
}
return;
}
nioWriteFully(channel, bb, true, null);
// We should not add messagesSent here according to Bruce.
// The counts are increased elsewhere.
// messagesSent++;
accessed();
} finally {
stats.endAsyncQueueFlush(flushStart);
}
}
// while
} finally {
// need to force this to false before doing the requestClose calls
synchronized (this.outgoingQueue) {
this.asyncQueuingInProgress = false;
this.outgoingQueue.notifyAll();
}
}
} catch (InterruptedException ex) {
// someone wants us to stop.
// No need to set interrupt bit, we're quitting.
// No need to throw an error, we're quitting.
} catch (IOException ex) {
final String err = LocalizedStrings.Connection_P2P_PUSHER_IO_EXCEPTION_FOR_0.toLocalizedString(this);
if (!isSocketClosed()) {
if (logger.isDebugEnabled() && !isIgnorableIOException(ex)) {
logger.debug(err, ex);
}
}
try {
requestClose(err + ": " + ex);
} catch (Exception ignore) {
}
} catch (CancelException ex) {
// bug 37367
final String err = LocalizedStrings.Connection_P2P_PUSHER_0_CAUGHT_CACHECLOSEDEXCEPTION_1.toLocalizedString(new Object[] { this, ex });
logger.debug(err);
try {
requestClose(err);
} catch (Exception ignore) {
}
return;
} catch (Exception ex) {
// bug 37101
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
if (!isSocketClosed()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_P2P_PUSHER_EXCEPTION_0, ex), ex);
}
try {
requestClose(LocalizedStrings.Connection_P2P_PUSHER_EXCEPTION_0.toLocalizedString(ex));
} catch (Exception ignore) {
}
} finally {
stats.incAsyncQueueSize(-this.queuedBytes);
this.queuedBytes = 0;
stats.endAsyncThread(threadStart);
stats.incAsyncThreads(-1);
stats.incAsyncQueues(-1);
if (logger.isDebugEnabled()) {
logger.debug("runNioPusher terminated id={} from {}/{}", conduitIdStr, remoteAddr, remoteAddr);
}
}
} finally {
synchronized (this.nioPusherSync) {
this.pusherThread = null;
this.nioPusherSync.notify();
}
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class RegionFactoryJUnitTest method testRegionFactoryAndCacheClose.
/**
* Test RegionFactory with Cache close and DistributedSystem disconnect
*/
@Test
public void testRegionFactoryAndCacheClose() throws Exception {
// Assert basic region creation when no DistributedSystem or Cache exists
RegionFactory factory = new RegionFactory(createGemFireProperties());
r1 = factory.create(r1Name);
assertBasicRegionFunctionality(r1, r1Name);
// Assert duplicate creation failure
try {
factory.create(r1Name);
fail("Expected RegionExistsException");
} catch (RegionExistsException expected) {
}
r2 = factory.create(r2Name);
assertBasicRegionFunctionality(r2, r2Name);
r2.destroyRegion();
// as of 6.5 if the cache that was used to create a regionFactory is closed
// then the factory is out of business
Cache c = r1.getCache();
r1.destroyRegion();
c.close();
try {
r1 = factory.create(r1Name);
fail("Use of RegionFactory after cache close should throw CancelException");
} catch (CancelException expected) {
// passed
}
factory = new RegionFactory(createGemFireProperties());
r1 = factory.create(r1Name);
assertBasicRegionFunctionality(r1, r1Name);
// as of 6.5 if the ds that was used to create a regionFactory is disconnected
// then the factory is out of business
// Assert we can handle a disconnected disributed system
DistributedSystem d = r1.getCache().getDistributedSystem();
r1.destroyRegion();
d.disconnect();
try {
r1 = factory.create(r1Name);
} catch (CancelException expected) {
// passed
}
factory = new RegionFactory(createGemFireProperties());
r1 = factory.create(r1Name);
assertBasicRegionFunctionality(r1, r1Name);
// as of 6.5 if the ds that was used to create a regionFactory is disconnected
// then the factory is out of business
// Assert we can handle both a closed Cache and a disconnected system
c = r1.getCache();
d = c.getDistributedSystem();
r1.destroyRegion();
c.close();
d.disconnect();
r1 = new RegionFactory(createGemFireProperties()).create(r1Name);
assertBasicRegionFunctionality(r1, r1Name);
}
Aggregations