Skip to content

Commit dfd6381

Browse files
authored
Merge branch 'main' into ssl-file-entitlement-checks
2 parents c4bc385 + 2c0fb18 commit dfd6381

File tree

11 files changed

+98
-66
lines changed

11 files changed

+98
-66
lines changed

.github/workflows/comment-on-asciidoc-changes.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/docs-build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: docs-build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request_target: ~
8+
merge_group: ~
9+
10+
jobs:
11+
docs-preview:
12+
uses: elastic/docs-builder/.github/workflows/preview-build.yml@main
13+
with:
14+
path-pattern: docs/**
15+
permissions:
16+
deployments: write
17+
id-token: write
18+
contents: read
19+
pull-requests: read

.github/workflows/docs-cleanup.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: docs-cleanup
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- closed
7+
8+
jobs:
9+
docs-preview:
10+
uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main
11+
permissions:
12+
contents: none
13+
id-token: write
14+
deployments: write

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

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: 3 additions & 0 deletions
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;
@@ -265,6 +266,8 @@ private static PolicyManager createPolicyManager() {
265266
List<Entitlement> agentEntitlements = List.of(
266267
new CreateClassLoaderEntitlement(),
267268
new ManageThreadsEntitlement(),
269+
new SetHttpsConnectionPropertiesEntitlement(),
270+
new OutboundNetworkEntitlement(),
268271
new FilesEntitlement(
269272
List.of(
270273
FileData.ofPath(Path.of("/co/elastic/apm/agent/"), READ),

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch;
1111

1212
import org.elasticsearch.core.Assertions;
13-
import org.elasticsearch.core.FixForMultiProject;
1413
import org.elasticsearch.core.UpdateForV9;
1514

1615
import java.lang.reflect.Field;
@@ -206,16 +205,7 @@ static TransportVersion def(int id) {
206205
public static final TransportVersion BYTE_SIZE_VALUE_ALWAYS_USES_BYTES = def(9_015_0_00);
207206
public static final TransportVersion ESQL_SERIALIZE_SOURCE_FUNCTIONS_WARNINGS = def(9_016_0_00);
208207
public static final TransportVersion ESQL_DRIVER_NODE_DESCRIPTION = def(9_017_0_00);
209-
210-
/*
211-
* WARNING: DO NOT MERGE INTO MAIN!
212-
* This is the transport version used for all multi-project changes.
213-
* This is above any possible transport version that could exist on main during multi-project branch development.
214-
* We don't care about BwC during initial development. Before this code is merged into main,
215-
* this variable needs to be changed to a regular transport version following the same rules as above.
216-
*/
217-
@FixForMultiProject
218-
public static final TransportVersion MULTI_PROJECT = def(9_999_990);
208+
public static final TransportVersion MULTI_PROJECT = def(9_018_0_00);
219209

220210
/*
221211
* STOP! READ THIS FIRST! No, really,

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsServiceTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.logging.log4j.Level;
1313
import org.apache.logging.log4j.LogManager;
1414
import org.apache.logging.log4j.Logger;
15+
import org.apache.lucene.tests.util.LuceneTestCase;
1516
import org.elasticsearch.action.ActionListener;
1617
import org.elasticsearch.cluster.ClusterChangedEvent;
1718
import org.elasticsearch.cluster.ClusterName;
@@ -84,6 +85,7 @@
8485
import static org.mockito.Mockito.times;
8586
import static org.mockito.Mockito.verify;
8687

88+
@LuceneTestCase.SuppressFileSystems("ExtrasFS")
8789
public class FileSettingsServiceTests extends ESTestCase {
8890
private static final Logger logger = LogManager.getLogger(FileSettingsServiceTests.class);
8991
private Environment env;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ private static class ImplicitCasting extends ParameterizedRule<LogicalPlan, Logi
11871187
public LogicalPlan apply(LogicalPlan plan, AnalyzerContext context) {
11881188
return plan.transformExpressionsUp(
11891189
org.elasticsearch.xpack.esql.core.expression.function.Function.class,
1190-
e -> ImplicitCasting.cast(e, context.functionRegistry())
1190+
e -> ImplicitCasting.cast(e, context.functionRegistry().snapshotRegistry())
11911191
);
11921192
}
11931193

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@
188188

189189
public class EsqlFunctionRegistry {
190190

191-
private static final Map<Class<? extends Function>, List<DataType>> DATA_TYPES_FOR_STRING_LITERAL_CONVERSIONS = new LinkedHashMap<>();
192-
193191
private static final Map<DataType, Integer> DATA_TYPE_CASTING_PRIORITY;
194192

195193
static {
@@ -225,6 +223,7 @@ public class EsqlFunctionRegistry {
225223
private final Map<String, FunctionDefinition> defs = new LinkedHashMap<>();
226224
private final Map<String, String> aliases = new HashMap<>();
227225
private final Map<Class<? extends Function>, String> names = new HashMap<>();
226+
private final Map<Class<? extends Function>, List<DataType>> dataTypesForStringLiteralConversions = new LinkedHashMap<>();
228227

229228
private SnapshotFunctionRegistry snapshotRegistry = null;
230229

@@ -711,20 +710,8 @@ private static Constructor<?> constructorFor(Class<? extends Function> clazz) {
711710
return constructors[0];
712711
}
713712

714-
private void buildDataTypesForStringLiteralConversion(FunctionDefinition[]... groupFunctions) {
715-
for (FunctionDefinition[] group : groupFunctions) {
716-
for (FunctionDefinition def : group) {
717-
FunctionDescription signature = description(def);
718-
DATA_TYPES_FOR_STRING_LITERAL_CONVERSIONS.put(
719-
def.clazz(),
720-
signature.args().stream().map(EsqlFunctionRegistry.ArgSignature::targetDataType).collect(Collectors.toList())
721-
);
722-
}
723-
}
724-
}
725-
726713
public List<DataType> getDataTypeForStringLiteralConversion(Class<? extends Function> clazz) {
727-
return DATA_TYPES_FOR_STRING_LITERAL_CONVERSIONS.get(clazz);
714+
return dataTypesForStringLiteralConversions.get(clazz);
728715
}
729716

730717
private static class SnapshotFunctionRegistry extends EsqlFunctionRegistry {
@@ -733,6 +720,7 @@ private static class SnapshotFunctionRegistry extends EsqlFunctionRegistry {
733720
throw new IllegalStateException("build snapshot function registry for non-snapshot build");
734721
}
735722
register(snapshotFunctions());
723+
buildDataTypesForStringLiteralConversion(snapshotFunctions());
736724
}
737725

738726
}
@@ -793,6 +781,18 @@ void register(FunctionDefinition... functions) {
793781
);
794782
}
795783

784+
protected void buildDataTypesForStringLiteralConversion(FunctionDefinition[]... groupFunctions) {
785+
for (FunctionDefinition[] group : groupFunctions) {
786+
for (FunctionDefinition def : group) {
787+
FunctionDescription signature = description(def);
788+
dataTypesForStringLiteralConversions.put(
789+
def.clazz(),
790+
signature.args().stream().map(EsqlFunctionRegistry.ArgSignature::targetDataType).collect(Collectors.toList())
791+
);
792+
}
793+
}
794+
}
795+
796796
protected FunctionDefinition cloneDefinition(String name, FunctionDefinition definition) {
797797
return new FunctionDefinition(name, emptyList(), definition.clazz(), definition.builder());
798798
}

0 commit comments

Comments
 (0)