Search in sources :

Example 6 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class ConcurrentHashMapPartitionStorage method snapshot.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Void> snapshot(Path snapshotPath) {
    return CompletableFuture.runAsync(() -> {
        try (OutputStream out = Files.newOutputStream(snapshotPath.resolve(SNAPSHOT_FILE));
            ObjectOutputStream objOut = new ObjectOutputStream(out)) {
            objOut.writeObject(map.keySet().stream().map(ByteArray::bytes).collect(toList()));
            objOut.writeObject(new ArrayList<>(map.values()));
        } catch (Exception e) {
            throw new IgniteInternalException(e);
        }
    });
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) ByteArray(org.apache.ignite.lang.ByteArray) ObjectOutputStream(java.io.ObjectOutputStream) StorageException(org.apache.ignite.internal.storage.StorageException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class ExecutionServiceImpl method onMessage.

@SuppressWarnings("unchecked")
private void onMessage(String nodeId, QueryStartRequest msg) {
    assert nodeId != null && msg != null;
    try {
        Query<RowT> qry = (Query<RowT>) queryRegistry.register(new Query<>(msg.queryId(), nodeId, null, exchangeSrvc, (q) -> queryRegistry.unregister(q.id()), LOG));
        QueryPlan qryPlan = qryPlanCache.queryPlan(new CacheKey(msg.schema(), msg.root()), () -> prepareFragment(msg.root()));
        FragmentPlan plan = (FragmentPlan) qryPlan;
        final BaseQueryContext qctx = createQueryContext(Contexts.empty(), msg.schema());
        ExecutionContext<RowT> ectx = new ExecutionContext<>(qctx, taskExecutor, msg.queryId(), locNodeId, nodeId, msg.topologyVersion(), msg.fragmentDescription(), handler, Commons.parametersMap(msg.parameters()));
        executeFragment(qry, plan, ectx);
    } catch (Throwable ex) {
        LOG.error("Failed to start query fragment", ex);
        mailboxRegistry.outboxes(msg.queryId(), msg.fragmentId(), -1).forEach(Outbox::close);
        mailboxRegistry.inboxes(msg.queryId(), msg.fragmentId(), -1).forEach(Inbox::close);
        try {
            msgSrvc.send(nodeId, FACTORY.queryStartResponse().queryId(msg.queryId()).fragmentId(msg.fragmentId()).error(ex).build());
        } catch (Exception e) {
            LOG.error("Error occurred during send error message", e);
            IgniteInternalException wrpEx = new IgniteInternalException("Error occurred during send error message", e);
            e.addSuppressed(ex);
            RunningQuery qry = queryRegistry.query(msg.queryId());
            qry.cancel();
            throw wrpEx;
        }
        throw ex;
    }
}
Also used : FragmentPlan(org.apache.ignite.internal.sql.engine.prepare.FragmentPlan) RootQuery(org.apache.ignite.internal.sql.engine.RootQuery) RunningQuery(org.apache.ignite.internal.sql.engine.RunningQuery) Query(org.apache.ignite.internal.sql.engine.Query) BaseQueryContext(org.apache.ignite.internal.sql.engine.util.BaseQueryContext) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) QueryPlan(org.apache.ignite.internal.sql.engine.prepare.QueryPlan) IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RemoteException(org.apache.ignite.internal.sql.engine.metadata.RemoteException) RunningQuery(org.apache.ignite.internal.sql.engine.RunningQuery) CacheKey(org.apache.ignite.internal.sql.engine.prepare.CacheKey)

Example 8 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class RootNode method exchangeBuffers.

private void exchangeBuffers() {
    assert !nullOrEmpty(sources()) && sources().size() == 1;
    lock.lock();
    try {
        while (ex.get() == null) {
            assert outBuff.isEmpty();
            if (inBuff.size() == inBufSize || waiting == -1) {
                Deque<RowT> tmp = inBuff;
                inBuff = outBuff;
                outBuff = tmp;
            }
            if (waiting == -1 && outBuff.isEmpty()) {
                close();
            } else if (inBuff.isEmpty() && waiting == 0) {
                int req = waiting = inBufSize;
                context().execute(() -> source().request(req), this::onError);
            }
            if (!outBuff.isEmpty() || waiting == -1) {
                break;
            }
            cond.await();
        }
    } catch (InterruptedException e) {
        throw new IgniteInternalException(e);
    } finally {
        lock.unlock();
    }
    checkException();
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Example 9 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class NettyServer method start.

/**
 * Starts the server.
 *
 * @return Future that resolves when the server is successfully started.
 */
public CompletableFuture<Void> start() {
    synchronized (startStopLock) {
        if (stopped) {
            throw new IgniteInternalException("Attempted to start an already stopped server");
        }
        if (serverStartFuture != null) {
            throw new IgniteInternalException("Attempted to start an already started server");
        }
        ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap();
        bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void initChannel(SocketChannel ch) {
                var sessionSerializationService = new PerSessionSerializationService(serializationService);
                // Get handshake manager for the new channel.
                HandshakeManager manager = handshakeManager.get();
                ch.pipeline().addLast(/*
                                     * Decoder that uses the MessageReader
                                     * to read chunked data.
                                     */
                new InboundDecoder(sessionSerializationService), // Handshake handler.
                new HandshakeHandler(manager, (consistentId) -> new MessageHandler(messageListener, consistentId, sessionSerializationService)), /*
                                     * Encoder that uses the MessageWriter
                                     * to write chunked data.
                                     */
                new ChunkedWriteHandler(), // Converts NetworkMessage to a ChunkedNetworkMessageInput
                new OutboundEncoder(sessionSerializationService), new IoExceptionSuppressingHandler());
                manager.handshakeFuture().thenAccept(newConnectionListener);
            }
        });
        int port = configuration.port();
        int portRange = configuration.portRange();
        var bindFuture = new CompletableFuture<Channel>();
        tryBind(bootstrap, port, port + portRange, port, bindFuture);
        serverStartFuture = bindFuture.handle((channel, err) -> {
            synchronized (startStopLock) {
                if (channel != null) {
                    serverCloseFuture = NettyUtils.toCompletableFuture(channel.closeFuture());
                }
                this.channel = (ServerChannel) channel;
                if (err != null || stopped) {
                    Throwable stopErr = err != null ? err : new CancellationException("Server was stopped");
                    return CompletableFuture.<Void>failedFuture(stopErr);
                } else {
                    return CompletableFuture.<Void>completedFuture(null);
                }
            }
        }).thenCompose(Function.identity());
        return serverStartFuture;
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) PerSessionSerializationService(org.apache.ignite.internal.network.serialization.PerSessionSerializationService) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) CompletableFuture(java.util.concurrent.CompletableFuture) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) CancellationException(java.util.concurrent.CancellationException) HandshakeManager(org.apache.ignite.internal.network.handshake.HandshakeManager)

Example 10 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class RaftGroupServiceTest method testSnapshotExecutionException.

/**
 * @throws Exception If failed.
 */
@Test
public void testSnapshotExecutionException() throws Exception {
    String groupId = "test";
    mockSnapshotRequest(1);
    RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, false, DELAY, executor).get(3, TimeUnit.SECONDS);
    var addr = new NetworkAddress("localhost", 8082);
    CompletableFuture<Void> fut = service.snapshot(new Peer(addr));
    try {
        fut.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IgniteInternalException);
    }
}
Also used : NetworkAddress(org.apache.ignite.network.NetworkAddress) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)58 RocksDBException (org.rocksdb.RocksDBException)19 IOException (java.io.IOException)11 Path (java.nio.file.Path)10 ArrayList (java.util.ArrayList)10 NotNull (org.jetbrains.annotations.NotNull)10 WriteBatch (org.rocksdb.WriteBatch)9 List (java.util.List)7 Entry (org.apache.ignite.internal.metastorage.server.Entry)7 NoSuchElementException (java.util.NoSuchElementException)6 NetworkAddress (org.apache.ignite.network.NetworkAddress)6 Test (org.junit.jupiter.api.Test)6 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)5 Nullable (org.jetbrains.annotations.Nullable)5 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)4 ReadOptions (org.rocksdb.ReadOptions)4 RocksIterator (org.rocksdb.RocksIterator)4 CompletableFuture (java.util.concurrent.CompletableFuture)3