use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsGreater.
@Test
public void testTableEventIsProcessedRequiredVersionIsGreater() throws NodeStoppingException {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(tableVer - 1);
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
when(tableManager.table(eq(tableId))).thenReturn(table);
when(schemaRegistry.lastSchemaVersion()).thenReturn(tableVer);
IgniteTable actTable = schemaManager.tableById(tableId, tableVer);
assertEquals(tableId, actTable.id());
IgniteInternalException ex = assertThrows(IgniteInternalException.class, () -> schemaManager.tableById(tableId, tableVer + 1));
assertThat(ex.getMessage(), containsString("Table version not found"));
Mockito.verify(tableManager, times(2)).table(eq(tableId));
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class ScaleCubeClusterServiceFactory method createClusterService.
/**
* Creates a new {@link ClusterService} using the provided context. The created network will not be in the "started" state.
*
* @param context Cluster context.
* @param networkConfiguration Network configuration.
* @param nettyBootstrapFactory Bootstrap factory.
* @return New cluster service.
*/
public ClusterService createClusterService(ClusterLocalConfiguration context, NetworkConfiguration networkConfiguration, NettyBootstrapFactory nettyBootstrapFactory) {
var messageFactory = new NetworkMessagesFactory();
var topologyService = new ScaleCubeTopologyService();
UserObjectSerializationContext userObjectSerialization = createUserObjectSerializationContext();
var messagingService = new DefaultMessagingService(messageFactory, topologyService, userObjectSerialization);
return new AbstractClusterService(context, topologyService, messagingService) {
private volatile ClusterImpl cluster;
private volatile ConnectionManager connectionMgr;
private volatile CompletableFuture<Void> shutdownFuture;
/**
* {@inheritDoc}
*/
@Override
public void start() {
String consistentId = context.getName();
var serializationService = new SerializationService(context.getSerializationRegistry(), userObjectSerialization);
UUID launchId = UUID.randomUUID();
NetworkView configView = networkConfiguration.value();
connectionMgr = new ConnectionManager(configView, serializationService, consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), nettyBootstrapFactory);
connectionMgr.start();
var transport = new ScaleCubeDirectMarshallerTransport(connectionMgr.getLocalAddress(), messagingService, topologyService, messageFactory);
NodeFinder finder = NodeFinderFactory.createNodeFinder(configView.nodeFinder());
cluster = new ClusterImpl(clusterConfig(configView.membership())).handler(cl -> new ClusterMessageHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onMembershipEvent(MembershipEvent event) {
topologyService.onMembershipEvent(event);
}
}).config(opts -> opts.memberAlias(consistentId)).transport(opts -> opts.transportFactory(transportConfig -> transport)).membership(opts -> opts.seedMembers(parseAddresses(finder.findNodes())));
shutdownFuture = cluster.onShutdown().toFuture();
// resolve cyclic dependencies
topologyService.setCluster(cluster);
messagingService.setConnectionManager(connectionMgr);
cluster.startAwait();
// emit an artificial event as if the local member has joined the topology (ScaleCube doesn't do that)
var localMembershipEvent = MembershipEvent.createAdded(cluster.member(), null, System.currentTimeMillis());
topologyService.onMembershipEvent(localMembershipEvent);
}
/**
* {@inheritDoc}
*/
@Override
public void stop() {
// local member will be null, if cluster has not been started
if (cluster.member() == null) {
return;
}
cluster.shutdown();
try {
shutdownFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInternalException("Interrupted while waiting for the ClusterService to stop", e);
} catch (TimeoutException e) {
throw new IgniteInternalException("Timeout while waiting for the ClusterService to stop", e);
} catch (ExecutionException e) {
throw new IgniteInternalException("Unable to stop the ClusterService", e.getCause());
}
connectionMgr.stop();
// Messaging service checks connection manager's status before sending a message, so connection manager should be
// stopped before messaging service
messagingService.stop();
}
/**
* {@inheritDoc}
*/
@Override
public void beforeNodeStop() {
stop();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isStopped() {
return shutdownFuture.isDone();
}
};
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class TableManager method dropTableLocally.
/**
* Drops local structures for a table.
*
* @param causalityToken Causality token.
* @param name Table name.
* @param tblId Table id.
* @param assignment Affinity assignment.
*/
private void dropTableLocally(long causalityToken, String name, UUID tblId, List<List<ClusterNode>> assignment) {
try {
int partitions = assignment.size();
for (int p = 0; p < partitions; p++) {
raftMgr.stopRaftGroup(raftGroupName(tblId, p));
}
tablesVv.update(causalityToken, previousVal -> {
var map = new HashMap<>(previousVal);
map.remove(name);
return map;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot drop a table [name={}, id={}]", name, tblId), th);
});
Map<UUID, TableImpl> tablesByIdFut = tablesByIdVv.update(causalityToken, previousVal -> {
var map = new HashMap<>(previousVal);
map.remove(tblId);
return map;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot drop a table [name={}, id={}]", name, tblId), th);
});
TableImpl table = tablesByIdFut.get(tblId);
assert table != null : "There is no table with the name specified [name=" + name + ']';
table.internalTable().storage().destroy();
fireEvent(TableEvent.DROP, new TableEventParameters(causalityToken, table), null);
} catch (Exception e) {
fireEvent(TableEvent.DROP, new TableEventParameters(causalityToken, tblId, name), e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class CommandUtils method rowToBytes.
/**
* Writes a row to byte array.
*
* @param row Row.
* @return Row bytes.
*/
public static byte[] rowToBytes(@Nullable BinaryRow row) {
if (row == null) {
return null;
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
row.writeTo(baos);
baos.flush();
return baos.toByteArray();
} catch (IOException e) {
LOG.error("Could not write row to stream [row=" + row + ']', e);
throw new IgniteInternalException(e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class PageMemoryNoStoreImpl method stop.
@Override
public void stop(boolean deallocate) throws IgniteInternalException {
synchronized (segmentsLock) {
if (LOG.isDebugEnabled()) {
LOG.debug("Stopping page memory.");
}
started = false;
directMemoryProvider.shutdown(deallocate);
if (directMemoryProvider instanceof Closeable) {
try {
((Closeable) directMemoryProvider).close();
} catch (IOException e) {
throw new IgniteInternalException(e);
}
}
}
}
Aggregations