sergey-chugunov-1985 commented on code in PR #12442: URL: https://github.com/apache/ignite/pull/12442#discussion_r2473274767
########## modules/core/src/main/java/org/apache/ignite/topology/MdcTopologyValidator.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.topology; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.lang.IgniteExperimental; + +/** + * Multi-Datacenter Topology Validator. + * + * <p>This class is used to validate the cluster topology in a multi-datacenter (MDC) environment + * by enforcing rules based on the visibility of datacenters. + * It provides protection against split-brain scenarios during datacenter failures or unavailability due to network issues.</p> + * + * <p>The validator supports two modes of operation:</p> + * <ul> + * <li><strong>Majority-based validation:</strong> When an odd number of datacenters are defined, the validator enables + * data modification operations in the cluster segment that contain a majority of datacenters. + * Any segment containing a minority of datacenters is considered as invalid with only read operations available.</li> + * <li><strong>Main Datacenter validation:</strong> When an even number of datacenters are defined, a main datacenter + * should be specified. The cluster segment remains write-accessible as long as the main datacenter is visible from + * all nodes of that segment.</li> + * </ul> + * + * <p><strong>Usage Requirements:</strong></p> + * <ul> + * <li>If number of datacenters is even, specify a main datacenter via {@link #setMainDatacenter(String)}. + * Set of datacenters could be left null.</li> + * <li>If number of datacenters is odd, set of datacenter IDs must be specified via {@link #setDatacenters(Set)}. + * Main datacenter setting is ignored and could be left null.</li> + * + * </ul> + * + * <p><strong>Example:</strong></p> + * <pre> + * MdcTopologyValidator mdcValidator = new MdcTopologyValidator(); + * mdcValidator.setDatacenters(Set.of("DC1", "DC2", "DC3")); + * + * CacheConfiguration cacheCfg = new CacheConfiguration("example-cache") + * .setTopologyValidator(mdcValidator) + * // other cache properties. + * </pre> + * + * <p><strong>Note:</strong> This class is marked with the {@link IgniteExperimental} annotation and may change in future releases.</p> + * + * @see TopologyValidator + * @since Apache Ignite 2.18 + */ +@IgniteExperimental +public class MdcTopologyValidator implements TopologyValidator { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private Set<String> dcs; + + /** */ + private String mainDc; + + /** @param datacenters Datacenters.*/ + public void setDatacenters(Set<String> datacenters) { + dcs = datacenters; + } + + /** @param mainDatacenter Main datacenter.*/ + public void setMainDatacenter(String mainDatacenter) { + mainDc = mainDatacenter; + } + + /** */ + public void checkConfiguration() { + if (dcs == null && mainDc == null) + throw new IllegalStateException("Missing datacenters or main datacenter."); + + if (dcs != null && dcs.isEmpty()) + throw new IllegalStateException("Missing datacenters."); + + if (mainDc != null && dcs != null && dcs.size() % 2 == 1) + throw new IllegalStateException("Datacenters count must be even when main datacenter is set."); Review Comment: ```suggestion throw new IllegalStateException("Uneven number of datacenters cannot be used along with main datacenter. Please remove main datacenter setting or specify even number of datacenters."); ``` ########## modules/core/src/test/java/org/apache/ignite/spi/failover/topology/validator/MdcTopologyValidatorTest.java: ########## @@ -0,0 +1,333 @@ +/* + * 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.spi.failover.topology.validator; + +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.CacheException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.topology.MdcTopologyValidator; +import org.junit.Test; + +/** */ +public class MdcTopologyValidatorTest extends GridCommonAbstractTest { + /** */ + private static final String DC_ID_0 = "DC0"; + + /** */ + private static final String DC_ID_1 = "DC1"; + + /** */ + private static final String DC_ID_2 = "DC2"; + + /** */ + private static final String KEY = "key"; + + /** */ + private static final String VAL = "val"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + + System.clearProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration() + .setDefaultDataRegionConfiguration( + new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ) + .setConsistentId(igniteInstanceName); + } + + /** */ + @Test + public void testEmptyConfig() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters or main datacenter"); + } + + /** */ + @Test + public void testOddDcsWithMain() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + topValidator.setMainDatacenter(DC_ID_1); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Datacenters count must be even when main datacenter is set."); + } + + /** Checks 1DC case with MdcTopologyValidator usage.*/ + @Test + public void testEmptyDc() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of()); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMajority() throws Exception { Review Comment: ```suggestion public void testNodeWithoutDcSpecifiedWithMajorityBasedValidator() throws Exception { ``` ########## modules/core/src/main/java/org/apache/ignite/topology/MdcTopologyValidator.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.topology; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.lang.IgniteExperimental; + +/** + * Multi-Datacenter Topology Validator. + * + * <p>This class is used to validate the cluster topology in a multi-datacenter (MDC) environment + * by enforcing rules based on the visibility of datacenters. + * It provides protection against split-brain scenarios during datacenter failures or unavailability due to network issues.</p> + * Review Comment: ```suggestion * * <p> * In order to use MdcTopologyValidator one has to specify datacenter ID attribute on each server node. * Datacenter ID is an arbitrary string that can be set with {@link IgniteSystemProperties#IGNITE_DATA_CENTER_ID} system property on the node startup. * All server nodes belonging to the same datacenter should specify the same datacenter ID, and nodes in different datacenters should have different datacenter IDs. * </p> ``` ########## modules/core/src/main/java/org/apache/ignite/topology/MdcTopologyValidator.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.topology; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; Review Comment: ```suggestion import java.util.stream.Stream; import org.apache.ignite.IgniteSystemProperties; ``` ########## modules/core/src/main/java/org/apache/ignite/topology/MdcTopologyValidator.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.topology; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.lang.IgniteExperimental; + +/** + * Multi-Datacenter Topology Validator. + * + * <p>This class is used to validate the cluster topology in a multi-datacenter (MDC) environment + * by enforcing rules based on the visibility of datacenters. + * It provides protection against split-brain scenarios during datacenter failures or unavailability due to network issues.</p> + * + * <p>The validator supports two modes of operation:</p> + * <ul> + * <li><strong>Majority-based validation:</strong> When an odd number of datacenters are defined, the validator enables + * data modification operations in the cluster segment that contain a majority of datacenters. + * Any segment containing a minority of datacenters is considered as invalid with only read operations available.</li> + * <li><strong>Main Datacenter validation:</strong> When an even number of datacenters are defined, a main datacenter + * should be specified. The cluster segment remains write-accessible as long as the main datacenter is visible from + * all nodes of that segment.</li> + * </ul> + * + * <p><strong>Usage Requirements:</strong></p> + * <ul> + * <li>If number of datacenters is even, specify a main datacenter via {@link #setMainDatacenter(String)}. + * Set of datacenters could be left null.</li> + * <li>If number of datacenters is odd, set of datacenter IDs must be specified via {@link #setDatacenters(Set)}. + * Main datacenter setting is ignored and could be left null.</li> + * + * </ul> + * + * <p><strong>Example:</strong></p> + * <pre> + * MdcTopologyValidator mdcValidator = new MdcTopologyValidator(); + * mdcValidator.setDatacenters(Set.of("DC1", "DC2", "DC3")); + * + * CacheConfiguration cacheCfg = new CacheConfiguration("example-cache") + * .setTopologyValidator(mdcValidator) + * // other cache properties. + * </pre> + * + * <p><strong>Note:</strong> This class is marked with the {@link IgniteExperimental} annotation and may change in future releases.</p> + * + * @see TopologyValidator + * @since Apache Ignite 2.18 + */ +@IgniteExperimental +public class MdcTopologyValidator implements TopologyValidator { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private Set<String> dcs; + + /** */ + private String mainDc; + + /** @param datacenters Datacenters.*/ + public void setDatacenters(Set<String> datacenters) { + dcs = datacenters; + } + + /** @param mainDatacenter Main datacenter.*/ + public void setMainDatacenter(String mainDatacenter) { + mainDc = mainDatacenter; + } + + /** */ + public void checkConfiguration() { + if (dcs == null && mainDc == null) + throw new IllegalStateException("Missing datacenters or main datacenter."); Review Comment: ```suggestion throw new IllegalStateException("Either set of datacenters or main datacenter should be specified."); ``` ########## modules/core/src/main/java/org/apache/ignite/topology/MdcTopologyValidator.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.topology; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.lang.IgniteExperimental; + +/** + * Multi-Datacenter Topology Validator. + * + * <p>This class is used to validate the cluster topology in a multi-datacenter (MDC) environment + * by enforcing rules based on the visibility of datacenters. + * It provides protection against split-brain scenarios during datacenter failures or unavailability due to network issues.</p> + * + * <p>The validator supports two modes of operation:</p> + * <ul> + * <li><strong>Majority-based validation:</strong> When an odd number of datacenters are defined, the validator enables + * data modification operations in the cluster segment that contain a majority of datacenters. + * Any segment containing a minority of datacenters is considered as invalid with only read operations available.</li> + * <li><strong>Main Datacenter validation:</strong> When an even number of datacenters are defined, a main datacenter + * should be specified. The cluster segment remains write-accessible as long as the main datacenter is visible from + * all nodes of that segment.</li> + * </ul> + * + * <p><strong>Usage Requirements:</strong></p> + * <ul> + * <li>If number of datacenters is even, specify a main datacenter via {@link #setMainDatacenter(String)}. + * Set of datacenters could be left null.</li> + * <li>If number of datacenters is odd, set of datacenter IDs must be specified via {@link #setDatacenters(Set)}. + * Main datacenter setting is ignored and could be left null.</li> + * + * </ul> + * + * <p><strong>Example:</strong></p> + * <pre> + * MdcTopologyValidator mdcValidator = new MdcTopologyValidator(); + * mdcValidator.setDatacenters(Set.of("DC1", "DC2", "DC3")); + * + * CacheConfiguration cacheCfg = new CacheConfiguration("example-cache") + * .setTopologyValidator(mdcValidator) + * // other cache properties. + * </pre> + * + * <p><strong>Note:</strong> This class is marked with the {@link IgniteExperimental} annotation and may change in future releases.</p> + * + * @see TopologyValidator + * @since Apache Ignite 2.18 + */ +@IgniteExperimental +public class MdcTopologyValidator implements TopologyValidator { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private Set<String> dcs; + + /** */ + private String mainDc; + + /** @param datacenters Datacenters.*/ + public void setDatacenters(Set<String> datacenters) { + dcs = datacenters; + } + + /** @param mainDatacenter Main datacenter.*/ + public void setMainDatacenter(String mainDatacenter) { + mainDc = mainDatacenter; + } + + /** */ + public void checkConfiguration() { + if (dcs == null && mainDc == null) + throw new IllegalStateException("Missing datacenters or main datacenter."); + + if (dcs != null && dcs.isEmpty()) + throw new IllegalStateException("Missing datacenters."); Review Comment: ```suggestion throw new IllegalStateException("Please provide a non-empty set of datacenters."); ``` ########## modules/core/src/test/java/org/apache/ignite/spi/failover/topology/validator/MdcTopologyValidatorTest.java: ########## @@ -0,0 +1,333 @@ +/* + * 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.spi.failover.topology.validator; + +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.CacheException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.topology.MdcTopologyValidator; +import org.junit.Test; + +/** */ +public class MdcTopologyValidatorTest extends GridCommonAbstractTest { + /** */ + private static final String DC_ID_0 = "DC0"; + + /** */ + private static final String DC_ID_1 = "DC1"; + + /** */ + private static final String DC_ID_2 = "DC2"; + + /** */ + private static final String KEY = "key"; + + /** */ + private static final String VAL = "val"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + + System.clearProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration() + .setDefaultDataRegionConfiguration( + new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ) + .setConsistentId(igniteInstanceName); + } + + /** */ + @Test + public void testEmptyConfig() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters or main datacenter"); + } + + /** */ + @Test + public void testOddDcsWithMain() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + topValidator.setMainDatacenter(DC_ID_1); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Datacenters count must be even when main datacenter is set."); + } + + /** Checks 1DC case with MdcTopologyValidator usage.*/ + @Test + public void testEmptyDc() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of()); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMajority() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMain() throws Exception { Review Comment: ```suggestion public void testNodeWithoutDcSpecifiedWithMainBasedValidator() throws Exception { ``` ########## modules/core/src/test/java/org/apache/ignite/spi/failover/topology/validator/MdcTopologyValidatorTest.java: ########## @@ -0,0 +1,333 @@ +/* + * 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.spi.failover.topology.validator; + +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.CacheException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.topology.MdcTopologyValidator; +import org.junit.Test; + +/** */ +public class MdcTopologyValidatorTest extends GridCommonAbstractTest { + /** */ + private static final String DC_ID_0 = "DC0"; + + /** */ + private static final String DC_ID_1 = "DC1"; + + /** */ + private static final String DC_ID_2 = "DC2"; + + /** */ + private static final String KEY = "key"; + + /** */ + private static final String VAL = "val"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + + System.clearProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration() + .setDefaultDataRegionConfiguration( + new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ) + .setConsistentId(igniteInstanceName); + } + + /** */ + @Test + public void testEmptyConfig() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters or main datacenter"); + } + + /** */ + @Test + public void testOddDcsWithMain() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + topValidator.setMainDatacenter(DC_ID_1); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Datacenters count must be even when main datacenter is set."); + } + + /** Checks 1DC case with MdcTopologyValidator usage.*/ + @Test + public void testEmptyDc() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of()); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMajority() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMain() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testClientDoesNotAffectValidation() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_0); + startGrid(0); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx client = startClientGrid("client"); + + waitForTopology(2); + + client.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache<Object, Object> cache = client.getOrCreateCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testTopologyValidatorEqualityCheck() throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx srv0 = startGrid(0); + + startGrid(1); + + waitForTopology(2); + + srv0.cluster().state(ClusterState.ACTIVE); + + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + CacheConfiguration<Object, Object> cfgCache1 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache1); + + stopGrid(1); + + srv0.destroyCache(cfgCache1.getName()); + + topValidator.setMainDatacenter(DC_ID_0); // Changed + + CacheConfiguration<Object, Object> cfgCache2 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache2); + + startGrid(2); + + waitForTopology(2); + + GridTestUtils.assertThrows(log, () -> startGrid(1), IgniteCheckedException.class, "Cache topology validator mismatch"); + } + + /** */ + @Test + public void testMainDc() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2, "DC4")); + topValidator.setMainDatacenter(DC_ID_1); + + IgniteCache<Object, Object> cache = createClusterWithCache(topValidator, true); + + cache.put(KEY, VAL); + assertEquals(VAL, cache.get(KEY)); + + stopGrid(2); + + cache.put(KEY, VAL + 1); + assertEquals(VAL + 1, cache.get(KEY)); + + stopGrid(1); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL + 2), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testMajority() throws Exception { Review Comment: ```suggestion public void testMajorityBasedValidator() throws Exception { ``` ########## modules/core/src/test/java/org/apache/ignite/spi/failover/topology/validator/MdcTopologyValidatorTest.java: ########## @@ -0,0 +1,333 @@ +/* + * 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.spi.failover.topology.validator; + +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.CacheException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.topology.MdcTopologyValidator; +import org.junit.Test; + +/** */ +public class MdcTopologyValidatorTest extends GridCommonAbstractTest { + /** */ + private static final String DC_ID_0 = "DC0"; + + /** */ + private static final String DC_ID_1 = "DC1"; + + /** */ + private static final String DC_ID_2 = "DC2"; + + /** */ + private static final String KEY = "key"; + + /** */ + private static final String VAL = "val"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + + System.clearProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration() + .setDefaultDataRegionConfiguration( + new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ) + .setConsistentId(igniteInstanceName); + } + + /** */ + @Test + public void testEmptyConfig() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters or main datacenter"); + } + + /** */ + @Test + public void testOddDcsWithMain() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + topValidator.setMainDatacenter(DC_ID_1); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Datacenters count must be even when main datacenter is set."); + } + + /** Checks 1DC case with MdcTopologyValidator usage.*/ + @Test + public void testEmptyDc() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of()); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMajority() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMain() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testClientDoesNotAffectValidation() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_0); + startGrid(0); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx client = startClientGrid("client"); + + waitForTopology(2); + + client.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache<Object, Object> cache = client.getOrCreateCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testTopologyValidatorEqualityCheck() throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx srv0 = startGrid(0); + + startGrid(1); + + waitForTopology(2); + + srv0.cluster().state(ClusterState.ACTIVE); + + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + CacheConfiguration<Object, Object> cfgCache1 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache1); + + stopGrid(1); + + srv0.destroyCache(cfgCache1.getName()); + + topValidator.setMainDatacenter(DC_ID_0); // Changed + + CacheConfiguration<Object, Object> cfgCache2 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache2); + + startGrid(2); + + waitForTopology(2); + + GridTestUtils.assertThrows(log, () -> startGrid(1), IgniteCheckedException.class, "Cache topology validator mismatch"); + } + + /** */ + @Test + public void testMainDc() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2, "DC4")); + topValidator.setMainDatacenter(DC_ID_1); + + IgniteCache<Object, Object> cache = createClusterWithCache(topValidator, true); + + cache.put(KEY, VAL); + assertEquals(VAL, cache.get(KEY)); + + stopGrid(2); + + cache.put(KEY, VAL + 1); + assertEquals(VAL + 1, cache.get(KEY)); + + stopGrid(1); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL + 2), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testMajority() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + IgniteCache<Object, Object> cache = createClusterWithCache(topValidator, true); + + cache.put(KEY, VAL); + assertEquals(VAL, cache.get(KEY)); + + int randomNode = ThreadLocalRandom.current().nextInt(1, 3); + + stopGrid(randomNode); + + cache.put(KEY, VAL + 1); + assertEquals(VAL + 1, cache.get(KEY)); + + stopGrid(randomNode == 1 ? 2 : 1); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL + 2), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testBigCluster() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_0); + + startGrid(0); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + + IgniteEx srv = startGrid(1); + startGrid(10); + startGrid(11); + startGrid(12); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_2); + + startGrid(2); + + waitForTopology(6); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache<Object, Object> cache = srv.createCache(cfgCache); + + cache.put(KEY, VAL); + assertEquals(VAL, cache.get(KEY)); + + stopGrid(0); + stopGrid(2); + + // Checking case when 4 nodes are alive, but only at single DC Review Comment: ```suggestion // Checking case when 4 nodes are alive, but only in single DC ``` ########## modules/core/src/test/java/org/apache/ignite/spi/failover/topology/validator/MdcTopologyValidatorTest.java: ########## @@ -0,0 +1,333 @@ +/* + * 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.spi.failover.topology.validator; + +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.CacheException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TopologyValidator; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.topology.MdcTopologyValidator; +import org.junit.Test; + +/** */ +public class MdcTopologyValidatorTest extends GridCommonAbstractTest { + /** */ + private static final String DC_ID_0 = "DC0"; + + /** */ + private static final String DC_ID_1 = "DC1"; + + /** */ + private static final String DC_ID_2 = "DC2"; + + /** */ + private static final String KEY = "key"; + + /** */ + private static final String VAL = "val"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + + System.clearProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration() + .setDefaultDataRegionConfiguration( + new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ) + .setConsistentId(igniteInstanceName); + } + + /** */ + @Test + public void testEmptyConfig() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters or main datacenter"); + } + + /** */ + @Test + public void testOddDcsWithMain() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + topValidator.setMainDatacenter(DC_ID_1); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Datacenters count must be even when main datacenter is set."); + } + + /** Checks 1DC case with MdcTopologyValidator usage.*/ + @Test + public void testEmptyDc() { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of()); + + GridTestUtils.assertThrows(log, + () -> createClusterWithCache(topValidator, false), + CacheException.class, + "Missing datacenters"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMajority() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1, DC_ID_2)); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testNodeWitoutDCWithMain() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + + IgniteEx srv = startGrid(0); + + waitForTopology(1); + + srv.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache cache = srv.createCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testClientDoesNotAffectValidation() throws Exception { + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_0); + startGrid(0); + + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx client = startClientGrid("client"); + + waitForTopology(2); + + client.cluster().state(ClusterState.ACTIVE); + + CacheConfiguration<Object, Object> cfgCache = new CacheConfiguration<>("cache").setTopologyValidator(topValidator); + + IgniteCache<Object, Object> cache = client.getOrCreateCache(cfgCache); + + GridTestUtils.assertThrows(log, () -> cache.put(KEY, VAL), IgniteException.class, "cache topology is not valid"); + } + + /** */ + @Test + public void testTopologyValidatorEqualityCheck() throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); + IgniteEx srv0 = startGrid(0); + + startGrid(1); + + waitForTopology(2); + + srv0.cluster().state(ClusterState.ACTIVE); + + MdcTopologyValidator topValidator = new MdcTopologyValidator(); + + topValidator.setMainDatacenter(DC_ID_1); + topValidator.setDatacenters(Set.of(DC_ID_0, DC_ID_1)); + + CacheConfiguration<Object, Object> cfgCache1 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache1); + + stopGrid(1); + + srv0.destroyCache(cfgCache1.getName()); + + topValidator.setMainDatacenter(DC_ID_0); // Changed + + CacheConfiguration<Object, Object> cfgCache2 = new CacheConfiguration<>(DEFAULT_CACHE_NAME).setTopologyValidator(topValidator); + + srv0.getOrCreateCache(cfgCache2); + + startGrid(2); + + waitForTopology(2); + + GridTestUtils.assertThrows(log, () -> startGrid(1), IgniteCheckedException.class, "Cache topology validator mismatch"); + } + + /** */ + @Test + public void testMainDc() throws Exception { Review Comment: ```suggestion public void testMainDcBasedValidator() throws Exception { ``` -- 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]
