denis-chudov commented on code in PR #778:
URL: https://github.com/apache/ignite-3/pull/778#discussion_r876847148


##########
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:
   fixed



-- 
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]

Reply via email to