This is an automated email from the ASF dual-hosted git repository.
sergeychugunov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new b84064e193 IGNITE-20914 Make ScaleCube's metadataTimeout configurable
(#2875)
b84064e193 is described below
commit b84064e193ef0ec1ed0101b87cf443bd4e5d0dc1
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Mon Nov 27 12:44:10 2023 +0400
IGNITE-20914 Make ScaleCube's metadataTimeout configurable (#2875)
Signed-off-by: Sergey Chugunov <[email protected]>
---
.../testframework/TestIgnitionManager.java | 49 ++++++++++++++++++----
.../ScaleCubeConfigurationSchema.java | 15 +++++++
.../scalecube/ScaleCubeClusterServiceFactory.java | 6 ++-
3 files changed, 61 insertions(+), 9 deletions(-)
diff --git
a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/TestIgnitionManager.java
b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/TestIgnitionManager.java
index fd50c0550d..91dda231aa 100644
---
a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/TestIgnitionManager.java
+++
b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/TestIgnitionManager.java
@@ -17,12 +17,14 @@
package org.apache.ignite.internal.testframework;
+import com.typesafe.config.ConfigException;
import com.typesafe.config.parser.ConfigDocument;
import com.typesafe.config.parser.ConfigDocumentFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
+import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgnitionManager;
@@ -37,6 +39,8 @@ public class TestIgnitionManager {
/** Default name of configuration file. */
public static final String DEFAULT_CONFIG_NAME = "ignite-config.conf";
+ private static final int DEFAULT_SCALECUBE_METADATA_TIMEOUT = 10_000;
+
/** Default DelayDuration in ms used for tests that is set on node init. */
public static final int DEFAULT_DELAY_DURATION_MS = 100;
@@ -48,6 +52,8 @@ public class TestIgnitionManager {
/**
* Starts an Ignite node with an optional bootstrap configuration from an
input stream with HOCON configs.
*
+ * <p>Test defaults are mixed to the configuration (only if the
corresponding config keys are not explicitly defined).
+ *
* <p>When this method returns, the node is partially started and ready to
accept the init command (that is, its
* REST endpoint is functional).
*
@@ -73,23 +79,50 @@ public class TestIgnitionManager {
* @throws IgniteException If error occurs while reading node
configuration.
*/
public static CompletableFuture<Ignite> start(String nodeName, @Nullable
String configStr, Path workDir) {
+ String enrichedConfig = enrichValidConfigWithTestDefaults(configStr);
+
try {
Files.createDirectories(workDir);
Path configPath = workDir.resolve(DEFAULT_CONFIG_NAME);
if (configStr == null) {
+ // Null config might mean that this is a restart, so we should
not rewrite the existing config file.
if (Files.notExists(configPath)) {
Files.createFile(configPath);
}
} else {
- Files.writeString(configPath, configStr,
+ assert enrichedConfig != null;
+
+ Files.writeString(configPath, enrichedConfig,
StandardOpenOption.SYNC, StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
}
+
return IgnitionManager.start(nodeName, configPath, workDir);
} catch (IOException e) {
throw new IgniteException("Couldn't write node config.", e);
}
}
+ private static @Nullable String
enrichValidConfigWithTestDefaults(@Nullable String configStr) {
+ try {
+ return enrichConfigWithTestDefaults(configStr);
+ } catch (ConfigException e) {
+ // Config is invalid, let Ignite itself reject it in a predictable
way.
+ return configStr;
+ }
+ }
+
+ private static String enrichConfigWithTestDefaults(@Nullable String
configStr) {
+ ConfigDocument configDocument = parseNullableConfigString(configStr);
+
+ configDocument = applyTestDefault(
+ configDocument,
+ "network.membership.scaleCube.metadataTimeout",
+ Integer.toString(DEFAULT_SCALECUBE_METADATA_TIMEOUT)
+ );
+
+ return configDocument.render();
+ }
+
/**
* Initializes a cluster using test defaults for cluster configuration
values that are not
* specified explicitly.
@@ -108,13 +141,7 @@ public class TestIgnitionManager {
.metaStorageNodeNames(params.metaStorageNodeNames())
.cmgNodeNames(params.cmgNodeNames());
- ConfigDocument configDocument;
-
- if (params.clusterConfiguration() == null) {
- configDocument = ConfigDocumentFactory.parseString("{}");
- } else {
- configDocument =
ConfigDocumentFactory.parseString(params.clusterConfiguration());
- }
+ ConfigDocument configDocument =
parseNullableConfigString(params.clusterConfiguration());
configDocument = applyTestDefault(
configDocument,
@@ -137,6 +164,12 @@ public class TestIgnitionManager {
return builder.build();
}
+ private static ConfigDocument parseNullableConfigString(@Nullable String
configString) {
+ String configToParse = Objects.requireNonNullElse(configString, "{}");
+
+ return ConfigDocumentFactory.parseString(configToParse);
+ }
+
private static ConfigDocument applyTestDefault(ConfigDocument document,
String path, String value) {
if (document.hasPath(path)) {
return document;
diff --git
a/modules/network/src/main/java/org/apache/ignite/internal/network/configuration/ScaleCubeConfigurationSchema.java
b/modules/network/src/main/java/org/apache/ignite/internal/network/configuration/ScaleCubeConfigurationSchema.java
index 2d10aafbe1..0f0c060044 100644
---
a/modules/network/src/main/java/org/apache/ignite/internal/network/configuration/ScaleCubeConfigurationSchema.java
+++
b/modules/network/src/main/java/org/apache/ignite/internal/network/configuration/ScaleCubeConfigurationSchema.java
@@ -45,4 +45,19 @@ public class ScaleCubeConfigurationSchema {
*/
@Value(hasDefault = true)
public final int gossipInterval = 200;
+
+ /**
+ * Gossip repeat multiplier.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Gossip_protocol">Gossip
Protocol</a>
+ */
+ @Value(hasDefault = true)
+ public final int gossipRepeatMult = 3;
+
+ /**
+ * Metadata timeout (milliseconds). This is the timeout on metadata update
operation (when one node requests metadata from
+ * another node).
+ */
+ @Value(hasDefault = true)
+ public final int metadataTimeout = 3_000;
}
diff --git
a/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
b/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
index ede2c9b20b..68e0de4097 100644
---
a/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
+++
b/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
@@ -241,7 +241,11 @@ public class ScaleCubeClusterServiceFactory {
opts.pingInterval(cfg.failurePingInterval())
.pingReqMembers(scaleCube.failurePingRequestMembers())
)
- .gossip(opts ->
opts.gossipInterval(scaleCube.gossipInterval()));
+ .gossip(opts ->
+ opts.gossipInterval(scaleCube.gossipInterval())
+ .gossipRepeatMult(scaleCube.gossipRepeatMult())
+ )
+ .metadataTimeout(scaleCube.metadataTimeout());
}
/**