Skip to content

Commit d6b887c

Browse files
committed
Merge branch 'main' into lucene_snapshot
2 parents 876ea52 + 2481237 commit d6b887c

File tree

31 files changed

+686
-100
lines changed

31 files changed

+686
-100
lines changed

docs/changelog/132967.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132967
2+
summary: ES-11331 streams params restriction
3+
area: Data streams
4+
type: enhancement
5+
issues: []

docs/changelog/133848.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 133848
2+
summary: Delay S3 repo warning if default region absent
3+
area: Snapshot/Restore
4+
type: bug
5+
issues: []

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public interface EntitlementChecker {
136136

137137
void check$java_net_URLClassLoader$(Class<?> callerClass, String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory);
138138

139+
void check$java_net_URLClassLoader$$newInstance(Class<?> callerClass, URL[] urls, ClassLoader parent);
140+
141+
void check$java_net_URLClassLoader$$newInstance(Class<?> callerClass, URL[] urls);
142+
139143
void check$java_security_SecureClassLoader$(Class<?> callerClass);
140144

141145
void check$java_security_SecureClassLoader$(Class<?> callerClass, ClassLoader parent);

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/JvmActions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ static void createClassLoader() throws IOException {
7272
}
7373
}
7474

75+
@EntitlementTest(expectedAccess = PLUGINS)
76+
static void createClassLoaderNewInstance1() throws IOException {
77+
try (var classLoader = URLClassLoader.newInstance(new URL[0])) {
78+
// intentionally empty, just let the loader close
79+
}
80+
}
81+
82+
@EntitlementTest(expectedAccess = PLUGINS)
83+
static void createClassLoaderNewInstance2() throws IOException {
84+
try (var classLoader = URLClassLoader.newInstance(new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) {
85+
// intentionally empty, just let the loader close
86+
}
87+
}
88+
7589
@EntitlementTest(expectedAccess = ALWAYS_DENIED)
7690
static void createLogManager() {
7791
new java.util.logging.LogManager() {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ public ElasticsearchEntitlementChecker(PolicyChecker policyChecker) {
194194
policyChecker.checkCreateClassLoader(callerClass);
195195
}
196196

197+
@Override
198+
public void check$java_net_URLClassLoader$$newInstance(Class<?> callerClass, URL[] urls) {
199+
policyChecker.checkCreateClassLoader(callerClass);
200+
}
201+
202+
@Override
203+
public void check$java_net_URLClassLoader$$newInstance(Class<?> callerClass, URL[] urls, ClassLoader parent) {
204+
policyChecker.checkCreateClassLoader(callerClass);
205+
}
206+
197207
@Override
198208
public void check$java_security_SecureClassLoader$(Class<?> callerClass) {
199209
policyChecker.checkCreateClassLoader(callerClass);

libs/simdvec/src/main21/java/org/elasticsearch/simdvec/internal/MemorySegmentES92PanamaInt7VectorsScorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected void panamaInt7DotProductBulk(byte[] q, int count, float[] scores) thr
168168
dotProductBody128Bulk(q, count, scores);
169169
}
170170
} else {
171-
int7DotProductBulk(q, count, scores);
171+
super.int7DotProductBulk(q, count, scores);
172172
}
173173
}
174174

modules/repository-s3/qa/insecure-credentials/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import software.amazon.awssdk.auth.credentials.AwsCredentials;
1313
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
1414
import software.amazon.awssdk.http.SdkHttpClient;
15+
import software.amazon.awssdk.regions.Region;
1516
import software.amazon.awssdk.services.s3.S3Client;
1617

1718
import org.apache.logging.log4j.LogManager;
@@ -306,7 +307,7 @@ public static final class ProxyS3Service extends S3Service {
306307
ProjectResolver projectResolver,
307308
ResourceWatcherService resourceWatcherService
308309
) {
309-
super(environment, clusterService, projectResolver, resourceWatcherService, () -> null);
310+
super(environment, clusterService, projectResolver, resourceWatcherService, () -> Region.of(randomIdentifier()));
310311
}
311312

312313
@Override
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.repositories.s3;
11+
12+
import software.amazon.awssdk.regions.Region;
13+
14+
import org.elasticsearch.common.util.concurrent.RunOnce;
15+
import org.elasticsearch.logging.LogManager;
16+
import org.elasticsearch.logging.Logger;
17+
18+
import java.util.function.Supplier;
19+
20+
/**
21+
* Holds onto the {@link Region} provided by the given supplier (think: the AWS SDK's default provider chain) in case it's needed for a S3
22+
* repository. If the supplier fails with an exception, the first call to {@link #getDefaultRegion} will log a warning message recording
23+
* the exception.
24+
*/
25+
class S3DefaultRegionHolder {
26+
27+
private static final Logger logger = LogManager.getLogger(S3DefaultRegionHolder.class);
28+
29+
// no synchronization required, assignments happen in start() which happens-before all reads
30+
private Region defaultRegion;
31+
private Runnable defaultRegionFailureLogger = () -> {};
32+
33+
private final Runnable initializer;
34+
35+
/**
36+
* @param delegateRegionSupplier Supplies a non-null {@link Region} or throws a {@link RuntimeException}.
37+
* <p>
38+
* Retained until its first-and-only invocation when {@link #start()} is called, and then released.
39+
*/
40+
S3DefaultRegionHolder(Supplier<Region> delegateRegionSupplier) {
41+
initializer = new RunOnce(() -> {
42+
try {
43+
defaultRegion = delegateRegionSupplier.get();
44+
assert defaultRegion != null;
45+
} catch (Exception e) {
46+
defaultRegion = null;
47+
defaultRegionFailureLogger = new RunOnce(() -> logger.warn("failed to obtain region from default provider chain", e));
48+
}
49+
});
50+
}
51+
52+
void start() {
53+
initializer.run();
54+
}
55+
56+
Region getDefaultRegion() {
57+
assert defaultRegion != null || defaultRegionFailureLogger instanceof RunOnce : "not initialized";
58+
defaultRegionFailureLogger.run();
59+
return defaultRegion;
60+
}
61+
}

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ S3Service s3Service(
101101
}
102102

103103
private static Region getDefaultRegion() {
104-
try {
105-
return DefaultAwsRegionProviderChain.builder().build().getRegion();
106-
} catch (Exception e) {
107-
logger.info("failed to obtain region from default provider chain", e);
108-
return null;
109-
}
104+
return DefaultAwsRegionProviderChain.builder().build().getRegion();
110105
}
111106

112107
@Override

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.elasticsearch.common.component.AbstractLifecycleComponent;
4949
import org.elasticsearch.common.settings.Setting;
5050
import org.elasticsearch.common.settings.Settings;
51-
import org.elasticsearch.common.util.concurrent.RunOnce;
5251
import org.elasticsearch.core.Nullable;
5352
import org.elasticsearch.core.Releasable;
5453
import org.elasticsearch.core.Releasables;
@@ -94,8 +93,7 @@ class S3Service extends AbstractLifecycleComponent {
9493
Setting.Property.NodeScope
9594
);
9695

97-
private final Runnable defaultRegionSetter;
98-
private volatile Region defaultRegion;
96+
private final S3DefaultRegionHolder defaultRegionHolder;
9997

10098
/**
10199
* Use a signer that does not require to pre-read (and checksum) the body of PutObject and UploadPart requests since we can rely on
@@ -129,7 +127,7 @@ class S3Service extends AbstractLifecycleComponent {
129127
compareAndExchangeTimeToLive = REPOSITORY_S3_CAS_TTL_SETTING.get(nodeSettings);
130128
compareAndExchangeAntiContentionDelay = REPOSITORY_S3_CAS_ANTI_CONTENTION_DELAY_SETTING.get(nodeSettings);
131129
isStateless = DiscoveryNode.isStateless(nodeSettings);
132-
defaultRegionSetter = new RunOnce(() -> defaultRegion = defaultRegionSupplier.get());
130+
defaultRegionHolder = new S3DefaultRegionHolder(defaultRegionSupplier);
133131
s3ClientsManager = new S3ClientsManager(
134132
nodeSettings,
135133
this::buildClientReference,
@@ -266,7 +264,7 @@ Region getClientRegion(S3ClientSettings clientSettings) {
266264
} else {
267265
endpointDescription = "no configured endpoint";
268266
}
269-
final var defaultRegion = this.defaultRegion;
267+
final var defaultRegion = defaultRegionHolder.getDefaultRegion();
270268
if (defaultRegion != null) {
271269
LOGGER.debug("""
272270
found S3 client with no configured region and {}, using region [{}] from SDK""", endpointDescription, defaultRegion);
@@ -415,7 +413,7 @@ public void onBlobStoreClose(@Nullable ProjectId projectId) {
415413

416414
@Override
417415
protected void doStart() {
418-
defaultRegionSetter.run();
416+
defaultRegionHolder.start();
419417
}
420418

421419
@Override

0 commit comments

Comments
 (0)