Search in sources :

Example 6 with NodeStoppingException

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

the class TableManager method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    tablesCfg.tables().listenElements(new ConfigurationNamedListListener<>() {

        @Override
        public CompletableFuture<?> onCreate(ConfigurationNotificationEvent<TableView> ctx) {
            if (!busyLock.enterBusy()) {
                String tblName = ctx.newValue().name();
                UUID tblId = ((ExtendedTableView) ctx.newValue()).id();
                fireEvent(TableEvent.CREATE, new TableEventParameters(ctx.storageRevision(), tblId, tblName), new NodeStoppingException());
                return CompletableFuture.failedFuture(new NodeStoppingException());
            }
            try {
                onTableCreateInternal(ctx);
            } finally {
                busyLock.leaveBusy();
            }
            return CompletableFuture.completedFuture(null);
        }

        /**
         * Method for handle a table configuration event.
         *
         * @param ctx Configuration event.
         */
        private void onTableCreateInternal(ConfigurationNotificationEvent<TableView> ctx) {
            String tblName = ctx.newValue().name();
            UUID tblId = ((ExtendedTableView) ctx.newValue()).id();
            // configuration, which is not supported now.
            assert ((ExtendedTableView) ctx.newValue()).assignments() != null : IgniteStringFormatter.format("Table [id={}, name={}] has empty assignments.", tblId, tblName);
            // TODO: IGNITE-16369 Listener with any placeholder should be used instead.
            ((ExtendedTableConfiguration) tablesCfg.tables().get(tblName)).schemas().listenElements(new ConfigurationNamedListListener<>() {

                @Override
                public CompletableFuture<?> onCreate(ConfigurationNotificationEvent<SchemaView> schemasCtx) {
                    long causalityToken = schemasCtx.storageRevision();
                    if (!busyLock.enterBusy()) {
                        fireEvent(TableEvent.ALTER, new TableEventParameters(causalityToken, tblId, tblName), new NodeStoppingException());
                        return CompletableFuture.failedFuture(new NodeStoppingException());
                    }
                    try {
                        // FIXME: https://issues.apache.org/jira/browse/IGNITE-16369
                        if (ctx.storageRevision() != schemasCtx.storageRevision()) {
                            return tablesByIdVv.get(causalityToken).thenAccept(tablesById -> {
                                TableImpl table = tablesById.get(tblId);
                                ((SchemaRegistryImpl) table.schemaView()).onSchemaRegistered(SchemaSerializerImpl.INSTANCE.deserialize((schemasCtx.newValue().schema())));
                                fireEvent(TableEvent.ALTER, new TableEventParameters(causalityToken, table), null);
                            });
                        }
                        return CompletableFuture.completedFuture(null);
                    } catch (Exception e) {
                        fireEvent(TableEvent.ALTER, new TableEventParameters(causalityToken, tblId, tblName), e);
                        return CompletableFuture.failedFuture(e);
                    } finally {
                        busyLock.leaveBusy();
                    }
                }
            });
            ((ExtendedTableConfiguration) tablesCfg.tables().get(tblName)).assignments().listen(assignmentsCtx -> {
                if (!busyLock.enterBusy()) {
                    return CompletableFuture.failedFuture(new NodeStoppingException());
                }
                try {
                    // FIXME: https://issues.apache.org/jira/browse/IGNITE-16369
                    if (ctx.storageRevision() == assignmentsCtx.storageRevision()) {
                        return CompletableFuture.completedFuture(null);
                    } else {
                        return updateAssignmentInternal(assignmentsCtx.storageRevision(), tblId, assignmentsCtx);
                    }
                } finally {
                    busyLock.leaveBusy();
                }
            });
            createTableLocally(ctx.storageRevision(), tblName, tblId, (List<List<ClusterNode>>) ByteUtils.fromBytes(((ExtendedTableView) ctx.newValue()).assignments()), SchemaSerializerImpl.INSTANCE.deserialize(((ExtendedTableView) ctx.newValue()).schemas().get(String.valueOf(INITIAL_SCHEMA_VERSION)).schema()));
        }

        private CompletableFuture<?> updateAssignmentInternal(long causalityToken, UUID tblId, ConfigurationNotificationEvent<byte[]> assignmentsCtx) {
            List<List<ClusterNode>> oldAssignments = (List<List<ClusterNode>>) ByteUtils.fromBytes(assignmentsCtx.oldValue());
            List<List<ClusterNode>> newAssignments = (List<List<ClusterNode>>) ByteUtils.fromBytes(assignmentsCtx.newValue());
            CompletableFuture<?>[] futures = new CompletableFuture<?>[oldAssignments.size()];
            // TODO: be exact same amount of partitions and replicas for both old and new assignments
            for (int i = 0; i < oldAssignments.size(); i++) {
                int partId = i;
                List<ClusterNode> oldPartitionAssignment = oldAssignments.get(partId);
                List<ClusterNode> newPartitionAssignment = newAssignments.get(partId);
                var toAdd = new HashSet<>(newPartitionAssignment);
                toAdd.removeAll(oldPartitionAssignment);
                // Create new raft nodes according to new assignments.
                futures[i] = tablesByIdVv.get(causalityToken).thenCompose(tablesById -> {
                    InternalTable internalTable = tablesById.get(tblId).internalTable();
                    try {
                        return raftMgr.updateRaftGroup(raftGroupName(tblId, partId), newPartitionAssignment, toAdd, () -> new PartitionListener(tblId, new VersionedRowStore(internalTable.storage().getOrCreatePartition(partId), txManager))).thenAccept(updatedRaftGroupService -> ((InternalTableImpl) internalTable).updateInternalTableRaftGroupService(partId, updatedRaftGroupService)).exceptionally(th -> {
                            LOG.error("Failed to update raft groups one the node", th);
                            return null;
                        });
                    } catch (NodeStoppingException e) {
                        throw new AssertionError("Loza was stopped before Table manager", e);
                    }
                });
            }
            return CompletableFuture.allOf(futures);
        }

        @Override
        public CompletableFuture<?> onRename(String oldName, String newName, ConfigurationNotificationEvent<TableView> ctx) {
            return CompletableFuture.completedFuture(null);
        }

        @Override
        public CompletableFuture<?> onDelete(ConfigurationNotificationEvent<TableView> ctx) {
            if (!busyLock.enterBusy()) {
                String tblName = ctx.oldValue().name();
                UUID tblId = ((ExtendedTableView) ctx.oldValue()).id();
                fireEvent(TableEvent.DROP, new TableEventParameters(ctx.storageRevision(), tblId, tblName), new NodeStoppingException());
                return CompletableFuture.failedFuture(new NodeStoppingException());
            }
            try {
                dropTableLocally(ctx.storageRevision(), ctx.oldValue().name(), ((ExtendedTableView) ctx.oldValue()).id(), (List<List<ClusterNode>>) ByteUtils.fromBytes(((ExtendedTableView) ctx.oldValue()).assignments()));
            } finally {
                busyLock.leaveBusy();
            }
            return CompletableFuture.completedFuture(null);
        }
    });
    engine.start();
    DataRegion defaultDataRegion = engine.createDataRegion(dataStorageCfg.defaultRegion());
    dataRegions.put(DEFAULT_DATA_REGION_NAME, defaultDataRegion);
    defaultDataRegion.start();
}
Also used : IgniteTablesInternal(org.apache.ignite.internal.table.IgniteTablesInternal) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) ExtendedTableChange(org.apache.ignite.internal.configuration.schema.ExtendedTableChange) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) Path(java.nio.file.Path) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) SchemaConfiguration(org.apache.ignite.internal.configuration.schema.SchemaConfiguration) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DEFAULT_DATA_REGION_NAME(org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema.DEFAULT_DATA_REGION_NAME) CompletionException(java.util.concurrent.CompletionException) Producer(org.apache.ignite.internal.manager.Producer) StorageEngine(org.apache.ignite.internal.storage.engine.StorageEngine) UUID(java.util.UUID) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Collectors(java.util.stream.Collectors) TxManager(org.apache.ignite.internal.tx.TxManager) TableView(org.apache.ignite.configuration.schemas.table.TableView) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) NotNull(org.jetbrains.annotations.NotNull) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) Loza(org.apache.ignite.internal.raft.Loza) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) ByteUtils(org.apache.ignite.internal.util.ByteUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SchemaSerializerImpl(org.apache.ignite.internal.schema.marshaller.schema.SchemaSerializerImpl) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SchemaView(org.apache.ignite.internal.configuration.schema.SchemaView) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NoSuchElementException(java.util.NoSuchElementException) VersionedValue(org.apache.ignite.internal.causality.VersionedValue) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Files(java.nio.file.Files) NamedListView(org.apache.ignite.configuration.NamedListView) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteObjectName(org.apache.ignite.internal.util.IgniteObjectName) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) ConfigurationNotificationEvent(org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent) TableEvent(org.apache.ignite.internal.table.event.TableEvent) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) EventListener(org.apache.ignite.internal.manager.EventListener) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Table(org.apache.ignite.table.Table) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) RocksDbStorageEngine(org.apache.ignite.internal.storage.rocksdb.RocksDbStorageEngine) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) ConfigurationNotificationEvent(org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) TableView(org.apache.ignite.configuration.schemas.table.TableView) ClusterNode(org.apache.ignite.network.ClusterNode) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) InternalTable(org.apache.ignite.internal.table.InternalTable) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) CompletionException(java.util.concurrent.CompletionException) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NoSuchElementException(java.util.NoSuchElementException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IOException(java.io.IOException) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion)

Example 7 with NodeStoppingException

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

the class TableManagerTest method testGetTableDuringCreation.

/**
 * Instantiates a table and prepares Table manager.
 */
@Test
public void testGetTableDuringCreation() {
    TableDefinition scmTbl = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_FOR_DROP_NAME).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build()).withPrimaryKey("key").build();
    Phaser phaser = new Phaser(2);
    CompletableFuture<Table> createFut = CompletableFuture.supplyAsync(() -> {
        try {
            return mockManagersAndCreateTableWithDelay(scmTbl, tblManagerFut, phaser);
        } catch (NodeStoppingException e) {
            fail(e.getMessage());
        }
        return null;
    });
    CompletableFuture<Table> getFut = CompletableFuture.supplyAsync(() -> {
        phaser.awaitAdvance(0);
        return tblManagerFut.join().table(scmTbl.canonicalName());
    });
    CompletableFuture<Collection<Table>> getAllTablesFut = CompletableFuture.supplyAsync(() -> {
        phaser.awaitAdvance(0);
        return tblManagerFut.join().tables();
    });
    assertFalse(createFut.isDone());
    assertFalse(getFut.isDone());
    assertFalse(getAllTablesFut.isDone());
    phaser.arrive();
    assertSame(createFut.join(), getFut.join());
    assertEquals(1, getAllTablesFut.join().size());
}
Also used : Table(org.apache.ignite.table.Table) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Collection(java.util.Collection) Phaser(java.util.concurrent.Phaser) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 8 with NodeStoppingException

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

the class DefaultMessagingService method send0.

/**
 * Sends a message. If the target is the current node, then message will be delivered immediately.
 *
 * @param recipient Target cluster node. TODO: Maybe {@code null} due to IGNITE-16373.
 * @param address Target address.
 * @param msg Message.
 * @param correlationId Correlation id. Not null iff the message is a response to a {@link #invoke} request.
 * @return Future of the send operation.
 */
private CompletableFuture<Void> send0(@Nullable ClusterNode recipient, NetworkAddress address, NetworkMessage msg, @Nullable Long correlationId) {
    if (connectionManager.isStopped()) {
        return failedFuture(new NodeStoppingException());
    }
    InetSocketAddress addr = new InetSocketAddress(address.host(), address.port());
    if (isSelf(recipient, address.consistentId(), addr)) {
        if (correlationId != null) {
            onInvokeResponse(msg, correlationId);
        } else {
            sendToSelf(msg, null);
        }
        return CompletableFuture.completedFuture(null);
    }
    NetworkMessage message = correlationId != null ? responseFromMessage(msg, correlationId) : msg;
    String recipientConsistentId = recipient != null ? recipient.name() : address.consistentId();
    return this.sendMessage0(message, recipientConsistentId, addr);
}
Also used : NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) InetSocketAddress(java.net.InetSocketAddress)

Example 9 with NodeStoppingException

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

the class DefaultMessagingService method invoke0.

/**
 * Sends an invocation request. If the target is the current node, then message will be delivered immediately.
 *
 * @param recipient Target cluster node. TODO: Maybe {@code null} due to IGNITE-16373.
 * @param addr Target address.
 * @param msg Message.
 * @param timeout Invocation timeout.
 * @return A future holding the response or error if the expected response was not received.
 */
private CompletableFuture<NetworkMessage> invoke0(@Nullable ClusterNode recipient, NetworkAddress addr, NetworkMessage msg, long timeout) {
    if (connectionManager.isStopped()) {
        return failedFuture(new NodeStoppingException());
    }
    long correlationId = createCorrelationId();
    CompletableFuture<NetworkMessage> responseFuture = new CompletableFuture<NetworkMessage>().orTimeout(timeout, TimeUnit.MILLISECONDS);
    requestsMap.put(correlationId, responseFuture);
    InetSocketAddress address = new InetSocketAddress(addr.host(), addr.port());
    if (isSelf(recipient, addr.consistentId(), address)) {
        sendToSelf(msg, correlationId);
        return responseFuture;
    }
    InvokeRequest message = requestFromMessage(msg, correlationId);
    String recipientConsistentId = recipient != null ? recipient.name() : addr.consistentId();
    return sendMessage0(message, recipientConsistentId, address).thenCompose(unused -> responseFuture);
}
Also used : NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) InetSocketAddress(java.net.InetSocketAddress) InvokeRequest(org.apache.ignite.internal.network.message.InvokeRequest)

Example 10 with NodeStoppingException

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

the class MetaStorageManager method stop.

/**
 * {@inheritDoc}
 */
@Override
public void stop() {
    if (!stopGuard.compareAndSet(false, true)) {
        return;
    }
    busyLock.block();
    Optional<IgniteUuid> watchId;
    try {
        // TODO: add busy lock for init method https://issues.apache.org/jira/browse/IGNITE-15114
        if (deployFut.isDone()) {
            watchId = deployFut.get();
            try {
                if (watchId.isPresent()) {
                    metaStorageSvcFut.get().stopWatch(watchId.get());
                }
            } catch (InterruptedException | ExecutionException e) {
                LOG.error("Failed to get meta storage service.");
                throw new IgniteInternalException(e);
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Failed to get watch.");
        throw new IgniteInternalException(e);
    }
    try {
        if (raftGroupServiceFut != null) {
            raftGroupServiceFut.get().shutdown();
            raftMgr.stopRaftGroup(METASTORAGE_RAFT_GROUP_NAME);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Failed to get meta storage raft group service.");
        throw new IgniteInternalException(e);
    } catch (NodeStoppingException e) {
        throw new AssertionError("Loza was stopped before Meta Storage manager", e);
    }
    try {
        storage.close();
    } catch (Exception e) {
        throw new IgniteInternalException("Exception when stopping the storage", e);
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ExecutionException(java.util.concurrent.ExecutionException) OperationTimeoutException(org.apache.ignite.internal.metastorage.client.OperationTimeoutException) CompactedException(org.apache.ignite.internal.metastorage.client.CompactedException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NoSuchElementException(java.util.NoSuchElementException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)13 IgniteException (org.apache.ignite.lang.IgniteException)6 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)6 Table (org.apache.ignite.table.Table)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 UUID (java.util.UUID)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Nullable (org.jetbrains.annotations.Nullable)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)3 IgniteComponent (org.apache.ignite.internal.manager.IgniteComponent)3 Loza (org.apache.ignite.internal.raft.Loza)3