-
Notifications
You must be signed in to change notification settings - Fork 916
S3CrossRegion Sync and Async Clients Redirect implementation #4089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3CrossRegion Sync and Async Clients Redirect implementation #4089
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Failed codegen test should be fixed by PR #4080
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
.../amazon/awssdk/services/s3/internal/crossregion/endpointprovider/BucketEndpointProvider.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...ware/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClientRedirectTest.java
Outdated
Show resolved
Hide resolved
...ware/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClientRedirectTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClientTest.java
Show resolved
Hide resolved
73f1003
to
233b93e
Compare
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3DecoratorRedirectBaseTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3DecoratorRedirectBaseTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3DecoratorRedirectBaseTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3DecoratorRedirectBaseTest.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/awssdk/services/s3/internal/crossregion/S3DecoratorRedirectBaseTest.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
|
||
return operation.apply(requestWithDecoratedEndpointProvider(request, bucket.get())) | ||
.whenComplete((r, t) -> handleOperationFailure(t, bucket.get())); | ||
if (bucketToRegionCache.containsKey(bucketName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the sync case, the try-catch contains both the call with cache hit and the cache miss, so the catch covers both cases. In this async instance, we will not catch a potential redirect as a result of calling with a cached region and we won't clear the cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line number 66 clears the cache.
Note that HeadBucket fall back logic comes into picture only when first fall back fails to get region and in this case we clear the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the code within the if-statement if (bucketToRegionCache.containsKey(bucketName))
. No other code will execute below that. If the call to requestWithDecoratedEndpointProvider
gets a redirect, it will not be handled. So the sync and async code will have slightly different behavior in that edge case. Question is if it's likely to occur at all and therefore worth handling - i.e., you get a region from the cache but it's the wrong region. Probably not a huge risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch !! This can happen if the bucket is changed, thanks for catching this bug.
Will update the code and add a test case for below standalone API call scenarios
- Redirect Cached and Success ==> 1st call
- Success ==> 2nd call
- Redirect and success ==> 3 rd Call
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
|
||
@SdkInternalApi | ||
public final class S3CrossRegionAsyncClient extends DelegatingS3AsyncClient { | ||
|
||
private final Map<String, CompletableFuture<Region>> bucketToRegionCache = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use LruCache to prevent this map from growing unbounded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LruCache cache doenot provide API to modify the Cache it just caches the content and provides get.
I will create a separate PR to make this bounded cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can update LruCache to support this? @cenedhryn WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems most use cases for Lru can be solved with a LinkedHashMap. (It may make sense to rewrite our LruCache on that model, but that's a different question)
For instance:
private static final int CAPACITY = 100;
private final Map<String, Region> bucketToRegionCache = Collections.synchronizedMap(
new LinkedHashMap<String, Region>(CAPACITY) {
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > CAPACITY;
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks , Will make the capacity as 300 to remain consistent with V1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we cannot implement using ConcurrentHashMap since it internally just does a putAlll and doesnot actually use LinkedHashMap in above
…bleFuture of main request
...in/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionSyncClient.java
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
ff52a5f
to
d086ece
Compare
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
String bucketName, | ||
CompletableFuture<ReturnT> returnFuture) { | ||
|
||
// // TODO: will fix the casts with separate PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a @SuppressWarnings("unchecked")
statement to requestWithDecoratedEndpointProvider
in CrossRegionUtils
in that PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ...Was wondering if there is a tool/scan which suggest this automatically ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually notice because IntelliJ gets angry and makes lines yellow.
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
...n/java/software/amazon/awssdk/services/s3/internal/crossregion/S3CrossRegionAsyncClient.java
Outdated
Show resolved
Hide resolved
a54eabc
to
f99d959
Compare
SonarCloud Quality Gate failed.
|
* Adding a generic method invokeOperation for abstract delegating clien… (#3996) Adding a generic method invokeOperation for abstract delegating client to allow overriding behavior changes for all operations * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration (#3978) * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration * updated review comments 1 * updated review comments 2 * Adds S3CrossRegion clients and codegen for retrieving bucket name (#4008) * Adds S3CrossRegion clients and codegen for retrieving bucket name * Removes codegen of bucket parameter since getValueForField() is better * Add back overloads * Adds cross region client logic for decorating endpoint provider (#4026) * Adds cross region client logic for decorating endpoint provider * Paginated methods returning publisher or iterable implement logic in … (#4046) * Paginated methods returning publisher or iterable implement logic in interface instead of throwing unsupported exception * Added internal annotation to class * Wraps s3 client in cross regional client when enabled (#4080) * Wraps s3 client in cross regional client when enabled * Adds composer interface * Add User Agent Api name for Cross region API calls (#4105) * Add User Agent Api name for Cross region API calls * Added test case for default client not to have user agent related to cross region * S3CrossRegion Sync and Async Clients Redirect implementation (#4089) * S3CrossRegionSyncClient Redirect implementation * Added implementation for Async client Decorator * Updated older Cross region test cases * Added paramterized test * Async Exception checged to completableException * Updated test cases and changes the Exception handling when HeadBucket Call fails * Handled Anna-karin's comments * Removed async execution of HeadBucket and attached it to the completableFuture of main request * Handled Zoe's comments * Added test case when Redirected after the Region is cached * Changed region constant to Region Type in Tests * Cross region support for CRT Client (#4129) * Cross region support for CRT Client * removing common class * handled review comments * Integration test cases for Cross region Async and Sync Clients (#4128) * Integration test cases for Cross region Sync and Sync Clients * Renamed files as Integration test * Handled CR comments to take care of retries thus captureInterceptor is removed * rebased and added CRT in Integ test * removed sout from integ * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators (#4151) * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators * Removed from S3Configurations * Move the optional parameter in getter --------- Co-authored-by: Anna-Karin Salander <[email protected]>
* Adding a generic method invokeOperation for abstract delegating clien… (#3996) Adding a generic method invokeOperation for abstract delegating client to allow overriding behavior changes for all operations * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration (#3978) * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration * updated review comments 1 * updated review comments 2 * Adds S3CrossRegion clients and codegen for retrieving bucket name (#4008) * Adds S3CrossRegion clients and codegen for retrieving bucket name * Removes codegen of bucket parameter since getValueForField() is better * Add back overloads * Adds cross region client logic for decorating endpoint provider (#4026) * Adds cross region client logic for decorating endpoint provider * Paginated methods returning publisher or iterable implement logic in … (#4046) * Paginated methods returning publisher or iterable implement logic in interface instead of throwing unsupported exception * Added internal annotation to class * Wraps s3 client in cross regional client when enabled (#4080) * Wraps s3 client in cross regional client when enabled * Adds composer interface * Add User Agent Api name for Cross region API calls (#4105) * Add User Agent Api name for Cross region API calls * Added test case for default client not to have user agent related to cross region * S3CrossRegion Sync and Async Clients Redirect implementation (#4089) * S3CrossRegionSyncClient Redirect implementation * Added implementation for Async client Decorator * Updated older Cross region test cases * Added paramterized test * Async Exception checged to completableException * Updated test cases and changes the Exception handling when HeadBucket Call fails * Handled Anna-karin's comments * Removed async execution of HeadBucket and attached it to the completableFuture of main request * Handled Zoe's comments * Added test case when Redirected after the Region is cached * Changed region constant to Region Type in Tests * Cross region support for CRT Client (#4129) * Cross region support for CRT Client * removing common class * handled review comments * Integration test cases for Cross region Async and Sync Clients (#4128) * Integration test cases for Cross region Sync and Sync Clients * Renamed files as Integration test * Handled CR comments to take care of retries thus captureInterceptor is removed * rebased and added CRT in Integ test * removed sout from integ * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators (#4151) * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators * Removed from S3Configurations * Move the optional parameter in getter --------- Co-authored-by: Anna-Karin Salander <[email protected]>
* Adding a generic method invokeOperation for abstract delegating clien… (#3996) Adding a generic method invokeOperation for abstract delegating client to allow overriding behavior changes for all operations * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration (#3978) * Add endpointProvider in ClientConfig and RequestOverrideConfig. Also add crossRegionBucketAccess in S3Configuration * updated review comments 1 * updated review comments 2 * Adds S3CrossRegion clients and codegen for retrieving bucket name (#4008) * Adds S3CrossRegion clients and codegen for retrieving bucket name * Removes codegen of bucket parameter since getValueForField() is better * Add back overloads * Adds cross region client logic for decorating endpoint provider (#4026) * Adds cross region client logic for decorating endpoint provider * Paginated methods returning publisher or iterable implement logic in … (#4046) * Paginated methods returning publisher or iterable implement logic in interface instead of throwing unsupported exception * Added internal annotation to class * Wraps s3 client in cross regional client when enabled (#4080) * Wraps s3 client in cross regional client when enabled * Adds composer interface * Add User Agent Api name for Cross region API calls (#4105) * Add User Agent Api name for Cross region API calls * Added test case for default client not to have user agent related to cross region * S3CrossRegion Sync and Async Clients Redirect implementation (#4089) * S3CrossRegionSyncClient Redirect implementation * Added implementation for Async client Decorator * Updated older Cross region test cases * Added paramterized test * Async Exception checged to completableException * Updated test cases and changes the Exception handling when HeadBucket Call fails * Handled Anna-karin's comments * Removed async execution of HeadBucket and attached it to the completableFuture of main request * Handled Zoe's comments * Added test case when Redirected after the Region is cached * Changed region constant to Region Type in Tests * Cross region support for CRT Client (#4129) * Cross region support for CRT Client * removing common class * handled review comments * Integration test cases for Cross region Async and Sync Clients (#4128) * Integration test cases for Cross region Sync and Sync Clients * Renamed files as Integration test * Handled CR comments to take care of retries thus captureInterceptor is removed * rebased and added CRT in Integ test * removed sout from integ * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators (#4151) * Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators * Removed from S3Configurations * Move the optional parameter in getter --------- Co-authored-by: Anna-Karin Salander <[email protected]>
Motivation and Context
Modifications
Testing
License