Search in sources :

Example 86 with IgniteCheckedException

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

the class IgniteClusterImpl method setBaselineTopology.

/**
 * {@inheritDoc}
 */
@Override
public void setBaselineTopology(long topVer) {
    guard();
    try {
        if (isInMemoryMode())
            return;
        Collection<ClusterNode> top = topology(topVer);
        if (top == null)
            throw new IgniteException("Topology version does not exist: " + topVer);
        Collection<BaselineNode> target = new ArrayList<>(top.size());
        for (ClusterNode node : top) {
            if (!node.isClient())
                target.add(node);
        }
        validateBeforeBaselineChange(target);
        ctx.state().changeGlobalState(true, target, true).get();
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    } finally {
        unguard();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 87 with IgniteCheckedException

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

the class JdbcThinTcpIo method connect.

/**
 * Connect to host.
 *
 * @param addr Address.
 * @param timeout Socket connection timeout in ms.
 * @throws IOException On IO error.
 * @throws SQLException On connection reject.
 */
private void connect(InetSocketAddress addr, int timeout) throws IOException, SQLException {
    Socket sock;
    if (ConnectionProperties.SSL_MODE_REQUIRE.equalsIgnoreCase(connProps.getSslMode()))
        sock = JdbcThinSSLUtil.createSSLSocket(addr, connProps);
    else if (ConnectionProperties.SSL_MODE_DISABLE.equalsIgnoreCase(connProps.getSslMode())) {
        sock = new Socket();
        try {
            sock.connect(addr, timeout);
        } catch (IOException e) {
            throw new SQLException("Failed to connect to server [host=" + addr.getHostName() + ", port=" + addr.getPort() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
        }
    } else {
        throw new SQLException("Unknown sslMode. [sslMode=" + connProps.getSslMode() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED);
    }
    if (connProps.getSocketSendBuffer() != 0)
        sock.setSendBufferSize(connProps.getSocketSendBuffer());
    if (connProps.getSocketReceiveBuffer() != 0)
        sock.setReceiveBufferSize(connProps.getSocketReceiveBuffer());
    sock.setTcpNoDelay(connProps.isTcpNoDelay());
    try {
        endpoint = new IpcClientTcpEndpoint(sock);
        out = new BufferedOutputStream(endpoint.outputStream());
        in = new BufferedInputStream(endpoint.inputStream());
    } catch (IgniteCheckedException e) {
        throw new SQLException("Failed to connect to server [url=" + connProps.getUrl() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLException(java.sql.SQLException) BufferedInputStream(java.io.BufferedInputStream) IpcClientTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket)

Example 88 with IgniteCheckedException

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

the class GridContinuousProcessor method onDiscoDataReceived.

/**
 * @param data received discovery data.
 */
private void onDiscoDataReceived(DiscoveryData data) {
    if (!ctx.isDaemon() && data != null) {
        for (DiscoveryDataItem item : data.items) {
            try {
                if (item.prjPred != null)
                    ctx.resource().injectGeneric(item.prjPred);
                // Register handler only if local node passes projection predicate.
                if ((item.prjPred == null || item.prjPred.apply(ctx.discovery().localNode())) && !locInfos.containsKey(item.routineId))
                    registerHandler(data.nodeId, item.routineId, item.hnd, item.bufSize, item.interval, item.autoUnsubscribe, false);
                if (!item.autoUnsubscribe)
                    // Register routine locally.
                    locInfos.putIfAbsent(item.routineId, new LocalRoutineInfo(item.prjPred, item.hnd, item.bufSize, item.interval, item.autoUnsubscribe));
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to register continuous handler.", e);
            }
        }
        for (Map.Entry<UUID, Map<UUID, LocalRoutineInfo>> entry : data.clientInfos.entrySet()) {
            UUID clientNodeId = entry.getKey();
            if (!ctx.clientNode()) {
                Map<UUID, LocalRoutineInfo> clientRoutineMap = entry.getValue();
                for (Map.Entry<UUID, LocalRoutineInfo> e : clientRoutineMap.entrySet()) {
                    UUID routineId = e.getKey();
                    LocalRoutineInfo info = e.getValue();
                    try {
                        if (info.prjPred != null)
                            ctx.resource().injectGeneric(info.prjPred);
                        if (info.prjPred == null || info.prjPred.apply(ctx.discovery().localNode())) {
                            registerHandler(clientNodeId, routineId, info.hnd, info.bufSize, info.interval, info.autoUnsubscribe, false);
                        }
                    } catch (IgniteCheckedException err) {
                        U.error(log, "Failed to register continuous handler.", err);
                    }
                }
            }
            Map<UUID, LocalRoutineInfo> map = clientInfos.get(entry.getKey());
            if (map == null) {
                map = new HashMap<>();
                clientInfos.put(entry.getKey(), map);
            }
            map.putAll(entry.getValue());
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID) CachePartitionPartialCountersMap.toCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap.toCountersMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 89 with IgniteCheckedException

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

the class IgniteTxManager method resumeTx.

/**
 * Resume transaction in current thread.
 * Please don't use directly. Use tx.resume() instead.
 *
 * @param tx Transaction to be resumed.
 *
 * @see #suspendTx(GridNearTxLocal)
 * @see GridNearTxLocal#suspend()
 * @see GridNearTxLocal#resume()
 * @throws IgniteCheckedException If failed to resume tx.
 */
public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
    assert tx != null && !tx.system() : tx;
    if (!tx.state(ACTIVE)) {
        throw new IgniteCheckedException("Trying to resume transaction with incorrect state " + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
    }
    assert !threadMap.containsValue(tx) : tx;
    assert !transactionMap(tx).containsValue(tx) : tx;
    assert !haveSystemTxForThread(Thread.currentThread().getId());
    long threadId = Thread.currentThread().getId();
    if (threadMap.putIfAbsent(threadId, tx) != null)
        throw new IgniteCheckedException("Thread already has started a transaction.");
    if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
        throw new IgniteCheckedException("Thread already has started a transaction.");
    tx.threadId(threadId);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 90 with IgniteCheckedException

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

the class IgfsIpcHandler method processPathControlRequest.

/**
 * Processes path control request.
 *
 * @param ses Session.
 * @param cmd Command.
 * @param msg Message.
 * @return Response message.
 * @throws IgniteCheckedException If failed.
 */
private IgfsMessage processPathControlRequest(final IgfsClientSession ses, final IgfsIpcCommand cmd, IgfsMessage msg) throws IgniteCheckedException {
    final IgfsPathControlRequest req = (IgfsPathControlRequest) msg;
    if (log.isDebugEnabled())
        log.debug("Processing path control request [igfsName=" + igfs.name() + ", req=" + req + ']');
    final IgfsControlResponse res = new IgfsControlResponse();
    final String userName = req.userName();
    assert userName != null;
    try {
        IgfsUserContext.doAs(userName, new IgniteOutClosure<Object>() {

            @Override
            public Void apply() {
                switch(cmd) {
                    case EXISTS:
                        res.response(igfs.exists(req.path()));
                        break;
                    case INFO:
                        res.response(igfs.info(req.path()));
                        break;
                    case PATH_SUMMARY:
                        res.response(igfs.summary(req.path()));
                        break;
                    case UPDATE:
                        res.response(igfs.update(req.path(), req.properties()));
                        break;
                    case RENAME:
                        igfs.rename(req.path(), req.destinationPath());
                        res.response(true);
                        break;
                    case DELETE:
                        res.response(igfs.delete(req.path(), req.flag()));
                        break;
                    case MAKE_DIRECTORIES:
                        igfs.mkdirs(req.path(), req.properties());
                        res.response(true);
                        break;
                    case LIST_PATHS:
                        res.paths(igfs.listPaths(req.path()));
                        break;
                    case LIST_FILES:
                        res.files(igfs.listFiles(req.path()));
                        break;
                    case SET_TIMES:
                        igfs.setTimes(req.path(), req.modificationTime(), req.accessTime());
                        res.response(true);
                        break;
                    case AFFINITY:
                        res.locations(igfs.affinity(req.path(), req.start(), req.length()));
                        break;
                    case OPEN_READ:
                        {
                            IgfsInputStream igfsIn = !req.flag() ? igfs.open(req.path(), bufSize) : igfs.open(req.path(), bufSize, req.sequentialReadsBeforePrefetch());
                            long streamId = registerResource(ses, igfsIn);
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS input stream for file read [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(new IgfsInputStreamDescriptor(streamId, igfsIn.length()));
                            break;
                        }
                    case OPEN_CREATE:
                        {
                            long streamId = registerResource(ses, igfs.create(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Overwrite if exists.
                            req.flag(), // Affinity key based on replication factor.
                            affinityKey(req), // Replication factor.
                            req.replication(), // Block size.
                            req.blockSize(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file create [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    case OPEN_APPEND:
                        {
                            long streamId = registerResource(ses, igfs.append(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Create if absent.
                            req.flag(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file append [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    default:
                        assert false : "Unhandled path control request command: " + cmd;
                        break;
                }
                return null;
            }
        });
    } catch (IgniteException e) {
        throw new IgniteCheckedException(e);
    }
    if (log.isDebugEnabled())
        log.debug("Finished processing path control request [igfsName=" + igfs.name() + ", req=" + req + ", res=" + res + ']');
    return res;
}
Also used : IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsPathControlRequest(org.apache.ignite.internal.igfs.common.IgfsPathControlRequest) IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

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