use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class Connection method readAck.
/**
* @param msToWait number of milliseconds to wait for an ack. If 0 then wait forever.
* @param msInterval interval between checks
* @throws SocketTimeoutException if msToWait expires.
* @throws ConnectionException if ack is not received (fixes bug 34312)
*/
public void readAck(final int msToWait, final long msInterval, final DirectReplyProcessor processor) throws SocketTimeoutException, ConnectionException {
if (isSocketClosed()) {
throw new ConnectionException(LocalizedStrings.Connection_CONNECTION_IS_CLOSED.toLocalizedString());
}
synchronized (this.stateLock) {
this.connectionState = STATE_READING_ACK;
}
boolean origSocketInUse = this.socketInUse;
this.socketInUse = true;
MsgReader msgReader = null;
DMStats stats = owner.getConduit().stats;
final Version version = getRemoteVersion();
try {
if (useNIO()) {
msgReader = new NIOMsgReader(this, version);
} else {
msgReader = new OioMsgReader(this, version);
}
Header header = msgReader.readHeader();
ReplyMessage msg;
int len;
if (header.getNioMessageType() == NORMAL_MSG_TYPE) {
msg = (ReplyMessage) msgReader.readMessage(header);
len = header.getNioMessageLength();
} else {
MsgDestreamer destreamer = obtainMsgDestreamer(header.getNioMessageId(), version);
while (header.getNioMessageType() == CHUNKED_MSG_TYPE) {
msgReader.readChunk(header, destreamer);
header = msgReader.readHeader();
}
msgReader.readChunk(header, destreamer);
msg = (ReplyMessage) destreamer.getMessage();
releaseMsgDestreamer(header.getNioMessageId(), destreamer);
len = destreamer.size();
}
// I'd really just like to call dispatchMessage here. However,
// that call goes through a bunch of checks that knock about
// 10% of the performance. Since this direct-ack stuff is all
// about performance, we'll skip those checks. Skipping them
// should be legit, because we just sent a message so we know
// the member is already in our view, etc.
DistributionManager dm = (DistributionManager) owner.getDM();
msg.setBytesRead(len);
msg.setSender(remoteAddr);
stats.incReceivedMessages(1L);
stats.incReceivedBytes(msg.getBytesRead());
stats.incMessageChannelTime(msg.resetTimestamp());
msg.process(dm, processor);
// dispatchMessage(msg, len, false);
} catch (MemberShunnedException e) {
// do nothing
} catch (SocketTimeoutException timeout) {
throw timeout;
} catch (IOException e) {
final String err = LocalizedStrings.Connection_ACK_READ_IO_EXCEPTION_FOR_0.toLocalizedString(this);
if (!isSocketClosed()) {
if (logger.isDebugEnabled() && !isIgnorableIOException(e)) {
logger.debug(err, e);
}
}
try {
requestClose(err + ": " + e);
} catch (Exception ex) {
}
throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
} catch (ConnectionException e) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
throw e;
} catch (Exception e) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
if (!isSocketClosed()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ACK_READ_EXCEPTION), e);
}
try {
requestClose(LocalizedStrings.Connection_ACK_READ_EXCEPTION_0.toLocalizedString(e));
} catch (Exception ex) {
}
throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
} finally {
stats.incProcessedMessages(1L);
accessed();
this.socketInUse = origSocketInUse;
if (this.ackTimedOut) {
logger.info(LocalizedMessage.create(LocalizedStrings.Connection_FINISHED_WAITING_FOR_REPLY_FROM_0, new Object[] { getRemoteAddress() }));
this.ackTimedOut = false;
}
if (msgReader != null) {
msgReader.close();
}
}
synchronized (stateLock) {
this.connectionState = STATE_RECEIVED_ACK;
}
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class AbstractExecution method executeFunctionOnLocalPRNode.
public void executeFunctionOnLocalPRNode(final Function fn, final FunctionContext cx, final PartitionedRegionFunctionResultSender sender, DM dm, boolean isTx) {
if (dm instanceof DistributionManager && !isTx) {
if (ServerConnection.isExecuteFunctionOnLocalNodeOnly().byteValue() == 1) {
// executed locally
ServerConnection.executeFunctionOnLocalNodeOnly((byte) 3);
executeFunctionLocally(fn, cx, sender, dm);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
} else {
final DistributionManager newDM = (DistributionManager) dm;
newDM.getFunctionExcecutor().execute(new Runnable() {
public void run() {
executeFunctionLocally(fn, cx, sender, newDM);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
}
});
}
} else {
executeFunctionLocally(fn, cx, sender, dm);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
}
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class RemoveBucketMessageTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
RemoveBucketMessage mockRemoveBucketMessage = mock(RemoveBucketMessage.class);
DistributionManager mockDistributionManager = mock(DistributionManager.class);
PartitionedRegion mockPartitionedRegion = mock(PartitionedRegion.class);
long startTime = System.currentTimeMillis();
Object key = new Object();
when(mockRemoveBucketMessage.operateOnPartitionedRegion(eq(mockDistributionManager), eq(mockPartitionedRegion), eq(startTime))).thenReturn(true);
assertThat(mockRemoveBucketMessage.operateOnPartitionedRegion(mockDistributionManager, mockPartitionedRegion, startTime)).isTrue();
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class OutOfOffHeapMemoryDUnitTest method testSimpleOutOfOffHeapMemoryMemberDisconnects.
@Test
public void testSimpleOutOfOffHeapMemoryMemberDisconnects() {
final DistributedSystem system = getSystem();
final Cache cache = getCache();
final DistributionManager dm = (DistributionManager) ((InternalDistributedSystem) system).getDistributionManager();
Region<Object, Object> region = cache.createRegionFactory(getRegionShortcut()).setOffHeap(true).create(getRegionName());
OutOfOffHeapMemoryException ooohme;
try {
Object value = new byte[1024];
for (int i = 0; true; i++) {
region.put("key-" + i, value);
}
} catch (OutOfOffHeapMemoryException e) {
ooohme = e;
}
assertNotNull(ooohme);
with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(() -> cache.isClosed() && !system.isConnected() && dm.isClosed());
// wait for cache instance to be nulled out
with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(() -> GemFireCacheImpl.getInstance() == null && InternalDistributedSystem.getAnyInstance() == null);
assertNull(GemFireCacheImpl.getInstance());
// verify system was closed out due to OutOfOffHeapMemoryException
assertFalse(system.isConnected());
InternalDistributedSystem ids = (InternalDistributedSystem) system;
try {
ids.getDistributionManager();
fail("InternalDistributedSystem.getDistributionManager() should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
// verify dm was closed out due to OutOfOffHeapMemoryException
assertTrue(dm.isClosed());
try {
dm.throwIfDistributionStopped();
fail("DistributionManager.throwIfDistributionStopped() should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
// verify cache was closed out due to OutOfOffHeapMemoryException
assertTrue(cache.isClosed());
try {
cache.getCancelCriterion().checkCancelInProgress(null);
fail("GemFireCacheImpl.getCancelCriterion().checkCancelInProgress should throw DistributedSystemDisconnectedException");
} catch (DistributedSystemDisconnectedException expected) {
assertRootCause(expected, OutOfOffHeapMemoryException.class);
}
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class BackupDUnitTest method testBackupStatusCleanedUpAfterFailureOnOneMember.
@Test
public void testBackupStatusCleanedUpAfterFailureOnOneMember() throws Throwable {
IgnoredException.addIgnoredException("Uncaught exception");
IgnoredException.addIgnoredException("Stop processing");
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
// Create an observer that will fail a backup
// When this member receives a prepare
DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareBackupRequest) {
DistributionMessageObserver.setInstance(null);
IOException exception = new IOException("Backup in progess");
AdminFailureResponse response = AdminFailureResponse.create(dm, message.getSender(), exception);
response.setMsgId(((PrepareBackupRequest) message).getMsgId());
dm.putOutgoing(response);
throw new RuntimeException("Stop processing");
}
}
};
vm0.invoke(() -> {
disconnectFromDS();
DistributionMessageObserver.setInstance(observer);
});
createPersistentRegion(vm0);
createPersistentRegion(vm1);
createData(vm0, 0, 5, "A", "region1");
createData(vm0, 0, 5, "B", "region2");
try {
backup(vm2);
fail("Backup should have failed with in progress exception");
} catch (Exception expected) {
// that's ok, hte backup should have failed
}
// A second backup should succeed because the observer
// has been cleared and the backup state should be cleared.
BackupStatus status = backup(vm2);
assertEquals(2, status.getBackedUpDiskStores().size());
assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
}
Aggregations