You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sashapolo (via GitHub)" <gi...@apache.org> on 2023/05/17 08:52:34 UTC

[GitHub] [ignite-3] sashapolo commented on a diff in pull request #2065: IGNITE-19293 Validate cluster configuration on init

sashapolo commented on code in PR #2065:
URL: https://github.com/apache/ignite-3/pull/2065#discussion_r1194883096


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -340,6 +349,17 @@ private CompletableFuture<CmgRaftService> doInit(CmgRaftService service, CmgInit
                 });
     }
 
+    private void validateConfiguration(@Nullable String configuration) {
+        if (configuration != null) {
+            List<ValidationIssue> issues = clusterConfigurationValidator.validate(configuration);
+            if (!issues.isEmpty()) {
+                throw new IllegalInitArgumentException(
+                        "Invalid configuration: " + new ConfigurationValidationException(issues).getMessage()

Review Comment:
   Should we throw this exception directly? Looks like a hack otherwise



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -331,7 +337,10 @@ private void handleInit(CmgInitMessage msg, String senderConsistentId, long corr
     }
 
     private CompletableFuture<CmgRaftService> doInit(CmgRaftService service, CmgInitMessage msg) {
-        return service.initClusterState(createClusterState(msg))
+        return CompletableFuture.runAsync(() -> {

Review Comment:
   What is this `runAsync` for?



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -331,7 +337,8 @@ private void handleInit(CmgInitMessage msg, String senderConsistentId, long corr
     }
 
     private CompletableFuture<CmgRaftService> doInit(CmgRaftService service, CmgInitMessage msg) {
-        return service.initClusterState(createClusterState(msg))
+        return CompletableFuture.runAsync(() -> validateConfiguration(msg.clusterConfigurationToApply()))

Review Comment:
   What is this `runAsync` for?



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationChanger.java:
##########
@@ -282,6 +271,22 @@ public void start() {
         storage.registerConfigurationListener(configurationStorageListener());
     }
 
+    /**
+     * Creates an empty configuration with defaults.
+     *
+     * @return Default configuration.
+     */
+    private SuperRoot defaultConfiguration() {

Review Comment:
   What is this method for?



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerExceptionHandlingTest.java:
##########
@@ -77,12 +79,18 @@ public class DdlCommandHandlerExceptionHandlingTest extends IgniteAbstractTest {
 
     private static final String ZONE_NAME = "zone1";
 
+    private final ConfigurationTreeGenerator generator = new ConfigurationTreeGenerator(

Review Comment:
   You need to call `close` on generator instances.  Please check that everywhere



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -398,12 +417,13 @@ public class IgniteImpl implements Ignite {
 
         this.cfgStorage = new DistributedConfigurationStorage(metaStorageMgr, vaultMgr);
 
+
         clusterCfgMgr = new ConfigurationManager(
                 modules.distributed().rootKeys(),
-                modules.distributed().validators(),
                 cfgStorage,
                 modules.distributed().internalSchemaExtensions(),
-                modules.distributed().polymorphicSchemaExtensions()
+                modules.distributed().polymorphicSchemaExtensions(),

Review Comment:
   looks like we need to pass the `distributedConfigurationGenerator` here. Also please fix the same issue in tests. Also, `ConfigurationManager` constructor with no generator should probably be removed and corresponding `ConfigurationRegistry` code refactored



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/ItNodeConfigurationFileTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.configuration;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.nio.file.Path;
+import java.util.UUID;
+import org.apache.ignite.configuration.validation.ConfigurationValidationException;
+import org.apache.ignite.internal.testframework.TestIgnitionManager;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.lang.IgniteException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * General integration tests for node configuration file.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class ItNodeConfigurationFileTest {

Review Comment:
   Don't we have this test in a different PR already?



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationChanger.java:
##########
@@ -274,11 +263,30 @@ public void start() throws ConfigurationChangeException {
         //Workaround for distributed configuration.
         addDefaults(superRoot);
 
+        // Validate the restored configuration
+        validateConfiguration(defaultConfiguration(), superRoot);

Review Comment:
   Doesn't it contradict what you are doing in https://github.com/apache/ignite-3/pull/2058 ? I think using empty root is a better approach



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/validation/ConfigurationValidator.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.configuration.validation;
+
+import java.util.List;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+import org.apache.ignite.internal.configuration.SuperRoot;
+import org.apache.ignite.internal.configuration.tree.ConfigurationSource;
+
+/**
+ * Configuration validator.
+ */
+public interface ConfigurationValidator {
+
+    List<ValidationIssue> validate(String src);

Review Comment:
   Missing javadocs, I wonder why checkstyle doesn't fail here



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/validation/ConfigurationValidatorImpl.java:
##########
@@ -19,52 +19,112 @@
 
 import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toMap;
+import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults;
 import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.appendKey;
+import static org.apache.ignite.internal.configuration.util.ConfigurationUtil.dropNulls;
 
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigException;
+import com.typesafe.config.ConfigFactory;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.function.Function;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-import org.apache.ignite.configuration.RootKey;
 import org.apache.ignite.configuration.annotation.NamedConfigValue;
 import org.apache.ignite.configuration.validation.ValidationIssue;
 import org.apache.ignite.configuration.validation.Validator;
+import org.apache.ignite.internal.configuration.ConfigurationTreeGenerator;
 import org.apache.ignite.internal.configuration.SuperRoot;
+import org.apache.ignite.internal.configuration.hocon.HoconConverter;
+import org.apache.ignite.internal.configuration.tree.ConfigurationSource;
 import org.apache.ignite.internal.configuration.tree.InnerNode;
 import org.apache.ignite.internal.configuration.util.AnyNodeConfigurationVisitor;
 import org.apache.ignite.internal.configuration.util.KeysTrackingConfigurationVisitor;
 import org.apache.ignite.lang.IgniteInternalException;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Utility class for configuration validation.
+ * Implementation of {@link ConfigurationValidator}.
  */
-public class ValidationUtil {
+public class ConfigurationValidatorImpl implements ConfigurationValidator {
+
+    /** Lazy annotations cache for configuration schema fields. */
+    private final Map<MemberKey, Map<Annotation, Set<Validator<?, ?>>>> cachedAnnotations = new ConcurrentHashMap<>();
+
+

Review Comment:
   extra empty line



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -398,12 +417,13 @@ public class IgniteImpl implements Ignite {
 
         this.cfgStorage = new DistributedConfigurationStorage(metaStorageMgr, vaultMgr);
 
+

Review Comment:
   redundant change



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/validation/ConfigurationValidator.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.configuration.validation;
+
+import java.util.List;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+import org.apache.ignite.internal.configuration.SuperRoot;
+import org.apache.ignite.internal.configuration.tree.ConfigurationSource;
+
+/**
+ * Configuration validator.
+ */
+public interface ConfigurationValidator {
+
+    List<ValidationIssue> validate(String src);

Review Comment:
   I would rename this to `validateHocon`



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/validation/DefaultValidators.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.configuration.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.ignite.configuration.validation.Validator;
+
+/**
+ * Collection of default configuration validators.
+ */
+public final class DefaultValidators {
+
+    /**
+     * Returns a set of default configuration validators.
+     *
+     * @return Set of default configuration validators.
+     */
+    public static Set<Validator<?, ?>> validators() {

Review Comment:
   This method is only used in one class, I think it can be inlined or extracted into a field



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -331,7 +337,10 @@ private void handleInit(CmgInitMessage msg, String senderConsistentId, long corr
     }
 
     private CompletableFuture<CmgRaftService> doInit(CmgRaftService service, CmgInitMessage msg) {
-        return service.initClusterState(createClusterState(msg))
+        return CompletableFuture.runAsync(() -> {
+                    validateConfiguration(msg.clusterConfigurationToApply());

Review Comment:
   Why do we do configuration validation here and not on the node that received the init command in the first place?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org