You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/01/30 15:33:03 UTC
[ignite] branch master updated: IGNITE-10921 Add
IGNITE_OVERRIDE_CONSISTENT_ID system property.
This is an automated email from the ASF dual-hosted git repository.
ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 67acdfd IGNITE-10921 Add IGNITE_OVERRIDE_CONSISTENT_ID system property.
67acdfd is described below
commit 67acdfd181860ee2c488413b1aebf36867148188
Author: Artur Muradimov <ar...@gmail.com>
AuthorDate: Wed Jan 30 18:32:23 2019 +0300
IGNITE-10921 Add IGNITE_OVERRIDE_CONSISTENT_ID system property.
Fixes #5982.
Fixes #5891.
Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
.../org/apache/ignite/IgniteSystemProperties.java | 8 +
.../org/apache/ignite/internal/IgnitionEx.java | 6 +
.../ConsistentIdImplicitlyExplicitlyTest.java | 189 +++++++++++++++++++++
.../ignite/testsuites/IgniteBasicTestSuite.java | 5 +-
4 files changed, 207 insertions(+), 1 deletion(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 203c135..a2d1565 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -639,6 +639,14 @@ public final class IgniteSystemProperties {
*/
public static final String IGNITE_CONSISTENT_ID_BY_HOST_WITHOUT_PORT = "IGNITE_CONSISTENT_ID_BY_HOST_WITHOUT_PORT";
+ /**
+ * System property to specify consistent id of Ignite node.
+ * <p>
+ * Value of the system property will overwrite matched property
+ * {@link org.apache.ignite.configuration.IgniteConfiguration#setConsistentId(Serializable)} in configuration.
+ */
+ public static final String IGNITE_OVERRIDE_CONSISTENT_ID = "IGNITE_OVERRIDE_CONSISTENT_ID";
+
/** */
public static final String IGNITE_IO_BALANCE_PERIOD = "IGNITE_IO_BALANCE_PERIOD";
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 5ddf7cd..7643488 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -132,6 +132,7 @@ import static org.apache.ignite.IgniteState.STOPPED_ON_FAILURE;
import static org.apache.ignite.IgniteState.STOPPED_ON_SEGMENTATION;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_CLIENT;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONFIG_URL;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_CONSISTENT_ID;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DEP_MODE_OVERRIDE;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_FORCE_START_JAVA7;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOCAL_HOST;
@@ -2189,6 +2190,11 @@ public class IgnitionEx {
myCfg.setNodeId(nodeId);
+ String predefineConsistentId = IgniteSystemProperties.getString(IGNITE_OVERRIDE_CONSISTENT_ID);
+
+ if (!F.isEmpty(predefineConsistentId))
+ myCfg.setConsistentId(predefineConsistentId);
+
IgniteLogger cfgLog = initLogger(cfg.getGridLogger(), nodeId, workDir);
assert cfgLog != null;
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ConsistentIdImplicitlyExplicitlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ConsistentIdImplicitlyExplicitlyTest.java
new file mode 100644
index 0000000..06deae9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ConsistentIdImplicitlyExplicitlyTest.java
@@ -0,0 +1,189 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.regex.Pattern;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Checks consistent id in various cases.
+ */
+@RunWith(JUnit4.class)
+public class ConsistentIdImplicitlyExplicitlyTest extends GridCommonAbstractTest {
+ /** Ipaddress with port pattern. */
+ private static final String IPADDRESS_WITH_PORT_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5]):[1-9][0-9]+$";
+
+ /** Pattern. */
+ private static final Pattern ADDR_WITH_PORT_PATTERN = Pattern.compile(IPADDRESS_WITH_PORT_PATTERN);
+
+ /** Uuid as string pattern. */
+ private static final String UUID_STR_PATTERN = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}" +
+ "-[a-fA-F0-9]{12}";
+
+ /** Pattern. */
+ private static final Pattern UUID_PATTERN = Pattern.compile(UUID_STR_PATTERN);
+
+ /** Configured consistent id. */
+ private Serializable defConsistentId;
+
+ /** Persistence enabled. */
+ private boolean persistenceEnabled;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setConsistentId(defConsistentId)
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)
+ .setMaxSize(200L * 1024 * 1024)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ stopAllGrids();
+
+ cleanPersistenceDir();
+
+ defConsistentId = null;
+ persistenceEnabled = false;
+
+ System.clearProperty(IgniteSystemProperties.IGNITE_OVERRIDE_CONSISTENT_ID);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ defConsistentId = null;
+
+ if (persistenceEnabled) {
+ cleanPersistenceDir();
+
+ persistenceEnabled = false;
+ }
+
+ System.clearProperty(IgniteSystemProperties.IGNITE_OVERRIDE_CONSISTENT_ID);
+ }
+
+ /**
+ * Consistent ID is not configured neither in the {@link IgniteConfiguration} nor via the JVM property.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testConsistentIdNotConfigured() throws Exception {
+ Ignite ignite = startGrid(0);
+
+ assertNull(ignite.configuration().getConsistentId());
+
+ assertTrue(ADDR_WITH_PORT_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
+
+ info("Consistent ID: " + ignite.cluster().localNode().consistentId());
+ }
+
+ /**
+ * Consistent ID is not configurent neither in the {@link IgniteConfiguration} nor in the JVM property, and persistent
+ * enabled.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testConsistentIdNotConfiguredWithPersistence() throws Exception {
+ persistenceEnabled = true;
+
+ Ignite ignite = startGrid(0);
+
+ assertNull(ignite.configuration().getConsistentId());
+
+ assertTrue(UUID_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
+
+ info("Consistent ID: " + ignite.cluster().localNode().consistentId());
+ }
+
+ /**
+ * Consistent ID is not configured in the {@link IgniteConfiguration}, but set in the JVM property.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testConsistentIdConfiguredInJvmProp() throws Exception {
+ String specificConsistentId = "JvmProp consistent id";
+
+ System.setProperty(IgniteSystemProperties.IGNITE_OVERRIDE_CONSISTENT_ID, specificConsistentId);
+
+ Ignite ignite = startGrid(0);
+
+ assertEquals(specificConsistentId, ignite.configuration().getConsistentId());
+
+ assertEquals(specificConsistentId, ignite.cluster().localNode().consistentId());
+
+ info("Consistent ID: " + ignite.cluster().localNode().consistentId());
+ }
+
+ /**
+ * Consistent ID is configured in the {@link IgniteConfiguration}, but not in the JVM property.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testConsistentIdConfiguredInIgniteCfg() throws Exception {
+ defConsistentId = "IgniteCfg consistent id";
+
+ Ignite ignite = startGrid(0);
+
+ assertEquals(defConsistentId, ignite.configuration().getConsistentId());
+
+ assertEquals(defConsistentId, ignite.cluster().localNode().consistentId());
+
+ info("Consistent ID: " + ignite.cluster().localNode().consistentId());
+ }
+
+ /**
+ * Consistent ID is configured in the {@link IgniteConfiguration} and in the JVM property.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testConsistentIdConfiguredInIgniteCfgAndJvmProp() throws Exception {
+ defConsistentId = "IgniteCfg consistent id";
+
+ String specificConsistentId = "JvmProp consistent id";
+
+ System.setProperty(IgniteSystemProperties.IGNITE_OVERRIDE_CONSISTENT_ID, specificConsistentId);
+
+ Ignite ignite = startGrid(0);
+
+ assertEquals(specificConsistentId, ignite.configuration().getConsistentId());
+
+ assertEquals(specificConsistentId, ignite.cluster().localNode().consistentId());
+
+ info("Consistent ID: " + ignite.cluster().localNode().consistentId());
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 69e3696..3fa910c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -25,6 +25,7 @@ import org.apache.ignite.failure.StopNodeOrHaltFailureHandlerTest;
import org.apache.ignite.internal.ClassSetTest;
import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
import org.apache.ignite.internal.ClusterGroupSelfTest;
+import org.apache.ignite.internal.ConsistentIdImplicitlyExplicitlyTest;
import org.apache.ignite.internal.GridFailFastNodeFailureDetectionSelfTest;
import org.apache.ignite.internal.GridLifecycleAwareSelfTest;
import org.apache.ignite.internal.GridLifecycleBeanSelfTest;
@@ -214,7 +215,9 @@ import org.junit.runners.Suite;
PluginNodeValidationTest.class,
// In-memory Distributed MetaStorage.
- DistributedMetaStorageTest.class
+ DistributedMetaStorageTest.class,
+
+ ConsistentIdImplicitlyExplicitlyTest.class
})
public class IgniteBasicTestSuite {
}