use of org.apache.ignite.lang.NodeStoppingException in project ignite-3 by apache.
the class MetaStorageManager method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
String[] metastorageNodes = this.locCfgMgr.configurationRegistry().getConfiguration(NodeConfiguration.KEY).metastorageNodes().value();
Predicate<ClusterNode> metaStorageNodesContainsLocPred = clusterNode -> Arrays.asList(metastorageNodes).contains(clusterNode.name());
if (metastorageNodes.length > 0) {
metaStorageNodesOnStart = true;
List<ClusterNode> metaStorageMembers = clusterNetSvc.topologyService().allMembers().stream().filter(metaStorageNodesContainsLocPred).collect(Collectors.toList());
// without hosting metastorage, this will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metaStorageMembers.isEmpty()) {
throw new IgniteException("Cannot start meta storage manager because there is no node in the cluster that hosts meta storage.");
}
// This will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metastorageNodes.length > 1) {
throw new IgniteException("Cannot start meta storage manager because it is not allowed to start several metastorage nodes.");
}
storage.start();
try {
raftGroupServiceFut = raftMgr.prepareRaftGroup(METASTORAGE_RAFT_GROUP_NAME, metaStorageMembers, () -> new MetaStorageListener(storage));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Meta Storage manager", e);
}
this.metaStorageSvcFut = raftGroupServiceFut.thenApply(service -> new MetaStorageServiceImpl(service, clusterNetSvc.topologyService().localMember().id()));
if (hasMetastorageLocally(locCfgMgr)) {
clusterNetSvc.topologyService().addEventHandler(new TopologyEventHandler() {
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
@Override
public void onDisappeared(ClusterNode member) {
metaStorageSvcFut.thenCompose(svc -> svc.closeCursors(member.id()));
}
});
}
} else {
this.metaStorageSvcFut = new CompletableFuture<>();
}
// TODO: IGNITE-15114 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
}
use of org.apache.ignite.lang.NodeStoppingException in project ignite-3 by apache.
the class IgniteImpl method start.
/**
* Starts ignite node.
*
* @param cfg Optional node configuration based on {@link org.apache.ignite.configuration.schemas.runner.NodeConfigurationSchema} and
* {@link org.apache.ignite.configuration.schemas.network.NetworkConfigurationSchema}. Following rules are used for applying
* the configuration properties:
* <ol>
* <li>Specified property overrides existing one or just applies itself if it wasn't
* previously specified.</li>
* <li>All non-specified properties either use previous value or use default one from
* corresponding configuration schema.</li>
* </ol>
* So that, in case of initial node start (first start ever) specified configuration, supplemented with defaults, is
* used. If no configuration was provided defaults are used for all configuration properties. In case of node
* restart, specified properties override existing ones, non specified properties that also weren't specified
* previously use default values. Please pay attention that previously specified properties are searched in the
* {@code workDir} specified by the user.
*/
public void start(@Nullable String cfg) {
List<IgniteComponent> startedComponents = new ArrayList<>();
try {
// Vault startup.
doStartComponent(name, startedComponents, vaultMgr);
vaultMgr.putName(name).join();
// Node configuration manager startup.
doStartComponent(name, startedComponents, nodeCfgMgr);
// Node configuration manager bootstrap.
if (cfg != null) {
try {
nodeCfgMgr.bootstrap(cfg);
} catch (Exception e) {
throw new IgniteException("Unable to parse user-specific configuration.", e);
}
} else {
nodeCfgMgr.configurationRegistry().initializeDefaults();
}
// Start the remaining components.
List<IgniteComponent> otherComponents = List.of(nettyBootstrapFactory, clusterSvc, raftMgr, txManager, metaStorageMgr, clusterCfgMgr, baselineMgr, distributedTblMgr, qryEngine, restComponent, clientHandlerModule);
for (IgniteComponent component : otherComponents) {
doStartComponent(name, startedComponents, component);
}
notifyConfigurationListeners();
// Deploy all registered watches because all components are ready and have registered their listeners.
metaStorageMgr.deployWatches();
if (!status.compareAndSet(Status.STARTING, Status.STARTED)) {
throw new NodeStoppingException();
}
} catch (Exception e) {
String errMsg = "Unable to start node=[" + name + "].";
LOG.error(errMsg, e);
doStopNode(startedComponents);
throw new IgniteException(errMsg, e);
}
}
use of org.apache.ignite.lang.NodeStoppingException in project ignite-3 by apache.
the class DistributedConfigurationStorageTest method mockMetaStorageManager.
/**
* Creates a mock implementation of a {@link MetaStorageManager}.
*/
private MetaStorageManager mockMetaStorageManager() {
var mock = mock(MetaStorageManager.class);
when(mock.invoke(any(), anyCollection(), anyCollection())).thenAnswer(invocation -> {
SimpleCondition condition = invocation.getArgument(0);
Collection<Operation> success = invocation.getArgument(1);
Collection<Operation> failure = invocation.getArgument(2);
boolean invokeResult = metaStorage.invoke(toServerCondition(condition), success.stream().map(DistributedConfigurationStorageTest::toServerOperation).collect(toList()), failure.stream().map(DistributedConfigurationStorageTest::toServerOperation).collect(toList()));
return CompletableFuture.completedFuture(invokeResult);
});
try {
when(mock.range(any(), any())).thenAnswer(invocation -> {
ByteArray keyFrom = invocation.getArgument(0);
ByteArray keyTo = invocation.getArgument(1);
return new CursorAdapter(metaStorage.range(keyFrom.bytes(), keyTo == null ? null : keyTo.bytes()));
});
} catch (NodeStoppingException e) {
throw new RuntimeException(e);
}
return mock;
}
use of org.apache.ignite.lang.NodeStoppingException in project ignite-3 by apache.
the class TableManager method createTableLocally.
/**
* Creates local structures for a table.
*
* @param causalityToken Causality token.
* @param name Table name.
* @param tblId Table id.
* @param assignment Affinity assignment.
*/
private void createTableLocally(long causalityToken, String name, UUID tblId, List<List<ClusterNode>> assignment, SchemaDescriptor schemaDesc) {
int partitions = assignment.size();
var partitionsGroupsFutures = new ArrayList<CompletableFuture<RaftGroupService>>();
Path storageDir = partitionsStoreDir.resolve(name);
try {
Files.createDirectories(storageDir);
} catch (IOException e) {
throw new IgniteInternalException("Failed to create partitions store directory for " + name + ": " + e.getMessage(), e);
}
TableConfiguration tableCfg = tablesCfg.tables().get(name);
DataRegion dataRegion = dataRegions.computeIfAbsent(tableCfg.dataRegion().value(), dataRegionName -> {
DataRegion newDataRegion = engine.createDataRegion(dataStorageCfg.regions().get(dataRegionName));
try {
newDataRegion.start();
} catch (Exception e) {
try {
newDataRegion.stop();
} catch (Exception stopException) {
e.addSuppressed(stopException);
}
throw e;
}
return newDataRegion;
});
TableStorage tableStorage = engine.createTable(storageDir, tableCfg, dataRegion);
tableStorage.start();
for (int p = 0; p < partitions; p++) {
int partId = p;
try {
partitionsGroupsFutures.add(raftMgr.prepareRaftGroup(raftGroupName(tblId, p), assignment.get(p), () -> new PartitionListener(tblId, new VersionedRowStore(tableStorage.getOrCreatePartition(partId), txManager))));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Table manager", e);
}
}
CompletableFuture.allOf(partitionsGroupsFutures.toArray(CompletableFuture[]::new)).thenRun(() -> {
try {
Int2ObjectOpenHashMap<RaftGroupService> partitionMap = new Int2ObjectOpenHashMap<>(partitions);
for (int p = 0; p < partitions; p++) {
CompletableFuture<RaftGroupService> future = partitionsGroupsFutures.get(p);
assert future.isDone();
RaftGroupService service = future.join();
partitionMap.put(p, service);
}
InternalTableImpl internalTable = new InternalTableImpl(name, tblId, partitionMap, partitions, netAddrResolver, txManager, tableStorage);
var schemaRegistry = new SchemaRegistryImpl(v -> {
if (!busyLock.enterBusy()) {
throw new IgniteException(new NodeStoppingException());
}
try {
return tableSchema(tblId, v);
} finally {
busyLock.leaveBusy();
}
}, () -> {
if (!busyLock.enterBusy()) {
throw new IgniteException(new NodeStoppingException());
}
try {
return latestSchemaVersion(tblId);
} finally {
busyLock.leaveBusy();
}
});
schemaRegistry.onSchemaRegistered(schemaDesc);
var table = new TableImpl(internalTable, schemaRegistry);
tablesVv.update(causalityToken, previous -> {
var val = previous == null ? new HashMap() : new HashMap<>(previous);
val.put(name, table);
return val;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
});
tablesByIdVv.update(causalityToken, previous -> {
var val = previous == null ? new HashMap() : new HashMap<>(previous);
val.put(tblId, table);
return val;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
});
completeApiCreateFuture(table);
fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, table), null);
} catch (Exception e) {
fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, tblId, name), e);
}
}).join();
}
use of org.apache.ignite.lang.NodeStoppingException in project ignite-3 by apache.
the class TableManagerTest method mockManagersAndCreateTableWithDelay.
/**
* Instantiates a table and prepares Table manager. When the latch would open, the method completes.
*
* @param tableDefinition Configuration schema for a table.
* @param tblManagerFut Future for table manager.
* @param phaser Phaser for the wait.
* @return Table manager.
* @throws NodeStoppingException If something went wrong.
*/
@NotNull
private TableImpl mockManagersAndCreateTableWithDelay(TableDefinition tableDefinition, CompletableFuture<TableManager> tblManagerFut, Phaser phaser) throws NodeStoppingException {
when(rm.prepareRaftGroup(any(), any(), any())).thenAnswer(mock -> {
RaftGroupService raftGrpSrvcMock = mock(RaftGroupService.class);
when(raftGrpSrvcMock.leader()).thenReturn(new Peer(new NetworkAddress("localhost", 47500)));
return CompletableFuture.completedFuture(raftGrpSrvcMock);
});
when(ts.getByAddress(any(NetworkAddress.class))).thenReturn(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 47500)));
try (MockedStatic<SchemaUtils> schemaServiceMock = mockStatic(SchemaUtils.class)) {
schemaServiceMock.when(() -> SchemaUtils.prepareSchemaDescriptor(anyInt(), any())).thenReturn(mock(SchemaDescriptor.class));
}
try (MockedStatic<AffinityUtils> affinityServiceMock = mockStatic(AffinityUtils.class)) {
ArrayList<List<ClusterNode>> assignment = new ArrayList<>(PARTITIONS);
for (int part = 0; part < PARTITIONS; part++) {
assignment.add(new ArrayList<>(Collections.singleton(node)));
}
affinityServiceMock.when(() -> AffinityUtils.calculateAssignments(any(), anyInt(), anyInt())).thenReturn(assignment);
}
TableManager tableManager = createTableManager(tblManagerFut);
final int tablesBeforeCreation = tableManager.tables().size();
tblsCfg.tables().listen(ctx -> {
boolean createTbl = ctx.newValue().get(tableDefinition.canonicalName()) != null && ctx.oldValue().get(tableDefinition.canonicalName()) == null;
boolean dropTbl = ctx.oldValue().get(tableDefinition.canonicalName()) != null && ctx.newValue().get(tableDefinition.canonicalName()) == null;
if (!createTbl && !dropTbl) {
return CompletableFuture.completedFuture(null);
}
if (phaser != null) {
phaser.arriveAndAwaitAdvance();
}
return CompletableFuture.completedFuture(null);
});
TableImpl tbl2 = (TableImpl) tableManager.createTable(tableDefinition.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tableDefinition, tblCh).changeReplicas(REPLICAS).changePartitions(PARTITIONS));
assertNotNull(tbl2);
assertEquals(tablesBeforeCreation + 1, tableManager.tables().size());
return tbl2;
}
Aggregations