Skip to content

Commit

Permalink
IGNITE-24587 Use production defaults when starting benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
rpuch committed Feb 21, 2025
1 parent 400990d commit 783832c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import org.apache.ignite.internal.configuration.SystemDistributedExtensionConfiguration;
import org.apache.ignite.internal.configuration.SystemDistributedExtensionConfigurationSchema;
import org.apache.ignite.internal.configuration.SystemLocalConfiguration;
import org.apache.ignite.internal.configuration.SystemLocalExtensionConfigurationSchema;
import org.apache.ignite.internal.configuration.storage.DistributedConfigurationStorage;
import org.apache.ignite.internal.configuration.storage.LocalFileConfigurationStorage;
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
Expand Down Expand Up @@ -1194,7 +1195,8 @@ private class Node {
ClientConnectorExtensionConfigurationSchema.class,
StorageExtensionConfigurationSchema.class,
PersistentPageMemoryStorageEngineExtensionConfigurationSchema.class,
VolatilePageMemoryStorageEngineExtensionConfigurationSchema.class
VolatilePageMemoryStorageEngineExtensionConfigurationSchema.class,
SystemLocalExtensionConfigurationSchema.class
),
List.of(
PersistentPageMemoryProfileConfigurationSchema.class,
Expand All @@ -1203,7 +1205,7 @@ private class Node {
);

Path configPath = workDir.resolve(testInfo.getDisplayName());
TestIgnitionManager.addDefaultsToConfigurationFile(configPath);
TestIgnitionManager.writeConfigurationFileApplyingTestDefaults(configPath);

nodeCfgMgr = new ConfigurationManager(
List.of(NodeConfiguration.KEY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private void startCluster() throws Exception {
String config = IgniteStringFormatter.format(configTemplate, port, connectNodeAddr,
BASE_CLIENT_PORT + i, BASE_REST_PORT + i);

igniteServers.add(TestIgnitionManager.start(nodeName, config, workDir.resolve(nodeName)));
igniteServers.add(TestIgnitionManager.startWithProductionDefaults(nodeName, config, workDir.resolve(nodeName)));
}

String metaStorageNodeName = nodeName(BASE_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,36 @@ public class TestIgnitionManager {
* @throws IgniteException If error occurs while reading node configuration.
*/
public static IgniteServer start(String nodeName, @Nullable String configStr, Path workDir) {
return doStart(nodeName, configStr, workDir, true);
}

/**
* Starts an Ignite node with an optional bootstrap configuration from an input stream with HOCON configs.
*
* <p>When this method returns, the node is partially started and ready to accept the init command (that is, its
* REST endpoint is functional).
*
* @param nodeName Name of the node. Must not be {@code null}.
* @param configStr Optional node configuration.
* @param workDir Path to the working directory.
* @return Completable future that resolves into an Ignite node after all components are started and the cluster initialization is
* complete.
* @throws IgniteException If error occurs while reading node configuration.
*/
public static IgniteServer startWithProductionDefaults(String nodeName, @Nullable String configStr, Path workDir) {
return doStart(nodeName, configStr, workDir, false);
}

private static IgniteServer doStart(String nodeName, @Nullable String configStr, Path workDir, boolean useTestDefaults) {
try {
Files.createDirectories(workDir);
Path configPath = workDir.resolve(DEFAULT_CONFIG_NAME);

addDefaultsToConfigurationFile(configStr, configPath);
if (useTestDefaults) {
writeConfigurationFileApplyingTestDefaults(configStr, configPath);
} else {
writeConfigurationFile(configStr, configPath);
}

return IgniteServer.start(nodeName, configPath, workDir);
} catch (IOException e) {
Expand All @@ -127,21 +152,32 @@ public static IgniteServer start(String nodeName, @Nullable String configStr, Pa
/**
* Writes default values into the configuration file, according to the same rules that are used in {@link #start(String, String, Path)}.
*/
public static void addDefaultsToConfigurationFile(Path configPath) {
public static void writeConfigurationFileApplyingTestDefaults(Path configPath) {
try {
addDefaultsToConfigurationFile(null, configPath);
writeConfigurationFileApplyingTestDefaults(null, configPath);
} catch (IOException e) {
throw new IgniteException(INTERNAL_ERR, "Couldn't update node configuration file", e);
}
}

private static void addDefaultsToConfigurationFile(@Nullable String configStr, Path configPath) throws IOException {
private static void writeConfigurationFileApplyingTestDefaults(@Nullable String configStr, Path configPath) throws IOException {
if (configStr == null && Files.exists(configPath)) {
// Nothing to do.
return;
}

String configStringToWrite = applyTestDefaultsToConfig(configStr, DEFAULT_NODE_CONFIG);

writeConfigurationFile(configStringToWrite, configPath);
}

private static void writeConfigurationFile(@Nullable String configStr, Path configPath) throws IOException {
if (configStr == null && Files.exists(configPath)) {
// Nothing to do.
return;
}

Files.writeString(configPath, applyTestDefaultsToConfig(configStr, DEFAULT_NODE_CONFIG), SYNC, CREATE, TRUNCATE_EXISTING);
Files.writeString(configPath, configStr, SYNC, CREATE, TRUNCATE_EXISTING);
}

/**
Expand Down

0 comments on commit 783832c

Please sign in to comment.