Skip to content

Commit 3bb425b

Browse files
committed
Merge branch 'main' into diskbbq-disk-rescoring
2 parents b115fc1 + 8f02aeb commit 3bb425b

File tree

164 files changed

+4540
-3257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+4540
-3257
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginFuncTest.groovy

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
5151
def "resolves expanded bwc versions from source"() {
5252
given:
5353
internalBuild()
54-
bwcMajor1ProjectSetup()
54+
bwcProjectSetup("major1")
5555
buildFile << """
5656
apply plugin: 'elasticsearch.internal-distribution-download'
5757
@@ -81,7 +81,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
8181
def "fails on resolving bwc versions with no bundled jdk"() {
8282
given:
8383
internalBuild()
84-
bwcMajor1ProjectSetup()
84+
bwcProjectSetup("major1")
8585
buildFile << """
8686
apply plugin: 'elasticsearch.internal-distribution-download'
8787
@@ -105,12 +105,47 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
105105
"without a bundled JDK is not supported.")
106106
}
107107

108-
private void bwcMajor1ProjectSetup() {
108+
def "resolves detached version from source"() {
109+
given:
110+
internalBuild()
111+
bwcProjectSetup("main")
112+
buildFile << """
113+
apply plugin: 'elasticsearch.internal-distribution-download'
114+
115+
System.setProperty("tests.bwc.main.version", "9.2.0")
116+
117+
elasticsearch_distributions {
118+
test_distro {
119+
version = "9.2.0"
120+
type = "archive"
121+
platform = "linux"
122+
architecture = Architecture.current();
123+
detachedVersion = true
124+
}
125+
}
126+
127+
tasks.register("setupDistro", Sync) {
128+
from(elasticsearch_distributions.test_distro)
129+
into("build/distro")
130+
}
131+
"""
132+
133+
when:
134+
def result = gradleRunner("setupDistro").build()
135+
136+
then:
137+
result.task(":distribution:bwc:main:buildBwcExpandedTask").outcome == TaskOutcome.SUCCESS
138+
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
139+
assertExtractedDistroIsCreated("distribution/bwc/main/build/install/elastic-distro",
140+
'bwc-marker.txt')
141+
}
142+
143+
private void bwcProjectSetup(String bwcProjectName) {
109144
settingsFile << """
110-
include ':distribution:bwc:major1'
145+
include ':distribution:bwc:$bwcProjectName'
111146
"""
112-
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", "major1")
113-
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=major1"
147+
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", bwcProjectName)
148+
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=$bwcProjectName"
114149
new File(bwcSubProjectFolder, 'build.gradle') << """
115150
apply plugin:'base'
116151

build-tools-internal/src/main/groovy/elasticsearch.bc-upgrade-test.gradle

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ import org.elasticsearch.gradle.Version
1111
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
1212

1313
tasks.register("bcUpgradeTest", StandaloneRestIntegTestTask) {
14-
// We use a phony version here as the real version is provided via `tests.bwc.main.version` system property
15-
usesBwcDistribution(Version.fromString("0.0.0"))
16-
systemProperty("tests.old_cluster_version", "0.0.0")
17-
onlyIf("tests.bwc.main.version system property exists") { System.getProperty("tests.bwc.main.version") != null }
14+
project.gradle.taskGraph.whenReady { allTasks ->
15+
if (allTasks.hasTask(getPath())) {
16+
if (System.getProperty("tests.bwc.refspec.main") == null) {
17+
throw new GradleException("You must set the `tests.bwc.refspec.main` system property to run bcUpgradeTest")
18+
}
19+
if (System.getProperty("tests.bwc.main.version") == null) {
20+
throw new GradleException("You must set the `tests.bwc.main.version` system property to run bcUpgradeTest")
21+
}
22+
}
23+
}
24+
if (System.getProperty("tests.bwc.refspec.main") != null && System.getProperty("tests.bwc.main.version") != null) {
25+
usesBwcDistributionFromRef(System.getProperty("tests.bwc.refspec.main"), Version.fromString(System.getProperty("tests.bwc.main.version")))
26+
systemProperty("tests.old_cluster_version", System.getProperty("tests.bwc.main.version"))
27+
}
1828
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchBuildCompletePlugin.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838
import java.io.FileNotFoundException;
3939
import java.io.IOException;
4040
import java.io.OutputStream;
41+
import java.io.UncheckedIOException;
42+
import java.nio.file.FileVisitResult;
4143
import java.nio.file.Files;
4244
import java.nio.file.Path;
45+
import java.nio.file.SimpleFileVisitor;
46+
import java.nio.file.attribute.BasicFileAttributes;
4347
import java.util.ArrayList;
4448
import java.util.Arrays;
4549
import java.util.List;
@@ -66,7 +70,7 @@ public void apply(Project target) {
6670
? System.getenv("BUILD_NUMBER")
6771
: System.getenv("BUILDKITE_BUILD_NUMBER");
6872
String performanceTest = System.getenv("BUILD_PERFORMANCE_TEST");
69-
if (buildNumber != null && performanceTest == null && GradleUtils.isIncludedBuild(target) == false && OS.current() != OS.WINDOWS) {
73+
if (buildNumber != null && performanceTest == null && GradleUtils.isIncludedBuild(target) == false) {
7074
File targetFile = calculateTargetFile(target, buildNumber);
7175
File projectDir = target.getProjectDir();
7276
File gradleWorkersDir = new File(target.getGradle().getGradleUserHomeDir(), "workers/");
@@ -102,6 +106,23 @@ private File calculateTargetFile(Project target, String buildNumber) {
102106
}
103107

104108
private List<File> resolveProjectLogs(File projectDir) {
109+
// HACK: Some tests leave behind symlinks, and gradle throws an exception if it encounters symlinks.
110+
// Here we remove them before collecting logs to upload. We could instead build our own path matcher
111+
// but that seemed more complex than just deleting the irrelevant files.
112+
try {
113+
Files.walkFileTree(projectDir.toPath(), new SimpleFileVisitor<>() {
114+
@Override
115+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
116+
if (Files.isSymbolicLink(file)) {
117+
Files.delete(file);
118+
}
119+
return FileVisitResult.CONTINUE;
120+
}
121+
});
122+
} catch (IOException e) {
123+
throw new UncheckedIOException(e);
124+
}
125+
105126
var projectDirFiles = getFileOperations().fileTree(projectDir);
106127
projectDirFiles.include("**/*.hprof");
107128
projectDirFiles.include("**/build/reports/configuration-cache/**");
@@ -276,7 +297,12 @@ private static void createBuildArchiveTar(List<File> files, File projectDir, Fil
276297

277298
@NotNull
278299
private static String calculateArchivePath(Path path, Path projectPath) {
279-
return path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
300+
String archivePath = path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
301+
if (OS.current() == OS.WINDOWS) {
302+
// tar always uses forward slashes
303+
archivePath = archivePath.replace("\\", "/");
304+
}
305+
return archivePath;
280306
}
281307
}
282308
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPlugin.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void apply(Project project) {
7474
*/
7575
private void registerInternalDistributionResolutions(List<DistributionResolution> resolutions, Provider<BwcVersions> bwcVersions) {
7676
resolutions.add(new DistributionResolution("local-build", (project, distribution) -> {
77-
if (isCurrentVersion(distribution)) {
77+
if (isCurrentVersion(distribution) && distribution.isDetachedVersion() == false) {
7878
// non-external project, so depend on local build
7979
return new ProjectBasedDistributionDependency(
8080
config -> projectDependency(project.getDependencies(), distributionProjectPath(distribution), config)
@@ -86,7 +86,7 @@ private void registerInternalDistributionResolutions(List<DistributionResolution
8686
resolutions.add(new DistributionResolution("bwc", (project, distribution) -> {
8787
BwcVersions.UnreleasedVersionInfo unreleasedInfo = bwcVersions.get()
8888
.unreleasedInfo(Version.fromString(distribution.getVersion()));
89-
if (unreleasedInfo != null) {
89+
if (unreleasedInfo != null && distribution.isDetachedVersion() == false) {
9090
if (distribution.getBundledJdk() == false) {
9191
throw new GradleException(
9292
"Configuring a snapshot bwc distribution ('"
@@ -103,21 +103,17 @@ private void registerInternalDistributionResolutions(List<DistributionResolution
103103
return null;
104104
}));
105105

106-
// Distribution resolution for "override" versions. This allows for building from source for any version, including the current
106+
// Distribution resolution for "detached" versions. This allows for building from source for any version, including the current
107107
// version of existing released versions from a commit form the main branch. This is done by passing certain system properties, ex:
108108
//
109109
// -Dtests.bwc.refspec.main=deadbeef -Dtests.bwc.main.version=9.0.0
110110
//
111-
// The 'test.bwc.main.version' property should map to the version returned by the commit referenced in 'tests.bwc.refspec.main'.
112-
resolutions.add(new DistributionResolution("override", (project, distribution) -> {
113-
String versionProperty = System.getProperty("tests.bwc.main.version");
114-
// We use this phony version as a placeholder for the real version
115-
if (distribution.getVersion().equals("0.0.0")) {
116-
if (versionProperty == null) {
117-
throw new GradleException("System property 'tests.bwc.main.version' expected for building bwc version.");
118-
}
111+
// The distribution version set by 'test.bwc.main.version' property should map to the version returned by the commit
112+
// referenced in 'tests.bwc.refspec.main'.
113+
resolutions.add(new DistributionResolution("detached", (project, distribution) -> {
114+
if (distribution.isDetachedVersion()) {
119115
BwcVersions.UnreleasedVersionInfo unreleasedVersionInfo = new BwcVersions.UnreleasedVersionInfo(
120-
Version.fromString(versionProperty),
116+
Version.fromString(distribution.getVersion()),
121117
"main",
122118
":distribution:bwc:main"
123119
);

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalTestClustersPlugin.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
import org.elasticsearch.gradle.VersionProperties;
1313
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
14-
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
1514
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
16-
import org.gradle.api.NamedDomainObjectContainer;
1715
import org.gradle.api.Plugin;
1816
import org.gradle.api.Project;
1917

@@ -33,17 +31,5 @@ public void apply(Project project) {
3331
version -> (version.equals(VersionProperties.getElasticsearchVersion()) && buildParams.getSnapshotBuild() == false)
3432
|| buildParams.getBwcVersions().unreleasedInfo(version) == null
3533
);
36-
37-
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
38-
.getExtensions()
39-
.getByName(TestClustersPlugin.EXTENSION_NAME);
40-
// Limit the number of allocated processors for all nodes to 2 in the cluster by default.
41-
// This is to ensure that the tests run consistently across different environments.
42-
String processorCount = shouldConfigureTestClustersWithOneProcessor() ? "1" : "2";
43-
testClusters.configureEach(elasticsearchCluster -> elasticsearchCluster.setting("node.processors", processorCount));
44-
}
45-
46-
private boolean shouldConfigureTestClustersWithOneProcessor() {
47-
return Boolean.parseBoolean(System.getProperty("tests.configure_test_clusters_with_one_processor", "false"));
4834
}
4935
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ public void apply(Project project) {
106106
ElasticsearchDistribution defaultDistro = createDistribution(
107107
project,
108108
DEFAULT_REST_INTEG_TEST_DISTRO,
109-
VersionProperties.getElasticsearch()
109+
VersionProperties.getElasticsearch(),
110+
false
110111
);
111112
ElasticsearchDistribution integTestDistro = createDistribution(
112113
project,
113114
INTEG_TEST_REST_INTEG_TEST_DISTRO,
114115
VersionProperties.getElasticsearch(),
115-
ElasticsearchDistributionTypes.INTEG_TEST_ZIP
116+
ElasticsearchDistributionTypes.INTEG_TEST_ZIP,
117+
false
116118
);
117119

118120
// Create configures for module and plugin dependencies
@@ -238,21 +240,11 @@ public Void call(Object... args) {
238240
}
239241

240242
Version version = (Version) args[0];
241-
boolean isReleased = bwcVersions.unreleasedInfo(version) == null && version.toString().equals("0.0.0") == false;
243+
boolean isReleased = bwcVersions.unreleasedInfo(version) == null;
242244
String versionString = version.toString();
243-
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString);
244-
245-
if (jdkIsIncompatibleWithOS(Version.fromString(versionString))) {
246-
var toolChainService = project.getExtensions().getByType(JavaToolchainService.class);
247-
var fallbackJdk17Launcher = toolChainService.launcherFor(spec -> {
248-
spec.getVendor().set(JvmVendorSpec.ADOPTIUM);
249-
spec.getLanguageVersion().set(JavaLanguageVersion.of(17));
250-
});
251-
task.environment(
252-
"ES_FALLBACK_JAVA_HOME",
253-
fallbackJdk17Launcher.get().getMetadata().getInstallationPath().getAsFile().getPath()
254-
);
255-
}
245+
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString, false);
246+
247+
handleJdkIncompatibleWithOS(version, project, task);
256248
task.dependsOn(bwcDistro);
257249
registerDistributionInputs(task, bwcDistro);
258250

@@ -261,16 +253,63 @@ public Void call(Object... args) {
261253
providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath())
262254
);
263255

264-
if (version.getMajor() > 0 && version.before(bwcVersions.getMinimumWireCompatibleVersion())) {
256+
if (version.before(bwcVersions.getMinimumWireCompatibleVersion())) {
265257
// If we are upgrade testing older versions we also need to upgrade to 7.last
266258
this.call(bwcVersions.getMinimumWireCompatibleVersion());
267259
}
268260
return null;
269261
}
270262
});
263+
264+
task.getExtensions().getExtraProperties().set("usesBwcDistributionFromRef", new Closure<Void>(task) {
265+
@Override
266+
public Void call(Object... args) {
267+
if (args.length != 2 || args[0] instanceof String == false || args[1] instanceof Version == false) {
268+
throw new IllegalArgumentException("Expected arguments (String refSpec, org.elasticsearch.gradle.Version version)");
269+
}
270+
271+
String refSpec = (String) args[0];
272+
Version version = (Version) args[1];
273+
boolean isDetachedVersion = true;
274+
String versionString = version.toString();
275+
276+
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + refSpec, versionString, isDetachedVersion);
277+
handleJdkIncompatibleWithOS(version, project, task);
278+
279+
task.dependsOn(bwcDistro);
280+
registerDistributionInputs(task, bwcDistro);
281+
282+
nonInputSystemProperties.systemProperty(
283+
BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX + versionString,
284+
providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath())
285+
);
286+
return null;
287+
}
288+
});
271289
});
272290
}
273291

292+
/**
293+
* Older distributions ship with openjdk versions that are not compatible with newer kernels of ubuntu 24.04 and later
294+
* Therefore we pass explicitly the runtime java to use the adoptium jdk that is maintained longer and compatible
295+
* with newer kernels.
296+
* 8.10.4 is the last version shipped with jdk < 21. We configure these cluster to run with jdk 17 adoptium as 17 was
297+
* the last LTS release before 21
298+
*/
299+
private static void handleJdkIncompatibleWithOS(Version version, Project project, StandaloneRestIntegTestTask task) {
300+
if (jdkIsIncompatibleWithOS(version)) {
301+
var toolChainService = project.getExtensions().getByType(JavaToolchainService.class);
302+
var fallbackJdk17Launcher = toolChainService.launcherFor(spec -> {
303+
spec.getVendor().set(JvmVendorSpec.ADOPTIUM);
304+
spec.getLanguageVersion().set(JavaLanguageVersion.of(17));
305+
});
306+
task.environment(
307+
"ES_FALLBACK_JAVA_HOME",
308+
fallbackJdk17Launcher.get().getMetadata().getInstallationPath().getAsFile().getPath()
309+
);
310+
}
311+
}
312+
274313
private void copyDependencies(Project project, DependencySet dependencies, Configuration configuration) {
275314
configuration.getDependencies()
276315
.stream()
@@ -279,16 +318,23 @@ private void copyDependencies(Project project, DependencySet dependencies, Confi
279318
.forEach(dependencies::add);
280319
}
281320

282-
private ElasticsearchDistribution createDistribution(Project project, String name, String version) {
283-
return createDistribution(project, name, version, null);
321+
private ElasticsearchDistribution createDistribution(Project project, String name, String version, boolean detachedVersion) {
322+
return createDistribution(project, name, version, null, detachedVersion);
284323
}
285324

286-
private ElasticsearchDistribution createDistribution(Project project, String name, String version, ElasticsearchDistributionType type) {
325+
private ElasticsearchDistribution createDistribution(
326+
Project project,
327+
String name,
328+
String version,
329+
ElasticsearchDistributionType type,
330+
boolean detachedVersion
331+
) {
287332
NamedDomainObjectContainer<ElasticsearchDistribution> distributions = DistributionDownloadPlugin.getContainer(project);
288333
ElasticsearchDistribution maybeDistro = distributions.findByName(name);
289334
if (maybeDistro == null) {
290335
return distributions.create(name, distro -> {
291336
distro.setVersion(version);
337+
distro.setDetachedVersion(detachedVersion);
292338
distro.setArchitecture(Architecture.current());
293339
if (type != null) {
294340
distro.setType(type);

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionDefinition.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public static TransportVersionDefinition fromString(Path file, String contents,
2222

2323
String idsLine = null;
2424
if (contents.isEmpty() == false) {
25-
String[] lines = contents.split(System.lineSeparator());
25+
// Regardless of whether windows newlines exist (they could be added by git), we split on line feed.
26+
// All we care about skipping lines with the comment character, so the remaining \r won't matter
27+
String[] lines = contents.split("\n");
2628
for (String line : lines) {
27-
line = line.replaceAll("\\s+", "");
29+
line = line.strip();
2830
if (line.startsWith("#") == false) {
2931
idsLine = line;
3032
break;

0 commit comments

Comments
 (0)