Skip to content

Commit 24f813c

Browse files
Merge branch 'main' into debertaTokenizerNormalizeFix
2 parents 57a9ea1 + b9bac36 commit 24f813c

File tree

156 files changed

+7410
-2919
lines changed

Some content is hidden

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

156 files changed

+7410
-2919
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
3535
import org.elasticsearch.indices.breaker.CircuitBreakerService;
3636
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
37+
import org.elasticsearch.plugins.PluginsLoader;
3738
import org.elasticsearch.plugins.PluginsService;
3839
import org.elasticsearch.plugins.ScriptPlugin;
3940
import org.elasticsearch.script.DocReader;
@@ -76,8 +77,7 @@ public class ScriptScoreBenchmark {
7677
private final PluginsService pluginsService = new PluginsService(
7778
Settings.EMPTY,
7879
null,
79-
null,
80-
Path.of(System.getProperty("plugins.dir"))
80+
new PluginsLoader(null, Path.of(System.getProperty("plugins.dir")))
8181
);
8282
private final ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, pluginsService.filterPlugins(ScriptPlugin.class).toList());
8383

branches.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{
88
"branch": "8.16"
99
},
10+
{
11+
"branch": "8.17"
12+
},
1013
{
1114
"branch": "8.x"
1215
},

build-tools-internal/src/main/groovy/org/elasticsearch/gradle/internal/AntFixtureStop.groovy

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ import org.elasticsearch.gradle.internal.test.AntFixture
1515
import org.gradle.api.file.FileSystemOperations
1616
import org.gradle.api.file.ProjectLayout
1717
import org.gradle.api.provider.ProviderFactory
18-
import org.gradle.api.tasks.Internal
1918
import org.gradle.process.ExecOperations
2019

2120
import javax.inject.Inject
2221

2322
abstract class AntFixtureStop extends LoggedExec implements FixtureStop {
2423

25-
@Internal
26-
AntFixture fixture
27-
2824
@Inject
2925
AntFixtureStop(ProjectLayout projectLayout,
3026
ExecOperations execOperations,
@@ -34,12 +30,12 @@ abstract class AntFixtureStop extends LoggedExec implements FixtureStop {
3430
}
3531

3632
void setFixture(AntFixture fixture) {
37-
assert this.fixture == null
38-
this.fixture = fixture;
39-
final Object pid = "${-> this.fixture.pid}"
40-
onlyIf("pidFile exists") { fixture.pidFile.exists() }
33+
def pidFile = fixture.pidFile
34+
def fixtureName = fixture.name
35+
final Object pid = "${-> Integer.parseInt(pidFile.getText('UTF-8').trim())}"
36+
onlyIf("pidFile exists") { pidFile.exists() }
4137
doFirst {
42-
logger.info("Shutting down ${fixture.name} with pid ${pid}")
38+
logger.info("Shutting down ${fixtureName} with pid ${pid}")
4339
}
4440

4541
if (OS.current() == OS.WINDOWS) {
@@ -51,9 +47,8 @@ abstract class AntFixtureStop extends LoggedExec implements FixtureStop {
5147
}
5248
doLast {
5349
fileSystemOperations.delete {
54-
it.delete(fixture.pidFile)
50+
it.delete(pidFile)
5551
}
5652
}
57-
this.fixture = fixture
5853
}
5954
}

build-tools-internal/src/main/groovy/org/elasticsearch/gradle/internal/AntTask.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ import java.nio.charset.Charset
2929
*/
3030
public abstract class AntTask extends DefaultTask {
3131

32-
/**
33-
* A buffer that will contain the output of the ant code run,
34-
* if the output was not already written directly to stdout.
35-
*/
36-
public final ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream()
3732

3833
@Inject
3934
protected FileSystemOperations getFileSystemOperations() {
@@ -57,6 +52,11 @@ public abstract class AntTask extends DefaultTask {
5752

5853
// otherwise groovy replaces System.out, and you have no chance to debug
5954
// ant.saveStreams = false
55+
/**
56+
* A buffer that will contain the output of the ant code run,
57+
* if the output was not already written directly to stdout.
58+
*/
59+
ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream()
6060

6161
final int outputLevel = logger.isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO
6262
final PrintStream stream = useStdout() ? System.out : new PrintStream(outputBuffer, true, Charset.defaultCharset().name())

build-tools-internal/src/main/groovy/org/elasticsearch/gradle/internal/test/AntFixture.groovy

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,37 @@
1010
package org.elasticsearch.gradle.internal.test
1111

1212
import org.elasticsearch.gradle.OS
13+
1314
import org.elasticsearch.gradle.internal.AntFixtureStop
1415
import org.elasticsearch.gradle.internal.AntTask
16+
import org.elasticsearch.gradle.testclusters.TestClusterInfo
17+
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
18+
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
1519
import org.gradle.api.GradleException
20+
import org.gradle.api.file.ProjectLayout
21+
import org.gradle.api.provider.Property
22+
import org.gradle.api.provider.Provider
23+
import org.gradle.api.provider.ProviderFactory
24+
import org.gradle.api.provider.ValueSource
25+
import org.gradle.api.provider.ValueSourceParameters
26+
import org.gradle.api.tasks.Input
1627
import org.gradle.api.tasks.Internal
1728
import org.gradle.api.tasks.TaskProvider
1829

30+
import javax.inject.Inject
31+
1932
/**
2033
* A fixture for integration tests which runs in a separate process launched by Ant.
2134
*/
22-
class AntFixture extends AntTask implements Fixture {
35+
class AntFixture extends AntTask {
2336

2437
/** The path to the executable that starts the fixture. */
2538
@Internal
2639
String executable
2740

2841
private final List<Object> arguments = new ArrayList<>()
42+
private ProjectLayout projectLayout
43+
private final ProviderFactory providerFactory
2944

3045
void args(Object... args) {
3146
arguments.addAll(args)
@@ -69,19 +84,14 @@ class AntFixture extends AntTask implements Fixture {
6984
return tmpFile.exists()
7085
}
7186

72-
private final TaskProvider<AntFixtureStop> stopTask
73-
74-
AntFixture() {
75-
stopTask = createStopTask()
87+
@Inject
88+
AntFixture(ProjectLayout projectLayout, ProviderFactory providerFactory) {
89+
this.providerFactory = providerFactory
90+
this.projectLayout = projectLayout;
91+
TaskProvider<AntFixtureStop> stopTask = createStopTask()
7692
finalizedBy(stopTask)
7793
}
7894

79-
@Override
80-
@Internal
81-
TaskProvider<AntFixtureStop> getStopTask() {
82-
return stopTask
83-
}
84-
8595
@Override
8696
protected void runAnt(AntBuilder ant) {
8797
// reset everything
@@ -231,7 +241,7 @@ class AntFixture extends AntTask implements Fixture {
231241
*/
232242
@Internal
233243
protected File getBaseDir() {
234-
return new File(project.buildDir, "fixtures/${name}")
244+
return new File(projectLayout.getBuildDirectory().getAsFile().get(), "fixtures/${name}")
235245
}
236246

237247
/** Returns the working directory for the process. Defaults to "cwd" inside baseDir. */
@@ -242,7 +252,7 @@ class AntFixture extends AntTask implements Fixture {
242252

243253
/** Returns the file the process writes its pid to. Defaults to "pid" inside baseDir. */
244254
@Internal
245-
protected File getPidFile() {
255+
File getPidFile() {
246256
return new File(baseDir, 'pid')
247257
}
248258

@@ -264,6 +274,12 @@ class AntFixture extends AntTask implements Fixture {
264274
return portsFile.readLines("UTF-8").get(0)
265275
}
266276

277+
@Internal
278+
Provider<String> getAddressAndPortProvider() {
279+
File thePortFile = portsFile
280+
return providerFactory.provider(() -> thePortFile.readLines("UTF-8").get(0))
281+
}
282+
267283
/** Returns a file that wraps around the actual command when {@code spawn == true}. */
268284
@Internal
269285
protected File getWrapperScript() {
@@ -281,4 +297,22 @@ class AntFixture extends AntTask implements Fixture {
281297
protected File getRunLog() {
282298
return new File(cwd, 'run.log')
283299
}
300+
301+
@Internal
302+
Provider<AntFixtureValueSource> getAddressAndPortSource() {
303+
return providerFactory.of(AntFixtureValueSource.class, spec -> {
304+
spec.getParameters().getPortFile().set(portsFile);
305+
});
306+
}
307+
308+
static abstract class AntFixtureValueSource implements ValueSource<String, AntFixtureValueSource.Parameters> {
309+
@Override
310+
String obtain() {
311+
return getParameters().getPortFile().map { it.readLines("UTF-8").get(0) }.get()
312+
}
313+
314+
interface Parameters extends ValueSourceParameters {
315+
Property<File> getPortFile();
316+
}
317+
}
284318
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.gradle.api.artifacts.Configuration;
2727
import org.gradle.api.artifacts.Dependency;
2828
import org.gradle.api.file.Directory;
29+
import org.gradle.api.file.FileCollection;
2930
import org.gradle.api.file.ProjectLayout;
3031
import org.gradle.api.file.RelativePath;
3132
import org.gradle.api.internal.file.FileOperations;
@@ -244,10 +245,11 @@ public void apply(Project project) {
244245
yamlRestCompatTestTask.configure(testTask -> {
245246
testTask.systemProperty("tests.restCompat", true);
246247
// Use test runner and classpath from "normal" yaml source set
248+
FileCollection outputFileCollection = yamlCompatTestSourceSet.getOutput();
247249
testTask.setTestClassesDirs(
248250
yamlTestSourceSet.getOutput().getClassesDirs().plus(yamlCompatTestSourceSet.getOutput().getClassesDirs())
249251
);
250-
testTask.onlyIf("Compatibility tests are available", t -> yamlCompatTestSourceSet.getOutput().isEmpty() == false);
252+
testTask.onlyIf("Compatibility tests are available", t -> outputFileCollection.isEmpty() == false);
251253
testTask.setClasspath(
252254
yamlCompatTestSourceSet.getRuntimeClasspath()
253255
// remove the "normal" api and tests

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
7676
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
7777
private final transient Project project;
7878
private final Provider<ReaperService> reaper;
79+
private final Provider<TestClustersRegistry> testClustersRegistryProvider;
7980
private final FileSystemOperations fileSystemOperations;
8081
private final ArchiveOperations archiveOperations;
8182
private final ExecOperations execOperations;
@@ -87,11 +88,14 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
8788

8889
private boolean shared = false;
8990

91+
private int claims = 0;
92+
9093
public ElasticsearchCluster(
9194
String path,
9295
String clusterName,
9396
Project project,
9497
Provider<ReaperService> reaper,
98+
Provider<TestClustersRegistry> testClustersRegistryProvider,
9599
FileSystemOperations fileSystemOperations,
96100
ArchiveOperations archiveOperations,
97101
ExecOperations execOperations,
@@ -104,6 +108,7 @@ public ElasticsearchCluster(
104108
this.clusterName = clusterName;
105109
this.project = project;
106110
this.reaper = reaper;
111+
this.testClustersRegistryProvider = testClustersRegistryProvider;
107112
this.fileSystemOperations = fileSystemOperations;
108113
this.archiveOperations = archiveOperations;
109114
this.execOperations = execOperations;
@@ -120,6 +125,7 @@ public ElasticsearchCluster(
120125
clusterName + "-0",
121126
project,
122127
reaper,
128+
testClustersRegistryProvider,
123129
fileSystemOperations,
124130
archiveOperations,
125131
execOperations,
@@ -177,6 +183,7 @@ public void setNumberOfNodes(int numberOfNodes) {
177183
clusterName + "-" + i,
178184
project,
179185
reaper,
186+
testClustersRegistryProvider,
180187
fileSystemOperations,
181188
archiveOperations,
182189
execOperations,
@@ -408,6 +415,7 @@ public void setPreserveDataDir(boolean preserveDataDir) {
408415
public void freeze() {
409416
nodes.forEach(ElasticsearchNode::freeze);
410417
configurationFrozen.set(true);
418+
nodes.whenObjectAdded(node -> { throw new IllegalStateException("Cannot add nodes to test cluster after is has been frozen"); });
411419
}
412420

413421
private void checkFrozen() {
@@ -663,4 +671,11 @@ public String toString() {
663671
return "cluster{" + path + ":" + clusterName + "}";
664672
}
665673

674+
int addClaim() {
675+
return ++this.claims;
676+
}
677+
678+
int removeClaim() {
679+
return --this.claims;
680+
}
666681
}

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public class ElasticsearchNode implements TestClusterConfiguration {
124124
private final String name;
125125
transient private final Project project;
126126
private final Provider<ReaperService> reaperServiceProvider;
127+
private final Provider<TestClustersRegistry> testClustersRegistryProvider;
128+
127129
private final FileSystemOperations fileSystemOperations;
128130
private final ArchiveOperations archiveOperations;
129131
private final ExecOperations execOperations;
@@ -164,7 +166,6 @@ public class ElasticsearchNode implements TestClusterConfiguration {
164166
private final List<ElasticsearchDistribution> distributions = new ArrayList<>();
165167
private int currentDistro = 0;
166168
private TestDistribution testDistribution;
167-
private volatile Process esProcess;
168169
private Function<String, String> nameCustomization = s -> s;
169170
private boolean isWorkingDirConfigured = false;
170171
private String httpPort = "0";
@@ -179,6 +180,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
179180
String name,
180181
Project project,
181182
Provider<ReaperService> reaperServiceProvider,
183+
Provider<TestClustersRegistry> testClustersRegistryProvider,
182184
FileSystemOperations fileSystemOperations,
183185
ArchiveOperations archiveOperations,
184186
ExecOperations execOperations,
@@ -191,6 +193,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
191193
this.name = name;
192194
this.project = project;
193195
this.reaperServiceProvider = reaperServiceProvider;
196+
this.testClustersRegistryProvider = testClustersRegistryProvider;
194197
this.fileSystemOperations = fileSystemOperations;
195198
this.archiveOperations = archiveOperations;
196199
this.execOperations = execOperations;
@@ -892,11 +895,13 @@ private void startElasticsearchProcess() {
892895
}
893896
}
894897
LOGGER.info("Running `{}` in `{}` for {} env: {}", command, workingDir, this, environment);
898+
Process esProcess;
895899
try {
896900
esProcess = processBuilder.start();
897901
} catch (IOException e) {
898902
throw new TestClustersException("Failed to start ES process for " + this, e);
899903
}
904+
testClustersRegistryProvider.get().storeProcess(id(), esProcess);
900905
reaperServiceProvider.get().registerPid(toString(), esProcess.pid());
901906
}
902907

@@ -982,6 +987,7 @@ public synchronized void stop(boolean tailLogs) {
982987
} catch (IOException e) {
983988
throw new UncheckedIOException(e);
984989
}
990+
Process esProcess = testClustersRegistryProvider.get().getProcess(id());
985991
if (esProcess == null && tailLogs) {
986992
// This is a special case. If start() throws an exception the plugin will still call stop
987993
// Another exception here would eat the orriginal.
@@ -1574,6 +1580,7 @@ public List<FeatureFlag> getFeatureFlags() {
15741580
@Override
15751581
@Internal
15761582
public boolean isProcessAlive() {
1583+
Process esProcess = testClustersRegistryProvider.get().getProcess(id());
15771584
requireNonNull(esProcess, "Can't wait for `" + this + "` as it's not started. Does the task have `useCluster` ?");
15781585
return esProcess.isAlive();
15791586
}
@@ -1602,6 +1609,10 @@ public int hashCode() {
16021609

16031610
@Override
16041611
public String toString() {
1612+
return id() + " (" + System.identityHashCode(this) + ")";
1613+
}
1614+
1615+
private String id() {
16051616
return "node{" + path + ":" + name + "}";
16061617
}
16071618

@@ -1702,7 +1713,7 @@ public CharSequence[] getArgs() {
17021713
}
17031714
}
17041715

1705-
private record FeatureFlag(String feature, Version from, Version until) {
1716+
public record FeatureFlag(String feature, Version from, Version until) {
17061717

17071718
@Input
17081719
public String getFeature() {

0 commit comments

Comments
 (0)