Search in sources :

Example 11 with IgniteClientDisconnectedException

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.");
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTooManyOpenFilesException(org.apache.ignite.internal.IgniteTooManyOpenFilesException)

Example 12 with IgniteClientDisconnectedException

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);
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) TxDeadlockFuture(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture)

Example 13 with IgniteClientDisconnectedException

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);
    }
}
Also used : DiscoveryServerOnlyCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Span(org.apache.ignite.internal.processors.tracing.Span) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryServerOnlyCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)

Example 14 with IgniteClientDisconnectedException

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();
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 15 with IgniteClientDisconnectedException

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));
}
Also used : CacheException(javax.cache.CacheException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Aggregations

IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)55 Ignite (org.apache.ignite.Ignite)33 IgniteException (org.apache.ignite.IgniteException)26 Test (org.junit.Test)23 CacheException (javax.cache.CacheException)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 Event (org.apache.ignite.events.Event)9 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)9 UUID (java.util.UUID)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteDiscoverySpi (org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi)6 TransactionRollbackException (org.apache.ignite.transactions.TransactionRollbackException)6 IgniteCallable (org.apache.ignite.lang.IgniteCallable)5 DiscoverySpi (org.apache.ignite.spi.discovery.DiscoverySpi)5 Callable (java.util.concurrent.Callable)4 IgniteTransactions (org.apache.ignite.IgniteTransactions)4 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3