Skip to content

Commit 8f4de13

Browse files
some tidying, questions, and marking todo work
1 parent 01c42a8 commit 8f4de13

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void close() {
254254

255255
@Override
256256
public String serviceName() {
257-
return null;
257+
return "AmazonS3Wrapper";
258258
}
259259

260260
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,13 @@ S3Service s3Service(Environment environment, Settings nodeSettings, ResourceWatc
259259
return new ProxyS3Service(environment, nodeSettings, resourceWatcherService);
260260
}
261261

262+
/**
263+
* This wrapper exposes a copy of the AWS credentials that the S3Client uses.
264+
*/
262265
public static final class ClientAndCredentials extends AmazonS3Wrapper {
263266
final AwsCredentialsProvider credentials;
264-
final SdkHttpClient httpClient;
267+
// The httpClient must be explicitly closed. Closure of the S3Client, which uses the httpClient, will not do so.
268+
private final SdkHttpClient httpClient;
265269

266270
ClientAndCredentials(S3Client delegate, SdkHttpClient httpClient, AwsCredentialsProvider credentials) {
267271
super(delegate);

modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3BlobStoreRepositoryTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,16 @@ protected static class S3ErroneousHttpHandler extends ErroneousHttpHandler {
658658
// S3 SDK stops retrying after TOKEN_BUCKET_SIZE/DEFAULT_EXCEPTION_TOKEN_COST == 500/5 == 100 failures in quick succession
659659
// see software.amazon.awssdk.retries.DefaultRetryStrategy.Legacy.TOKEN_BUCKET_SIZE
660660
// see software.amazon.awssdk.retries.DefaultRetryStrategy.Legacy.DEFAULT_EXCEPTION_TOKEN_COST
661+
// TODO NOMERGE: do we need to use (100 - DEFAULT_EXCEPTION_TOKEN_COST) to avoid running out of tokens?
661662
private final Semaphore failurePermits = new Semaphore(100);
662663

663664
S3ErroneousHttpHandler(final HttpHandler delegate, final int maxErrorsPerRequest) {
664665
super(delegate, maxErrorsPerRequest);
665666
}
666667

668+
/**
669+
* Bypasses {@link ErroneousHttpHandler#handle} once we exhaust {@link #failurePermits} because S3 will start rate limiting.
670+
*/
667671
@Override
668672
public void handle(HttpExchange exchange) throws IOException {
669673
if (failurePermits.tryAcquire()) {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.settings.Setting.Property;
2020
import org.elasticsearch.common.settings.Settings;
2121
import org.elasticsearch.core.TimeValue;
22+
import org.elasticsearch.core.UpdateForV10;
2223

2324
import java.util.Collections;
2425
import java.util.HashMap;
@@ -76,7 +77,8 @@ final class S3ClientSettings {
7677
key -> new Setting<>(key, "", s -> s.toLowerCase(Locale.ROOT), Property.NodeScope)
7778
);
7879

79-
/** Formerly the protocol to use to connect to s3, now unused */
80+
/** Formerly the protocol to use to connect to s3, now unused. V2 AWS SDK can infer the protocol from {@link #endpoint}. */
81+
@UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_COORDINATION) // no longer used, should be removed in v10
8082
static final Setting.AffixSetting<HttpScheme> UNUSED_PROTOCOL_SETTING = Setting.affixKeySetting(
8183
PREFIX,
8284
"protocol",
@@ -139,7 +141,8 @@ final class S3ClientSettings {
139141
key -> Setting.intSetting(key, Defaults.RETRY_COUNT, 0, Property.NodeScope)
140142
);
141143

142-
/** Formerly whether retries should be throttled (ie use backoff), now unused. */
144+
/** Formerly whether retries should be throttled (ie use backoff), now unused. V2 AWS SDK always uses throttling. */
145+
@UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_COORDINATION) // no longer used, should be removed in v10
143146
static final Setting.AffixSetting<Boolean> UNUSED_USE_THROTTLE_RETRIES_SETTING = Setting.affixKeySetting(
144147
PREFIX,
145148
"use_throttle_retries",
@@ -167,7 +170,8 @@ final class S3ClientSettings {
167170
key -> Setting.simpleString(key, Property.NodeScope)
168171
);
169172

170-
/** Formerly an override for the signer to use, now unused. */
173+
/** Formerly an override for the signer to use, now unused. V2 AWS SDK only supports AWS v4 signatures. */
174+
@UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_COORDINATION) // no longer used, should be removed in v10
171175
static final Setting.AffixSetting<String> UNUSED_SIGNER_OVERRIDE = Setting.affixKeySetting(
172176
PREFIX,
173177
"signer_override",
@@ -354,6 +358,7 @@ static boolean checkDeprecatedCredentials(Settings repositorySettings) {
354358
}
355359

356360
// backcompat for reading keys out of repository settings (clusterState)
361+
// TODO NOMERGE: delete this comment? Doesn't give me any context to understand. Can we delete deprecated code?
357362
private static AwsCredentials loadDeprecatedCredentials(Settings repositorySettings) {
358363
assert checkDeprecatedCredentials(repositorySettings);
359364
try (
@@ -474,6 +479,6 @@ static final class Defaults {
474479
static final TimeValue READ_TIMEOUT = TimeValue.timeValueSeconds(50);
475480
static final int MAX_CONNECTIONS = 50;
476481
static final int RETRY_COUNT = 3;
477-
static final boolean THROTTLE_RETRIES = true;
482+
static final boolean THROTTLE_RETRIES = true; // NOMERGE: delete this and hardcode for one (deprecated) use?
478483
}
479484
}

test/fixtures/aws-fixture-utils/src/main/java/fixture/aws/AwsCredentialsUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum AwsCredentialsUtils {
2626
/**
2727
* Region supplier which matches any region.
2828
*/
29+
// TODO NOMERGE: replace with DynamicRegionSupplier.
2930
public static final Supplier<String> ANY_REGION = () -> "*";
3031

3132
/**
@@ -72,7 +73,7 @@ public static boolean isValidAwsV4SignedAuthorizationHeader(
7273
}
7374

7475
if (region.equals("*")) {
75-
// skip region validation; TODO eliminate this when region is fixed in all tests
76+
// skip region validation; TODO NOMERGE eliminate this when region is fixed in all tests
7677
return authorizationHeader.contains("/" + serviceName + "/aws4_request, ");
7778
}
7879

0 commit comments

Comments
 (0)