Search in sources :

Example 1 with IgniteInternalException

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

the class RootQuery method run.

/**
 * Starts execution phase for the query and setup remote fragments.
 */
public void run(ExecutionContext<RowT> ctx, MultiStepPlan plan, Node<RowT> root) {
    synchronized (mux) {
        if (state == QueryState.CLOSED) {
            throw new IgniteInternalException("The query was cancelled while executing.");
        }
        RootNode<RowT> rootNode = new RootNode<>(ctx, plan.metadata().rowType(), this::tryClose);
        rootNode.register(root);
        addFragment(new RunningFragment<>(rootNode, ctx));
        this.root = rootNode;
        for (int i = 1; i < plan.fragments().size(); i++) {
            Fragment fragment = plan.fragments().get(i);
            List<String> nodes = plan.mapping(fragment).nodeIds();
            remotes.addAll(nodes);
            for (String node : nodes) {
                waiting.add(new RemoteFragmentKey(node, fragment.fragmentId()));
            }
        }
        state = QueryState.EXECUTING;
    }
}
Also used : RootNode(org.apache.ignite.internal.sql.engine.exec.rel.RootNode) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Fragment(org.apache.ignite.internal.sql.engine.prepare.Fragment)

Example 2 with IgniteInternalException

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

the class RootQuery method planningContext.

/**
 * Returns a planning context to prepare this query.
 */
public PlanningContext planningContext() {
    synchronized (mux) {
        if (state == QueryState.CLOSED || state == QueryState.CLOSING) {
            throw new IgniteInternalException("The query was cancelled while executing.");
        }
        if (state == QueryState.EXECUTING || state == QueryState.MAPPING) {
            throw new IgniteInternalException("Invalid query flow");
        }
        if (pctx == null) {
            state = QueryState.PLANNING;
            pctx = PlanningContext.builder().parentContext(ctx).query(sql).parameters(params).build();
            try {
                cancel.add(() -> pctx.unwrap(CancelFlag.class).requestCancel());
            } catch (QueryCancelledException e) {
                throw new IgniteInternalException(e.getMessage(), e);
            }
        }
        return pctx;
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Example 3 with IgniteInternalException

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

the class RootQuery method tryClose.

/**
 * Can be called multiple times after receive each error at {@link #onResponse(RemoteFragmentKey, Throwable)}.
 */
@Override
protected void tryClose() {
    QueryState state0 = null;
    synchronized (mux) {
        if (state == QueryState.CLOSED) {
            return;
        }
        if (state == QueryState.INITED || state == QueryState.PLANNING || state == QueryState.MAPPING) {
            state = QueryState.CLOSED;
            return;
        }
        if (state == QueryState.EXECUTING) {
            state0 = state = QueryState.CLOSING;
            root.closeInternal();
        }
        if (state == QueryState.CLOSING && waiting.isEmpty()) {
            state0 = state = QueryState.CLOSED;
        }
    }
    if (state0 == QueryState.CLOSED) {
        try {
            IgniteInternalException wrpEx = null;
            for (String nodeId : remotes) {
                try {
                    if (!nodeId.equals(root.context().localNodeId())) {
                        exchangeService.closeQuery(nodeId, id());
                    }
                } catch (IgniteInternalCheckedException e) {
                    if (wrpEx == null) {
                        wrpEx = new IgniteInternalException("Failed to send cancel message. [nodeId=" + nodeId + ']', e);
                    } else {
                        wrpEx.addSuppressed(e);
                    }
                }
            }
            if (wrpEx != null) {
                log.warn("An exception occures during the query cancel", wrpEx);
            }
        } finally {
            super.tryClose();
        }
    }
}
Also used : IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Example 4 with IgniteInternalException

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

the class RocksUtils method createSstFile.

/**
 * Creates an SST file for the column family.
 *
 * @param columnFamily Column family.
 * @param snapshot     Point-in-time snapshot.
 * @param path         Directory to put the SST file in.
 */
public static void createSstFile(ColumnFamily columnFamily, Snapshot snapshot, Path path) {
    try (EnvOptions envOptions = new EnvOptions();
        Options options = new Options();
        ReadOptions readOptions = new ReadOptions().setSnapshot(snapshot);
        RocksIterator it = columnFamily.newIterator(readOptions);
        SstFileWriter sstFileWriter = new SstFileWriter(envOptions, options)) {
        Path sstFile = path.resolve(columnFamily.name());
        sstFileWriter.open(sstFile.toString());
        it.seekToFirst();
        forEach(it, sstFileWriter::put);
        sstFileWriter.finish();
    } catch (Throwable t) {
        throw new IgniteInternalException("Failed to write snapshot: " + t.getMessage(), t);
    }
}
Also used : Path(java.nio.file.Path) ReadOptions(org.rocksdb.ReadOptions) Options(org.rocksdb.Options) EnvOptions(org.rocksdb.EnvOptions) SstFileWriter(org.rocksdb.SstFileWriter) ReadOptions(org.rocksdb.ReadOptions) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RocksIterator(org.rocksdb.RocksIterator) EnvOptions(org.rocksdb.EnvOptions)

Example 5 with IgniteInternalException

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

the class ConcurrentHashMapPartitionStorage method restoreSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public void restoreSnapshot(Path snapshotPath) {
    try (InputStream in = Files.newInputStream(snapshotPath.resolve(SNAPSHOT_FILE));
        ObjectInputStream objIn = new ObjectInputStream(in)) {
        var keys = (List<byte[]>) objIn.readObject();
        var values = (List<byte[]>) objIn.readObject();
        map.clear();
        for (int i = 0; i < keys.size(); i++) {
            map.put(new ByteArray(keys.get(i)), values.get(i));
        }
    } catch (Exception e) {
        throw new IgniteInternalException(e);
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ByteArray(org.apache.ignite.lang.ByteArray) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StorageException(org.apache.ignite.internal.storage.StorageException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ObjectInputStream(java.io.ObjectInputStream)

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