vldpyatkov commented on code in PR #778:
URL: https://github.com/apache/ignite-3/pull/778#discussion_r876077646
##########
modules/core/src/main/java/org/apache/ignite/internal/causality/VersionedValue.java:
##########
@@ -51,7 +51,7 @@
private static final long NOT_INITIALIZED = -1L;
/** Default history size. */
- private static final int DEFAULT_HISTORY_SIZE = 2;
+ public static final int DEFAULT_HISTORY_SIZE = 2;
Review Comment:
Why did you publish this constant?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/TableImpl.java:
##########
@@ -42,8 +42,18 @@ public class TableImpl implements Table {
/** Internal table. */
private final InternalTable tbl;
- /** Schema registry. */
- private final SchemaRegistry schemaReg;
+ /** Schema registry. Should be set either in constructor or via {@link
#schemaView(SchemaRegistry)} before start of using the table. */
+ private volatile SchemaRegistry schemaReg;
+
+ /**
+ * Constructor.
+ *
+ * @param tbl The table.
+ */
+ public TableImpl(InternalTable tbl) {
+ this.tbl = tbl;
+ this.schemaReg = schemaReg;
Review Comment:
What does the line do?
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaManager.java:
##########
@@ -0,0 +1,374 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static
org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy;
+import static
org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.configuration.NamedListView;
+import
org.apache.ignite.configuration.notifications.ConfigurationNamedListListener;
+import
org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent;
+import org.apache.ignite.configuration.schemas.table.TablesConfiguration;
+import org.apache.ignite.internal.causality.VersionedValue;
+import
org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration;
+import org.apache.ignite.internal.configuration.schema.SchemaConfiguration;
+import org.apache.ignite.internal.configuration.schema.SchemaView;
+import org.apache.ignite.internal.manager.EventListener;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.manager.Producer;
+import org.apache.ignite.internal.schema.event.SchemaEvent;
+import org.apache.ignite.internal.schema.event.SchemaEventParameters;
+import
org.apache.ignite.internal.schema.marshaller.schema.SchemaSerializerImpl;
+import org.apache.ignite.internal.schema.registry.SchemaRegistryImpl;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.apache.ignite.lang.IgniteStringFormatter;
+import org.apache.ignite.lang.NodeStoppingException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * The class services a management of table schemas.
+ */
+public class SchemaManager extends Producer<SchemaEvent,
SchemaEventParameters> implements IgniteComponent {
+ /** Initial version for schemas. */
+ public static final int INITIAL_SCHEMA_VERSION = 1;
+
+ /** Busy lock to stop synchronously. */
+ private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+ /** Prevents double stopping the component. */
+ private final AtomicBoolean stopGuard = new AtomicBoolean();
+
+ /** Tables configuration. */
+ private final TablesConfiguration tablesCfg;
+
+ /** Versioned store for tables by name. */
+ private final VersionedValue<Map<UUID, SchemaRegistryImpl>> registriesVv;
+
+ /** Constructor. */
+ public SchemaManager(Consumer<Function<Long, CompletableFuture<?>>>
registry, TablesConfiguration tablesCfg) {
+ this.registriesVv = new VersionedValue<>(registry, HashMap::new);
+
+ this.tablesCfg = tablesCfg;
+
+ registriesVv.whenComplete((token, registries, e) -> {
+ fireEvent(SchemaEvent.COMPLETE, new SchemaEventParameters(token,
null, null), e);
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void start() {
+ ((ExtendedTableConfiguration)
tablesCfg.tables().any()).schemas().listenElements(new
ConfigurationNamedListListener<>() {
+ @Override
+ public CompletableFuture<?>
onCreate(ConfigurationNotificationEvent<SchemaView> schemasCtx) {
+ return onSchemaCreate(schemasCtx);
+ }
+ });
+ }
+
+ /**
+ * Listener of schema configuration changes.
+ *
+ * @param schemasCtx Schemas configuration context.
+ * @return A future.
+ */
+ private CompletableFuture<?>
onSchemaCreate(ConfigurationNotificationEvent<SchemaView> schemasCtx) {
+ long causalityToken = schemasCtx.storageRevision();
+
+ ExtendedTableConfiguration tblCfg =
schemasCtx.config(ExtendedTableConfiguration.class);
+
+ UUID tblId = tblCfg.id().value();
+
+ String tableName = tblCfg.name().value();
+
+ SchemaDescriptor schemaDescriptor =
SchemaSerializerImpl.INSTANCE.deserialize((schemasCtx.newValue().schema()));
+
+ CompletableFuture<?> res = createSchema(causalityToken, tblId,
tableName, schemaDescriptor);
+
+ fireEvent(SchemaEvent.CREATE, new
SchemaEventParameters(causalityToken, tblId, schemaDescriptor), null);
Review Comment:
How does this event depend on the creation schema future?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -225,6 +225,25 @@ public CompletableFuture<?>
onDelete(ConfigurationNotificationEvent<TableView> c
return onTableDelete(ctx);
}
});
+
+ schemaManager.listen(SchemaEvent.CREATE, new EventListener<>() {
+ /** {@inheritDoc} */
+ @Override public boolean notify(@NotNull SchemaEventParameters
parameters, @Nullable Throwable exception) {
+
tablesByIdVv.get(parameters.causalityToken()).thenAccept(tablesById -> {
+ fireEvent(
+ TableEvent.ALTER,
+ new
TableEventParameters(parameters.causalityToken(),
tablesById.get(parameters.tableId())), null
+ );
+ });
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void remove(@NotNull Throwable exception) {
Review Comment:
It looks like a default behavior.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -189,20 +191,18 @@ public TableManager(
};
clusterNodeResolver = topologyService::getByAddress;
- tablesVv = new VersionedValue<>(registry, HashMap::new);
- tablesByIdVv = new VersionedValue<>(registry, HashMap::new);
+ tablesByIdVv = new VersionedValue<>(null, HashMap::new);
+
+ this.schemaManager.listen(SchemaEvent.COMPLETE, (parameters, e) -> {
+ tablesByIdVv.complete(parameters.causalityToken());
Review Comment:
Is that right to complete a versioned value by hand without regard to the
update revision listener?
We still guess that update of configuration handling can be asynchronous.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -549,11 +466,14 @@ private void createTableLocally(long causalityToken,
String name, UUID tblId, in
return completedFuture(val);
});
- CompletableFuture.allOf(tablesByIdVv.get(causalityToken),
tablesVv.get(causalityToken)).thenRun(() -> {
+ // TODO should be reworked in IGNITE-16763
+ schemaFut.thenCompose(v ->
tablesByIdVv.get(causalityToken)).thenRun(() -> {
Review Comment:
You can to hold this on tablesByIdVv.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -247,7 +266,7 @@ private CompletableFuture<?>
onTableCreate(ConfigurationNotificationEvent<TableV
}
try {
- createTableLocally(
+ return createTableLocally(
Review Comment:
I think, there is no a reason to do this anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]