Skip to content

Commit 95e7257

Browse files
Merge remote-tracking branch 'elastic/main' into batched-exec-short
2 parents 41b4e4a + 2c0fb18 commit 95e7257

File tree

1,284 files changed

+39689
-15932
lines changed

Some content is hidden

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

1,284 files changed

+39689
-15932
lines changed

.buildkite/pipelines/periodic-fwc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is auto-generated. See .buildkite/pipelines/periodic-fwc.template.yml
22
steps:
3-
- label: $FWC_VERSION / fwc
4-
command: .ci/scripts/run-gradle.sh -Dbwc.checkout.align=true v$FWC_VERSION#fwcTest -Dtests.bwc.snapshot=false
3+
- label: "{{matrix.FWC_VERSION}} / fwc"
4+
command: .ci/scripts/run-gradle.sh -Dbwc.checkout.align=true v$$FWC_VERSION#fwcTest -Dtests.bwc.snapshot=false
55
timeout_in_minutes: 300
66
agents:
77
provider: gcp
@@ -13,4 +13,4 @@ steps:
1313
setup:
1414
FWC_VERSION: []
1515
env:
16-
FWC_VERSION: $FWC_VERSION
16+
FWC_VERSION: "{{matrix.FWC_VERSION}}"

benchmarks/src/main/java/org/elasticsearch/benchmark/indices/resolution/IndexNameExpressionResolverBenchmark.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.cluster.metadata.IndexMetadata;
1818
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1919
import org.elasticsearch.cluster.metadata.Metadata;
20+
import org.elasticsearch.cluster.project.DefaultProjectResolver;
2021
import org.elasticsearch.common.settings.Settings;
2122
import org.elasticsearch.common.util.concurrent.ThreadContext;
2223
import org.elasticsearch.index.Index;
@@ -84,7 +85,11 @@ public void setUp() {
8485
}
8586
int mid = indices.length / 2;
8687
clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(mb).build();
87-
resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(List.of()));
88+
resolver = new IndexNameExpressionResolver(
89+
new ThreadContext(Settings.EMPTY),
90+
new SystemIndices(List.of()),
91+
DefaultProjectResolver.INSTANCE
92+
);
8893
indexListRequest = new Request(IndicesOptions.lenientExpandOpenHidden(), indices);
8994
starRequest = new Request(IndicesOptions.lenientExpandOpenHidden(), "*");
9095
String[] mixed = indices.clone();

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void setUp() throws Exception {
138138
Metadata metadata = mb.build();
139139
RoutingTable.Builder rb = RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY);
140140
for (int i = 1; i <= numIndices; i++) {
141-
rb.addAsNew(metadata.index("test_" + i));
141+
rb.addAsNew(metadata.getProject().index("test_" + i));
142142
}
143143
RoutingTable routingTable = rb.build();
144144
DiscoveryNodes.Builder nb = DiscoveryNodes.builder();

build-tools-internal/src/main/groovy/elasticsearch.ide.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,23 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
145145
}
146146
}
147147

148-
// modifies the idea module config to enable preview features on ':libs:native' module
148+
// modifies the idea module config to enable preview features on module that need them
149149
tasks.register("enablePreviewFeatures", EnablePreviewFeaturesTask) {
150150
group = 'ide'
151-
description = 'Enables preview features on native library module'
151+
description = 'Enables preview features on modules that need them'
152152
dependsOn tasks.named("enableExternalConfiguration")
153153
doLast {
154154
enablePreview('.idea/modules/libs/native/elasticsearch.libs.native.main.iml', 'JDK_21_PREVIEW')
155155
enablePreview('.idea/modules/libs/native/elasticsearch.libs.native.test.iml', 'JDK_21_PREVIEW')
156+
// due to org.elasticsearch.plugins.PluginsLoader
157+
enablePreview('.idea/modules/server/elasticsearch.server.main.iml', 'JDK_21_PREVIEW')
158+
enablePreview('.idea/modules/server/elasticsearch.server.test.iml', 'JDK_21_PREVIEW')
156159
enablePreview('.idea/modules/libs/entitlement/elasticsearch.libs.entitlement.main.iml', 'JDK_21_PREVIEW')
157160
enablePreview('.idea/modules/libs/entitlement/elasticsearch.libs.entitlement.test.iml', 'JDK_21_PREVIEW')
158161
enablePreview('.idea/modules/libs/entitlement/bridge/elasticsearch.libs.entitlement.bridge.main.iml', 'JDK_21_PREVIEW')
159162
enablePreview('.idea/modules/libs/entitlement/bridge/elasticsearch.libs.entitlement.bridge.test.iml', 'JDK_21_PREVIEW')
163+
enablePreview('.idea/modules/libs/entitlement/qa/entitlement-test-plugin/elasticsearch.libs.entitlement.qa.entitlement-test-plugin.main.iml', 'JDK_21_PREVIEW')
164+
enablePreview('.idea/modules/libs/entitlement/qa/entitlement-test-plugin/elasticsearch.libs.entitlement.qa.entitlement-test-plugin.test.iml', 'JDK_21_PREVIEW')
160165
}
161166
}
162167

docs/changelog/123492.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 123492
2+
summary: Fix function registry concurrency issues on constructor
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 123430
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.core;
11+
12+
import java.lang.annotation.ElementType;
13+
import java.lang.annotation.Retention;
14+
import java.lang.annotation.RetentionPolicy;
15+
import java.lang.annotation.Target;
16+
17+
/**
18+
* Annotation to identify a block of code (a whole class, a method, a field, or a local variable) that needs to be reviewed (for cleanup,
19+
* removal or change) before merging the multi-project branch into main
20+
*/
21+
@Retention(RetentionPolicy.SOURCE)
22+
@Target(
23+
{ ElementType.LOCAL_VARIABLE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.MODULE }
24+
)
25+
public @interface FixForMultiProject {
26+
27+
/**
28+
* Some explanation on what and why for the future fix
29+
*/
30+
String description() default "";
31+
}

libs/core/src/main/java/org/elasticsearch/core/Releasables.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
package org.elasticsearch.core;
1111

12-
import java.io.IOException;
13-
import java.io.UncheckedIOException;
1412
import java.util.Arrays;
1513
import java.util.Iterator;
1614
import java.util.concurrent.atomic.AtomicReference;
@@ -21,11 +19,17 @@ public enum Releasables {
2119

2220
/** Release the provided {@link Releasable}s. */
2321
public static void close(Iterable<? extends Releasable> releasables) {
24-
try {
25-
// this does the right thing with respect to add suppressed and not wrapping errors etc.
26-
IOUtils.close(releasables);
27-
} catch (IOException e) {
28-
throw new UncheckedIOException(e);
22+
RuntimeException firstException = null;
23+
for (final Releasable releasable : releasables) {
24+
try {
25+
close(releasable);
26+
} catch (RuntimeException e) {
27+
firstException = useOrSuppress(firstException, e);
28+
}
29+
}
30+
31+
if (firstException != null) {
32+
throw firstException;
2933
}
3034
}
3135

@@ -38,7 +42,18 @@ public static void close(@Nullable Releasable releasable) {
3842

3943
/** Release the provided {@link Releasable}s. */
4044
public static void close(Releasable... releasables) {
41-
close(true, releasables);
45+
RuntimeException firstException = null;
46+
for (final Releasable releasable : releasables) {
47+
try {
48+
close(releasable);
49+
} catch (RuntimeException e) {
50+
firstException = useOrSuppress(firstException, e);
51+
}
52+
}
53+
54+
if (firstException != null) {
55+
throw firstException;
56+
}
4257
}
4358

4459
/** Release the provided {@link Releasable}s expecting no exception to by thrown by any of them. */
@@ -63,19 +78,21 @@ public static void closeExpectNoException(Releasable releasable) {
6378

6479
/** Release the provided {@link Releasable}s, ignoring exceptions. */
6580
public static void closeWhileHandlingException(Releasable... releasables) {
66-
close(false, releasables);
81+
for (final Releasable releasable : releasables) {
82+
try {
83+
close(releasable);
84+
} catch (RuntimeException e) {
85+
// ignored
86+
}
87+
}
6788
}
6889

69-
/** Release the provided {@link Releasable}s, ignoring exceptions if <code>success</code> is {@code false}. */
70-
private static void close(boolean success, Releasable... releasables) {
71-
try {
72-
// this does the right thing with respect to add suppressed and not wrapping errors etc.
73-
IOUtils.close(releasables);
74-
} catch (IOException e) {
75-
if (success) {
76-
throw new UncheckedIOException(e);
77-
}
90+
private static RuntimeException useOrSuppress(RuntimeException firstException, RuntimeException e) {
91+
if (firstException == null || firstException == e) {
92+
return e;
7893
}
94+
firstException.addSuppressed(e);
95+
return firstException;
7996
}
8097

8198
/** Wrap several releasables into a single one. This is typically useful for use with try-with-resources: for example let's assume

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.entitlement.runtime.policy.entitlements.ManageThreadsEntitlement;
3434
import org.elasticsearch.entitlement.runtime.policy.entitlements.OutboundNetworkEntitlement;
3535
import org.elasticsearch.entitlement.runtime.policy.entitlements.ReadStoreAttributesEntitlement;
36+
import org.elasticsearch.entitlement.runtime.policy.entitlements.SetHttpsConnectionPropertiesEntitlement;
3637

3738
import java.lang.instrument.Instrumentation;
3839
import java.lang.reflect.Constructor;
@@ -242,7 +243,14 @@ private static PolicyManager createPolicyManager() {
242243
if (trustStorePath != null) {
243244
Collections.addAll(
244245
serverScopes,
245-
new Scope("org.bouncycastle.fips.tls", List.of(new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))))),
246+
new Scope(
247+
"org.bouncycastle.fips.tls",
248+
List.of(
249+
new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))),
250+
new OutboundNetworkEntitlement(),
251+
new ManageThreadsEntitlement()
252+
)
253+
),
246254
new Scope(
247255
"org.bouncycastle.fips.core",
248256
// read to lib dir is required for checksum validation
@@ -258,6 +266,8 @@ private static PolicyManager createPolicyManager() {
258266
List<Entitlement> agentEntitlements = List.of(
259267
new CreateClassLoaderEntitlement(),
260268
new ManageThreadsEntitlement(),
269+
new SetHttpsConnectionPropertiesEntitlement(),
270+
new OutboundNetworkEntitlement(),
261271
new FilesEntitlement(
262272
List.of(
263273
FileData.ofPath(Path.of("/co/elastic/apm/agent/"), READ),

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,74 @@
3030

3131
public final class FileAccessTree {
3232

33+
/**
34+
* An intermediary structure to help build exclusive paths for files entitlements.
35+
*/
36+
record ExclusiveFileEntitlement(String componentName, String moduleName, FilesEntitlement filesEntitlement) {}
37+
38+
/**
39+
* An intermediary structure to help globally validate exclusive paths, and then build exclusive paths for individual modules.
40+
*/
41+
record ExclusivePath(String componentName, String moduleName, String path) {
42+
43+
@Override
44+
public String toString() {
45+
return "[[" + componentName + "] [" + moduleName + "] [" + path + "]]";
46+
}
47+
}
48+
49+
static List<ExclusivePath> buildExclusivePathList(List<ExclusiveFileEntitlement> exclusiveFileEntitlements, PathLookup pathLookup) {
50+
List<ExclusivePath> exclusivePaths = new ArrayList<>();
51+
for (ExclusiveFileEntitlement efe : exclusiveFileEntitlements) {
52+
for (FilesEntitlement.FileData fd : efe.filesEntitlement().filesData()) {
53+
if (fd.exclusive()) {
54+
List<Path> paths = fd.resolvePaths(pathLookup).toList();
55+
for (Path path : paths) {
56+
exclusivePaths.add(new ExclusivePath(efe.componentName(), efe.moduleName(), normalizePath(path)));
57+
}
58+
}
59+
}
60+
}
61+
exclusivePaths.sort((ep1, ep2) -> PATH_ORDER.compare(ep1.path(), ep2.path()));
62+
return exclusivePaths;
63+
}
64+
65+
static void validateExclusivePaths(List<ExclusivePath> exclusivePaths) {
66+
if (exclusivePaths.isEmpty() == false) {
67+
ExclusivePath currentExclusivePath = exclusivePaths.get(0);
68+
for (int i = 1; i < exclusivePaths.size(); ++i) {
69+
ExclusivePath nextPath = exclusivePaths.get(i);
70+
if (currentExclusivePath.path().equals(nextPath.path) || isParent(currentExclusivePath.path(), nextPath.path())) {
71+
throw new IllegalArgumentException(
72+
"duplicate/overlapping exclusive paths found in files entitlements: " + currentExclusivePath + " and " + nextPath
73+
);
74+
}
75+
currentExclusivePath = nextPath;
76+
}
77+
}
78+
}
79+
3380
private static final Logger logger = LogManager.getLogger(FileAccessTree.class);
3481
private static final String FILE_SEPARATOR = getDefaultFileSystem().getSeparator();
3582

83+
private final String[] exclusivePaths;
3684
private final String[] readPaths;
3785
private final String[] writePaths;
3886

39-
private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
87+
private FileAccessTree(
88+
String componentName,
89+
String moduleName,
90+
FilesEntitlement filesEntitlement,
91+
PathLookup pathLookup,
92+
List<ExclusivePath> exclusivePaths
93+
) {
94+
List<String> updatedExclusivePaths = new ArrayList<>();
95+
for (ExclusivePath exclusivePath : exclusivePaths) {
96+
if (exclusivePath.componentName().equals(componentName) == false || exclusivePath.moduleName().equals(moduleName) == false) {
97+
updatedExclusivePaths.add(exclusivePath.path());
98+
}
99+
}
100+
40101
List<String> readPaths = new ArrayList<>();
41102
List<String> writePaths = new ArrayList<>();
42103
BiConsumer<Path, Mode> addPath = (path, mode) -> {
@@ -83,9 +144,11 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup)
83144
Path jdk = Paths.get(System.getProperty("java.home"));
84145
addPathAndMaybeLink.accept(jdk.resolve("conf"), Mode.READ);
85146

147+
updatedExclusivePaths.sort(PATH_ORDER);
86148
readPaths.sort(PATH_ORDER);
87149
writePaths.sort(PATH_ORDER);
88150

151+
this.exclusivePaths = updatedExclusivePaths.toArray(new String[0]);
89152
this.readPaths = pruneSortedPaths(readPaths).toArray(new String[0]);
90153
this.writePaths = pruneSortedPaths(writePaths).toArray(new String[0]);
91154
}
@@ -106,8 +169,14 @@ private static List<String> pruneSortedPaths(List<String> paths) {
106169
return prunedReadPaths;
107170
}
108171

109-
public static FileAccessTree of(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
110-
return new FileAccessTree(filesEntitlement, pathLookup);
172+
public static FileAccessTree of(
173+
String componentName,
174+
String moduleName,
175+
FilesEntitlement filesEntitlement,
176+
PathLookup pathLookup,
177+
List<ExclusivePath> exclusivePaths
178+
) {
179+
return new FileAccessTree(componentName, moduleName, filesEntitlement, pathLookup, exclusivePaths);
111180
}
112181

113182
boolean canRead(Path path) {
@@ -132,10 +201,16 @@ static String normalizePath(Path path) {
132201
return result;
133202
}
134203

135-
private static boolean checkPath(String path, String[] paths) {
204+
private boolean checkPath(String path, String[] paths) {
136205
if (paths.length == 0) {
137206
return false;
138207
}
208+
209+
int endx = Arrays.binarySearch(exclusivePaths, path, PATH_ORDER);
210+
if (endx < -1 && isParent(exclusivePaths[-endx - 2], path) || endx >= 0) {
211+
return false;
212+
}
213+
139214
int ndx = Arrays.binarySearch(paths, path, PATH_ORDER);
140215
if (ndx < -1) {
141216
return isParent(paths[-ndx - 2], path);

0 commit comments

Comments
 (0)