Search in sources :

Example 26 with IgniteCheckedException

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

the class GridH2TreeIndex method getRowCount.

/** {@inheritDoc} */
@Override
public long getRowCount(@Nullable Session ses) {
    IndexingQueryFilter f = threadLocalFilter();
    int seg = threadLocalSegment();
    // Fast path if we don't need to perform any filtering.
    if (f == null || f.forCache((getTable()).cacheName()) == null)
        try {
            return treeForRead(seg).size();
        } catch (IgniteCheckedException e) {
            throw DbException.convert(e);
        }
    GridCursor<GridH2Row> cursor = doFind(null, false, null);
    long size = 0;
    try {
        while (cursor.next()) size++;
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
    return size;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter)

Example 27 with IgniteCheckedException

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

the class JdbcThinTcpIo method start.

/**
     * @throws IgniteCheckedException On error.
     * @throws IOException On IO error in handshake.
     */
public void start() throws IgniteCheckedException, IOException {
    Socket sock = new Socket();
    if (sockSndBuf != 0)
        sock.setSendBufferSize(sockSndBuf);
    if (sockRcvBuf != 0)
        sock.setReceiveBufferSize(sockRcvBuf);
    sock.setTcpNoDelay(tcpNoDelay);
    try {
        sock.connect(new InetSocketAddress(host, port));
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to connect to server [host=" + host + ", port=" + port + ']', e);
    }
    endpoint = new IpcClientTcpEndpoint(sock);
    out = new BufferedOutputStream(endpoint.outputStream());
    in = new BufferedInputStream(endpoint.inputStream());
    handshake();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BufferedInputStream(java.io.BufferedInputStream) InetSocketAddress(java.net.InetSocketAddress) IpcClientTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket)

Example 28 with IgniteCheckedException

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

the class JdbcThinTcpIo method handshake.

/**
     * @throws IOException On error.
     * @throws IgniteCheckedException On error.
     */
public void handshake() throws IOException, IgniteCheckedException {
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
    writer.writeByte((byte) SqlListenerRequest.HANDSHAKE);
    writer.writeShort(CURRENT_VER.major());
    writer.writeShort(CURRENT_VER.minor());
    writer.writeShort(CURRENT_VER.maintenance());
    writer.writeByte(SqlListenerNioListener.JDBC_CLIENT);
    writer.writeBoolean(distributedJoins);
    writer.writeBoolean(enforceJoinOrder);
    send(writer.array());
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, new BinaryHeapInputStream(read()), null, null, false);
    boolean accepted = reader.readBoolean();
    if (accepted)
        return;
    short maj = reader.readShort();
    short min = reader.readShort();
    short maintenance = reader.readShort();
    String err = reader.readString();
    SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(maj, min, maintenance);
    throw new IgniteCheckedException("Handshake failed [driverProtocolVer=" + CURRENT_VER + ", remoteNodeProtocolVer=" + ver + ", err=" + err + ']');
}
Also used : SqlListenerProtocolVersion(org.apache.ignite.internal.processors.odbc.SqlListenerProtocolVersion) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 29 with IgniteCheckedException

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

the class GridEventStorageManager method waitForEvent.

/**
     *
     * @param timeout Timeout.
     * @param c Optional continuation.
     * @param p Optional predicate.
     * @param types Event types to wait for.
     * @return Event.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
public Event waitForEvent(long timeout, @Nullable Runnable c, @Nullable final IgnitePredicate<? super Event> p, int... types) throws IgniteCheckedException {
    assert timeout >= 0;
    final GridFutureAdapter<Event> fut = new GridFutureAdapter<>();
    addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            if (p == null || p.apply(evt)) {
                fut.onDone(evt);
                removeLocalEventListener(this);
            }
        }
    }, types);
    try {
        if (c != null)
            c.run();
    } catch (Exception e) {
        throw new IgniteCheckedException(e);
    }
    return fut.get(timeout);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 30 with IgniteCheckedException

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

the class GridCacheIoManager method safeSend.

/**
     * Sends message and automatically accounts for lefts nodes.
     *
     * @param nodes Nodes to send to.
     * @param msg Message to send.
     * @param plc IO policy.
     * @param fallback Callback for failed nodes.
     * @throws IgniteCheckedException If send failed.
     */
@SuppressWarnings({ "BusyWait", "unchecked" })
public void safeSend(Collection<? extends ClusterNode> nodes, GridCacheMessage msg, byte plc, @Nullable IgnitePredicate<ClusterNode> fallback) throws IgniteCheckedException {
    assert nodes != null;
    assert msg != null;
    if (nodes.isEmpty()) {
        if (log.isDebugEnabled())
            log.debug("Message will not be sent as collection of nodes is empty: " + msg);
        return;
    }
    if (!onSend(msg, null))
        return;
    if (log.isDebugEnabled())
        log.debug("Sending cache message [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
    final Collection<UUID> leftIds = new GridLeanSet<>();
    int cnt = 0;
    while (cnt < retryCnt) {
        try {
            Collection<? extends ClusterNode> nodesView = F.view(nodes, new P1<ClusterNode>() {

                @Override
                public boolean apply(ClusterNode e) {
                    return !leftIds.contains(e.id());
                }
            });
            cctx.gridIO().sendToGridTopic(nodesView, TOPIC_CACHE, msg, plc);
            boolean added = false;
            // ignored the message during stopping.
            for (ClusterNode n : nodes) {
                if (!leftIds.contains(n.id()) && !cctx.discovery().alive(n.id())) {
                    leftIds.add(n.id());
                    if (fallback != null && !fallback.apply(n))
                        // If fallback signalled to stop.
                        return;
                    added = true;
                }
            }
            if (added) {
                if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
                    if (log.isDebugEnabled())
                        log.debug("Message will not be sent because all nodes left topology [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
                    return;
                }
            }
            break;
        } catch (IgniteCheckedException e) {
            boolean added = false;
            for (ClusterNode n : nodes) {
                if (!leftIds.contains(n.id()) && (!cctx.discovery().alive(n.id()) || !cctx.discovery().pingNode(n.id()))) {
                    leftIds.add(n.id());
                    if (fallback != null && !fallback.apply(n))
                        // If fallback signalled to stop.
                        return;
                    added = true;
                }
            }
            if (!added) {
                cnt++;
                if (cnt == retryCnt)
                    throw e;
                U.sleep(retryDelay);
            }
            if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
                if (log.isDebugEnabled())
                    log.debug("Message will not be sent because all nodes left topology [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
                return;
            }
            if (log.isDebugEnabled())
                log.debug("Message send will be retried [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ", leftIds=" + leftIds + ']');
        }
    }
    if (log.isDebugEnabled())
        log.debug("Sent cache message [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
}
Also used : GridLeanSet(org.apache.ignite.internal.util.GridLeanSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96