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;
}
}
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;
}
}
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();
}
}
}
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);
}
}
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);
}
}
Aggregations