From f38eae7abc56087e88dac656d3024f9c3148908a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 24 Jan 2020 13:10:59 -0500 Subject: [PATCH] Install plugins in a single transaction in tests (#51433) When building clusters for integration tests, today we install plugins sequentially. We recently introduced the ability to install plugins in a single invocation of the install plugin command. Using this can save substantial time starting up JVMs. This commit changes the build infrastructure to install multiple plugins at once when building clusters for integration tests. For the docs integration tests in particular, where we install many plugins, this change makes a substantial difference. On my laptop, prior to this change, installing the plugins sequentially took 115 seconds. After this change, it takes 14 seconds. --- .../testclusters/ElasticsearchNode.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java index 0b24b9acb3f..f11eca471c2 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java @@ -422,14 +422,27 @@ public class ElasticsearchNode implements TestClusterConfiguration { } createConfiguration(); + final List pluginsToInstall = new ArrayList<>(); if (plugins.isEmpty() == false) { - logToProcessStdout("Installing " + plugins.size() + " plugins"); - plugins.forEach(plugin -> runElasticsearchBinScript("elasticsearch-plugin", "install", "--batch", plugin.toString())); + pluginsToInstall.addAll(plugins.stream().map(URI::toString).collect(Collectors.toList())); } if (getVersion().before("6.3.0") && testDistribution == TestDistribution.DEFAULT) { - LOGGER.info("emulating the {} flavor for {} by installing x-pack", testDistribution, getVersion()); - runElasticsearchBinScript("elasticsearch-plugin", "install", "--batch", "x-pack"); + logToProcessStdout("emulating the " + testDistribution + " flavor for " + getVersion() + " by installing x-pack"); + pluginsToInstall.add("x-pack"); + } + + if (pluginsToInstall.isEmpty() == false) { + if (getVersion().onOrAfter("7.6.0")) { + logToProcessStdout("installing " + pluginsToInstall.size() + " plugins in a single transaction"); + final String[] arguments = Stream.concat(Stream.of("install", "--batch"), pluginsToInstall.stream()).toArray(String[]::new); + runElasticsearchBinScript("elasticsearch-plugin", arguments); + logToProcessStdout("installed plugins"); + } else { + logToProcessStdout("installing " + pluginsToInstall.size() + " plugins sequentially"); + pluginsToInstall.forEach(plugin -> runElasticsearchBinScript("elasticsearch-plugin", "install", "--batch", plugin)); + logToProcessStdout("installed plugins"); + } } if (keystoreSettings.isEmpty() == false || keystoreFiles.isEmpty() == false) {