Search in sources :

Example 31 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.

the class GridDiscoveryManager method sendCustomEvent.

/**
 * @param msg Custom message.
 * @throws IgniteCheckedException If failed.
 */
public void sendCustomEvent(DiscoveryCustomMessage msg) throws IgniteCheckedException {
    try {
        IgniteSecurity security = ctx.security();
        getSpi().sendCustomEvent(security.enabled() ? new SecurityAwareCustomMessageWrapper(msg, security.securityContext().subject().id()) : new CustomMessageWrapper(msg));
    } catch (IgniteClientDisconnectedException e) {
        IgniteFuture<?> reconnectFut = ctx.cluster().clientReconnectFuture();
        throw new IgniteClientDisconnectedCheckedException(reconnectFut, e.getMessage());
    } catch (IgniteException e) {
        throw new IgniteCheckedException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)

Example 32 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method metadata.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public BinaryType metadata(final int typeId, final int schemaId) {
    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
    if (ctx.clientNode()) {
        if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
            try {
                transport.requestUpToDateMetadata(typeId).get();
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            IgniteFuture<?> reconnectFut0 = reconnectFut;
            if (holder == null && reconnectFut0 != null)
                throw new IgniteClientDisconnectedException(reconnectFut0, "Client node disconnected.");
            if (log.isDebugEnabled())
                log.debug("Finished waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
        }
    } else {
        if (holder != null && IgniteThread.current() instanceof IgniteDiscoveryThread)
            return holder.metadata().wrap(binaryCtx);
        else if (holder != null && (holder.pendingVersion() - holder.acceptedVersion() > 0)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<MetadataUpdateResult> fut = transport.awaitMetadataUpdate(typeId, holder.pendingVersion());
            try {
                fut.get();
            } catch (IgniteCheckedException e) {
                log.error("Failed to wait for metadata update [typeId=" + typeId + ", schemaId=" + schemaId + ']', e);
            }
            if (log.isDebugEnabled())
                log.debug("Finished waiting for metadata update" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            holder = metadataLocCache.get(typeId);
        } else if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            // Last resort waiting.
            U.warn(log, "Schema is missing while no metadata updates are in progress " + "(will wait for schema update within timeout defined by " + IGNITE_WAIT_SCHEMA_UPDATE + " system property)" + " [typeId=" + typeId + ", missingSchemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ", binMetaUpdateTimeout=" + waitSchemaTimeout + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<?> fut = transport.awaitSchemaUpdate(typeId, schemaId);
            try {
                fut.get(waitSchemaTimeout);
            } catch (IgniteFutureTimeoutCheckedException e) {
                log.error("Timed out while waiting for schema update [typeId=" + typeId + ", schemaId=" + schemaId + ']');
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            if (log.isDebugEnabled() && holder != null && holder.metadata().hasSchema(schemaId))
                log.debug("Found the schema after wait" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
        }
    }
    if (holder != null && metadataFileStore != null) {
        try {
            metadataFileStore.waitForWriteCompletion(typeId, holder.pendingVersion());
        } catch (IgniteCheckedException e) {
            log.warning("Failed to wait for metadata write operation for [typeId=" + typeId + ", typeVer=" + holder.acceptedVersion() + ']', e);
            return null;
        }
    }
    return holder != null ? holder.metadata().wrap(binaryCtx) : null;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteDiscoveryThread(org.apache.ignite.spi.discovery.IgniteDiscoveryThread) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.

the class ConnectGateway method disconnected.

/**
 * @param reconnectFut Reconnect future.
 */
public void disconnected(IgniteFuture<?> reconnectFut) {
    lock.writeLock();
    err = new IgniteClientDisconnectedException(reconnectFut, "Failed to connect, client node disconnected.");
    lock.writeUnlock();
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 34 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.

the class ZookeeperDiscoveryImpl method sendCustomMessage.

/**
 * @param msg Message.
 */
public void sendCustomMessage(DiscoverySpiCustomMessage msg) {
    assert msg != null;
    List<ClusterNode> nodes = rtState.top.topologySnapshot();
    boolean hasServerNode = false;
    for (int i = 0, size = nodes.size(); i < size; i++) {
        ClusterNode node = nodes.get(i);
        if (!node.isClient())
            hasServerNode = true;
    }
    if (!hasServerNode)
        throw new IgniteException("Failed to send custom message: no server nodes in topology.");
    byte[] msgBytes;
    try {
        msgBytes = marshalZip(msg);
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal custom message: " + msg, e);
    }
    while (!busyLock.enterBusy()) checkState();
    try {
        ZookeeperClient zkClient = rtState.zkClient;
        saveCustomMessage(zkClient, msgBytes);
    } catch (ZookeeperClientFailedException e) {
        if (clientReconnectEnabled)
            throw new IgniteClientDisconnectedException(null, "Client is disconnected.");
        throw new IgniteException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IgniteInterruptedException(e);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 35 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.

the class GridAbstractTest method waitForTopology.

/**
 * @param expSize Expected nodes number.
 * @throws Exception If failed.
 */
protected void waitForTopology(final int expSize) throws Exception {
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            List<Ignite> nodes = G.allGrids();
            if (nodes.size() != expSize) {
                info("Wait all nodes [size=" + nodes.size() + ", exp=" + expSize + ']');
                return false;
            }
            for (Ignite node : nodes) {
                try {
                    IgniteFuture<?> reconnectFut = node.cluster().clientReconnectFuture();
                    if (reconnectFut != null && !reconnectFut.isDone()) {
                        info("Wait for size on node, reconnect is in progress [node=" + node.name() + ']');
                        return false;
                    }
                    int sizeOnNode = node.cluster().nodes().size();
                    if (sizeOnNode != expSize) {
                        info("Wait for size on node [node=" + node.name() + ", size=" + sizeOnNode + ", exp=" + expSize + ']');
                        return false;
                    }
                } catch (IgniteClientDisconnectedException e) {
                    info("Wait for size on node, node disconnected [node=" + node.name() + ']');
                    return false;
                }
            }
            return true;
        }
    }, 30_000));
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite)

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