Skip to content

Commit 51f4589

Browse files
SOLR-15599: Upgrade AWS SDK from v1 to v2 (#271)
Also removed woodstox-core-asl dependency, and replaced with com.fasterxml.woodstox:woodstox-core:6.2.4, the newer version of the dependency.
1 parent cfa7ec9 commit 51f4589

36 files changed

+369
-1160
lines changed

solr/CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ Improvements
396396

397397
* SOLR-9853: Project multi-valued fields in SQL query results (Timothy Potter)
398398

399+
* SOLR-15599: Upgrade AWS SDK from v1 to v2 for S3 Repository (Houston Putman)
400+
399401
Optimizations
400402
---------------------
401403
* SOLR-15433: Replace transient core cache LRU by Caffeine cache. (Bruno Roustant)
@@ -437,6 +439,8 @@ Other Changes
437439

438440
* SOLR-15324: Upgrade Jaeger dependency from 1.1.0 to 1.6.0 and thus also libthrift to 0.14.1 (janhoy)
439441

442+
* SOLR-15599: woodstox-core-asl:4.4.1 (org.codehaus) replaced with woodstox-core:6.2.4 (com.fasterxml) (Houston Putman)
443+
440444
================== 8.9.0 ==================
441445

442446
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

solr/contrib/s3-repository/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ This S3 repository is a backup repository implementation designed to provide bac
77

88
Add this to your `solr.xml`:
99

10+
```xml
1011
<backup>
1112
<repository name="s3" class="org.apache.solr.s3.S3BackupRepository" default="false">
1213
<str name="s3.bucket.name">BUCKET_NAME</str>
1314
<str name="s3.region">us-west-2</str>
1415
</repository>
1516
</backup>
17+
```
1618

17-
This plugin uses the [default AWS credentials provider chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html), so ensure that your credentials are set appropriately (e.g., via env var, or in `~/.aws/credentials`, etc.).
19+
This plugin uses the [default AWS credentials provider chain](https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html), so ensure that your credentials are set appropriately (e.g., via env var, or in `~/.aws/credentials`, etc.).
1820

1921
## Testing locally
2022

@@ -25,13 +27,15 @@ To run / test locally, first spin up S3Mock:
2527

2628
Add this to your `solr.xml`:
2729

30+
```xml
2831
<backup>
2932
<repository name="s3" class="org.apache.solr.s3.S3BackupRepository" default="false">
3033
<str name="s3.endpoint">http://localhost:9090</str>
3134
<str name="s3.bucket.name">TEST_BUCKET</str>
3235
<str name="s3.region">us-east-1</str>
3336
</repository>
3437
</backup>
38+
```
3539

3640
Start Solr, and create a collection (e.g., "foo"). Then hit the following URL, which will take a backup and persist it in S3Mock under the name `test`:
3741

@@ -45,13 +49,15 @@ http://localhost:8983/solr/admin/collections?action=RESTORE&repository=s3&locati
4549

4650
If you are also running Solr in a docker image, and need to set the endpoint of S3Mock to be different than `localhost`, then add the following under `<repository>`:
4751

52+
```xml
4853
<backup>
4954
<repository name="s3" class="org.apache.solr.s3.S3BackupRepository" default="false">
5055
<str name="s3.bucket.name">TEST_BUCKET</str>
5156
<str name="s3.endpoint">http://host.docker.internal:9090</str>
5257
<str name="s3.region">us-east-1</str>
5358
</repository>
5459
</backup>
60+
```
5561

5662
This works for the regular S3 backup repository as well (not mock).
5763
But the plugin only provides official support for AWS S3, not _S3 compatible_ products.

solr/contrib/s3-repository/build.gradle

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ description = 'S3 Repository'
2323
dependencies {
2424
api project(':solr:core')
2525

26-
implementation platform('com.amazonaws:aws-java-sdk-bom')
27-
28-
implementation ('com.amazonaws:aws-java-sdk-core') { exclude group: 'commons-codec', module: 'commons-codec' }
29-
implementation ('com.amazonaws:aws-java-sdk-s3') { exclude group: 'commons-codec', module: 'commons-codec' }
30-
31-
// Not strictly needed, but provides better performance according to AWS SDK
32-
// Can remove this when we upgrade to AWS SDK v2
33-
implementation ('javax.xml.bind:jaxb-api') { transitive = false }
26+
implementation platform(group: 'software.amazon.awssdk', name: 'bom')
27+
implementation (group: 'software.amazon.awssdk', name: 'auth')
28+
implementation (group: 'software.amazon.awssdk', name: 'apache-client')
29+
implementation (group: 'software.amazon.awssdk', name: 'aws-core')
30+
implementation (group: 'software.amazon.awssdk', name: 's3') {
31+
exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
32+
}
33+
implementation (group: 'software.amazon.awssdk', name: 'sdk-core')
34+
implementation (group: 'software.amazon.awssdk', name: 'protocol-core')
35+
runtimeOnly (group: 'com.fasterxml.woodstox', name: 'woodstox-core')
36+
runtimeOnly (group: 'org.codehaus.woodstox', name: 'stax2-api')
3437

3538
testImplementation('com.adobe.testing:s3mock-junit4') {
3639
// Don't pull in separate versions of these libs, just use what Solr already has
@@ -41,6 +44,8 @@ dependencies {
4144
exclude group: 'commons-io', module: 'commons-io'
4245
exclude group: 'commons-codec', module: 'commons-codec'
4346
exclude group: 'org.apache.commons', module: 'commons-lang3'
47+
exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
48+
exclude group: 'org.codehaus.woodstox', module: 'stax2-api'
4449
}
4550

4651
testImplementation project(':solr:test-framework')
@@ -52,9 +57,11 @@ test {
5257
environment "spring.jmx.enabled", "false"
5358

5459
// Without this, randomizedtesting will think our tests leak threads (b/c S3Mock's Jetty hasn't bothered to clean up yet)
55-
environment "server.jetty.threads.idle-timeout", "3s"
60+
environment "server.jetty.threads.idle-timeout", "1s"
5661

5762
// Reduce logging noise during the tests
5863
environment "aws.accessKeyId", "foo"
59-
environment "aws.secretKey", "bar"
64+
environment "aws.secretAccessKey", "bar"
65+
environment "aws.sharedCredentialsFile", "conf/credentials"
66+
environment "aws.configFile", "conf/config"
6067
}

solr/contrib/s3-repository/src/java/org/apache/solr/s3/S3BackupRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public URI createURI(String location) {
8787
if (location.startsWith(S3_SCHEME + ":")) {
8888
result = new URI(location);
8989
} else if (location.startsWith("/")) {
90-
result = new URI(S3_SCHEME, null, location, null);
90+
result = new URI(S3_SCHEME, "", location, null);
9191
} else {
92-
result = new URI(S3_SCHEME, null, "/" + location, null);
92+
result = new URI(S3_SCHEME, "", "/" + location, null);
9393
}
9494
return result;
9595
} catch (URISyntaxException ex) {
@@ -124,9 +124,11 @@ public URI resolve(URI baseUri, String... pathComponents) {
124124
@Override
125125
public URI resolveDirectory(URI baseUri, String... pathComponents) {
126126
if (pathComponents.length > 0) {
127-
pathComponents[pathComponents.length - 1] = pathComponents[pathComponents.length - 1] + "/";
127+
if (!pathComponents[pathComponents.length - 1].endsWith("/")) {
128+
pathComponents[pathComponents.length - 1] = pathComponents[pathComponents.length - 1] + "/";
129+
}
128130
} else {
129-
if (!baseUri.getPath().endsWith("/")) {
131+
if (!baseUri.toString().endsWith("/")) {
130132
baseUri = URI.create(baseUri + "/");
131133
}
132134
}

solr/contrib/s3-repository/src/java/org/apache/solr/s3/S3BackupRepositoryConfig.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ public class S3BackupRepositoryConfig {
2929
public static final String BUCKET_NAME = "s3.bucket.name";
3030
public static final String REGION = "s3.region";
3131
public static final String ENDPOINT = "s3.endpoint";
32-
public static final String PROXY_HOST = "s3.proxy.host";
33-
public static final String PROXY_PORT = "s3.proxy.port";
32+
public static final String PROXY_URL = "s3.proxy.url";
33+
public static final String PROXY_USE_SYSTEM_SETTINGS = "s3.proxy.useSystemSettings";
3434

3535
private final String bucketName;
3636
private final String region;
37-
private final String proxyHost;
38-
private final int proxyPort;
37+
private final String proxyURL;
38+
private final boolean proxyUseSystemSettings;
3939
private final String endpoint;
4040

4141
public S3BackupRepositoryConfig(NamedList<?> config) {
4242
region = getStringConfig(config, REGION);
4343
bucketName = getStringConfig(config, BUCKET_NAME);
44-
proxyHost = getStringConfig(config, PROXY_HOST);
45-
proxyPort = getIntConfig(config, PROXY_PORT);
44+
proxyURL = getStringConfig(config, PROXY_URL);
45+
proxyUseSystemSettings = getBooleanConfig(config, PROXY_USE_SYSTEM_SETTINGS, true);
4646
endpoint = getStringConfig(config, ENDPOINT);
4747
}
4848

4949
/** Construct a {@link S3StorageClient} from the provided config. */
5050
public S3StorageClient buildClient() {
51-
return new S3StorageClient(bucketName, region, proxyHost, proxyPort, endpoint);
51+
return new S3StorageClient(bucketName, region, proxyURL, proxyUseSystemSettings, endpoint);
5252
}
5353

5454
private static String getStringConfig(NamedList<?> config, String property) {
@@ -73,10 +73,14 @@ private static int getIntConfig(NamedList<?> config, String property) {
7373

7474
/** If the property as any other value than 'true' or 'TRUE', this will default to false. */
7575
private static boolean getBooleanConfig(NamedList<?> config, String property) {
76+
return getBooleanConfig(config, property, false);
77+
}
78+
79+
private static boolean getBooleanConfig(NamedList<?> config, String property, boolean def) {
7680
String envProp = System.getenv().get(toEnvVar(property));
7781
if (envProp == null) {
7882
Boolean configProp = config.getBooleanArg(property);
79-
return configProp != null && configProp;
83+
return configProp == null ? def : configProp;
8084
} else {
8185
return Boolean.parseBoolean(envProp);
8286
}

0 commit comments

Comments
 (0)