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