Skip to content

Commit 7986219

Browse files
retajainankitk
authored andcommitted
Fallback to netty client if AWS Crt client is not available on the target platform / architecture (opensearch-project#20698)
Signed-off-by: Andriy Redko <drreta@gmail.com> Signed-off-by: Ankit Jain <jainankitk@apache.org>
1 parent b6cabb7 commit 7986219

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3333
- Leveraging segment-global ordinal mapping for efficient terms aggregation ([#20624](https://github.com/opensearch-project/OpenSearch/pull/20624))
3434
- Support Docker distribution builds for ppc64le, arm64 and s390x ([#20678](https://github.com/opensearch-project/OpenSearch/pull/20678))
3535
- Harden detection of HTTP/3 support by ensuring Quic native libraries are available for the target platform ([#20680](https://github.com/opensearch-project/OpenSearch/pull/20680))
36+
- Fallback to netty client if AWS Crt client is not available on the target platform / architecture ([#20698](https://github.com/opensearch-project/OpenSearch/pull/20698))
3637
- Fix ShardSearchFailure in transport-grpc ([#20641](https://github.com/opensearch-project/OpenSearch/pull/20641))
3738

3839
### Dependencies

plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.opensearch.repositories.s3.S3ClientSettings.IrsaCredentials;
5050
import org.opensearch.repositories.s3.async.AsyncExecutorContainer;
5151
import org.opensearch.repositories.s3.async.AsyncTransferEventLoopGroup;
52+
import org.opensearch.repositories.s3.utils.AwsCrtUtils;
5253
import org.opensearch.secure_sm.AccessController;
5354

5455
import java.io.Closeable;
@@ -335,7 +336,16 @@ static SdkAsyncHttpClient buildHttpClient(
335336
if (S3Repository.NETTY_ASYNC_HTTP_CLIENT_TYPE.equals(asyncHttpClientType)) {
336337
return buildAsyncNettyHttpClient(clientSettings, asyncTransferEventLoopGroup);
337338
}
338-
return buildAsyncCrtHttpClient(clientSettings);
339+
if (AwsCrtUtils.isAwsCrtAvailable() == true) {
340+
return buildAsyncCrtHttpClient(clientSettings);
341+
} else {
342+
logger.warn(
343+
"AWS CRT client is not available on the target platform, falling back to "
344+
+ S3Repository.NETTY_ASYNC_HTTP_CLIENT_TYPE
345+
+ " client type"
346+
);
347+
return buildAsyncNettyHttpClient(clientSettings, asyncTransferEventLoopGroup);
348+
}
339349
}
340350

341351
static SdkAsyncHttpClient buildAsyncNettyHttpClient(
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.repositories.s3.utils;
10+
11+
import software.amazon.awssdk.crt.CRT;
12+
import software.amazon.awssdk.crt.CRT.UnknownPlatformException;
13+
14+
/**
15+
* An utility class to check if AWS CRT client is available on the current platform and architecture.
16+
*/
17+
public final class AwsCrtUtils {
18+
static final boolean isAwsCrtAvailable;
19+
20+
static {
21+
boolean crtAvailable;
22+
try {
23+
final String archIdentifier = CRT.getArchIdentifier();
24+
crtAvailable = (archIdentifier != null && archIdentifier.isBlank() == false);
25+
} catch (ExceptionInInitializerError | UnknownPlatformException ex) {
26+
crtAvailable = false;
27+
}
28+
// CRT native libraries are not available on some platforms
29+
isAwsCrtAvailable = crtAvailable;
30+
}
31+
32+
private AwsCrtUtils() {
33+
34+
}
35+
36+
/**
37+
* Check if AWS CRT client is available on the current platform and architecture.
38+
*
39+
* @return true if AWS CRT client is available
40+
*/
41+
public static boolean isAwsCrtAvailable() {
42+
return isAwsCrtAvailable;
43+
}
44+
}

plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3AsyncServiceTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.opensearch.common.settings.Settings;
1919
import org.opensearch.repositories.s3.async.AsyncExecutorContainer;
2020
import org.opensearch.repositories.s3.async.AsyncTransferEventLoopGroup;
21+
import org.opensearch.repositories.s3.utils.AwsCrtUtils;
2122
import org.opensearch.secure_sm.AccessController;
2223
import org.opensearch.test.OpenSearchTestCase;
2324
import org.junit.Before;
@@ -29,6 +30,8 @@
2930

3031
import io.netty.channel.nio.NioEventLoopGroup;
3132

33+
import static org.hamcrest.CoreMatchers.equalTo;
34+
import static org.junit.Assume.assumeThat;
3235
import static org.mockito.Mockito.mock;
3336
import static org.mockito.Mockito.verify;
3437
import static org.mockito.Mockito.when;
@@ -173,6 +176,8 @@ public void testBuildHttpClientWithNetty() {
173176
}
174177

175178
public void testBuildHttpClientWithCRT() {
179+
assumeThat("AWS CRT client is not available on the target platform", AwsCrtUtils.isAwsCrtAvailable(), equalTo(true));
180+
176181
final int port = randomIntBetween(10, 1080);
177182
final String userName = randomAlphaOfLength(10);
178183
final String password = randomAlphaOfLength(10);

0 commit comments

Comments
 (0)