use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class CommunicationWorker method processDisconnect.
/**
* @param sesInfo Disconnected session information.
*/
private void processDisconnect(DisconnectedSessionInfo sesInfo) {
GridNioRecoveryDescriptor recoveryDesc = sesInfo.recoveryDescription();
ClusterNode node = recoveryDesc.node();
if (!recoveryDesc.nodeAlive(nodeGetter.apply(node.id())))
return;
try {
if (log.isDebugEnabled())
log.debug("Recovery reconnect [rmtNode=" + recoveryDesc.node().id() + ']');
GridCommunicationClient client = clientPool.reserveClient(node, sesInfo.connectionIndex());
client.release();
} catch (ClusterTopologyCheckedException e) {
if (log.isDebugEnabled())
log.debug("Recovery reconnect failed, node stopping [rmtNode=" + recoveryDesc.node().id() + ']');
} catch (IgniteTooManyOpenFilesException e) {
eRegistrySupplier.get().onException(e.getMessage(), e);
throw e;
} catch (IgniteCheckedException | IgniteException e) {
try {
if (recoveryDesc.nodeAlive(nodeGetter.apply(node.id())) && pingNode.apply(node.id())) {
if (log.isDebugEnabled()) {
log.debug("Recovery reconnect failed, will retry " + "[rmtNode=" + recoveryDesc.node().id() + ", err=" + e + ']');
}
addProcessDisconnectRequest(sesInfo);
} else {
if (log.isDebugEnabled()) {
log.debug("Recovery reconnect failed, " + "node left [rmtNode=" + recoveryDesc.node().id() + ", err=" + e + ']');
}
eRegistrySupplier.get().onException("Recovery reconnect failed, node left [rmtNode=" + recoveryDesc.node().id() + "]", e);
}
} catch (IgniteClientDisconnectedException ignored) {
if (log.isDebugEnabled())
log.debug("Failed to ping node, client disconnected.");
}
}
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteTxManager method onDisconnected.
/**
* {@inheritDoc}
*/
@Override
public void onDisconnected(IgniteFuture reconnectFut) {
for (IgniteInternalTx tx : idMap.values()) {
rollbackTx(tx, true, false);
tx.state(ROLLING_BACK);
tx.state(ROLLED_BACK);
}
for (IgniteInternalTx tx : nearIdMap.values()) {
rollbackTx(tx, true, false);
tx.state(ROLLING_BACK);
tx.state(ROLLED_BACK);
}
IgniteClientDisconnectedException err = new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.");
for (TxDeadlockFuture fut : deadlockDetectFuts.values()) fut.onDone(err);
for (TxTimeoutOnPartitionMapExchangeChangeFuture fut : txTimeoutOnPartitionMapExchangeFuts.values()) fut.onDone(err);
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class ClientImpl method sendCustomEvent.
/**
* {@inheritDoc}
*/
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
State state = this.state;
if (state == DISCONNECTED)
throw new IgniteClientDisconnectedException(null, "Failed to send custom message: client is disconnected.");
if (state == STOPPED || state == SEGMENTED || state == STARTING)
throw new IgniteException("Failed to send custom message: client is " + state.name().toLowerCase() + ".");
try {
TcpDiscoveryCustomEventMessage msg;
if (((CustomMessageWrapper) evt).delegate() instanceof DiscoveryServerOnlyCustomMessage)
msg = new TcpDiscoveryServerOnlyCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
else
msg = new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
Span rootSpan = tracing.create(TraceableMessagesTable.traceName(msg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> getLocalNodeId().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addTag(SpanTags.MESSAGE_CLASS, () -> ((CustomMessageWrapper) evt).delegate().getClass().getSimpleName()).addLog(() -> "Created");
// This root span will be parent both from local and remote nodes.
msg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
sockWriter.sendMessage(msg);
rootSpan.addLog(() -> "Sent").end();
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
}
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectCacheTest method testReconnectTransactions.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectTransactions() throws Exception {
IgniteEx client = startClientGrid(SRV_CNT);
Ignite srv = ignite(0);
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
final IgniteTransactions txs = client.transactions();
final Transaction tx = txs.txStart(OPTIMISTIC, REPEATABLE_READ);
cache.put(1, 1);
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
try {
tx.commit();
fail();
} catch (IgniteClientDisconnectedException e) {
log.info("Expected error: " + e);
assertNotNull(e.reconnectFuture());
}
try {
txs.txStart();
fail();
} catch (IgniteClientDisconnectedException e) {
log.info("Expected error: " + e);
assertNotNull(e.reconnectFuture());
}
}
});
assertNull(txs.tx());
try (Transaction tx0 = txs.txStart(OPTIMISTIC, REPEATABLE_READ)) {
cache.put(1, 1);
assertEquals(1, cache.get(1));
tx0.commit();
}
try (Transaction tx0 = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(2, 2);
assertEquals(2, cache.get(2));
tx0.commit();
}
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectCacheTest method checkOperationInProgressFails.
/**
* @param client Client.
* @param ccfg Cache configuration.
* @param msgToBlock Message to block.
* @param c Cache operation closure.
* @throws Exception If failed.
*/
private void checkOperationInProgressFails(final IgniteEx client, final CacheConfiguration<Object, Object> ccfg, Class<?> msgToBlock, final IgniteInClosure<IgniteCache<Object, Object>> c) throws Exception {
Ignite srv = ignite(0);
final UUID id = client.localNode().id();
DiscoverySpi srvSpi = spi0(srv);
final IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
for (int i = 0; i < SRV_CNT; i++) {
TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) grid(i).configuration().getCommunicationSpi();
srvCommSpi.blockMessages(msgToBlock, client.localNode().id());
}
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteClientDisconnectedException e0 = null;
try {
assertEquals(id, client.localNode().id());
c.apply(cache);
fail();
} catch (IgniteClientDisconnectedException e) {
log.info("Expected exception: " + e);
e0 = e;
} catch (CacheException e) {
log.info("Expected exception: " + e);
assertTrue("Unexpected cause: " + e.getCause(), e.getCause() instanceof IgniteClientDisconnectedException);
e0 = (IgniteClientDisconnectedException) e.getCause();
}
assertNotNull(e0);
assertNotNull(e0.reconnectFuture());
e0.reconnectFuture().get();
assertNotEquals(id, client.localNode().id());
c.apply(cache);
return null;
}
});
Thread.sleep(1000);
assertNotDone(fut);
log.info("Fail client: " + client.localNode().id());
srvSpi.failNode(client.localNode().id(), null);
try {
fut.get();
} finally {
for (int i = 0; i < SRV_CNT; i++) ((TestCommunicationSpi) grid(i).configuration().getCommunicationSpi()).stopBlock(false);
}
assertNotEquals(id, client.localNode().id());
while (true) {
try {
cache.put(1, 1);
break;
} catch (Exception e) {
MvccFeatureChecker.assertMvccWriteConflict(e);
}
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return cache.get(1) != null;
}
}, 5000);
assertEquals(1, cache.get(1));
}
Aggregations