Skip to content

Fix inconsistent updateSdkClientConfiguration methods in sync and async clients and optmize performance #6232

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Jul 3, 2025

Motivation and Context

  • I noticed that the updateSdkClientConfiguration has different implementation in sync and async clients. More specifically, the method in sync client has additional validation but the one in async client doesn't.
--- async.java	2025-07-04 09:45:06
+++ sync.java	2025-07-04 09:44:50
@@ -1,13 +1,21 @@
     private SdkClientConfiguration updateSdkClientConfiguration(SdkRequest request, SdkClientConfiguration clientConfiguration) {
         List<SdkPlugin> plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList());
         SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();
         if (plugins.isEmpty()) {
             return configuration.build();
         }
         S3ServiceClientConfigurationBuilder serviceConfigBuilder = new S3ServiceClientConfigurationBuilder(configuration);
         for (SdkPlugin plugin : plugins) {
             plugin.configureClient(serviceConfigBuilder);
         }
+        AttributeMap newContextParams = configuration.option(SdkClientOption.CLIENT_CONTEXT_PARAMS);
+        AttributeMap originalContextParams = clientConfiguration.option(SdkClientOption.CLIENT_CONTEXT_PARAMS);
+        newContextParams = (newContextParams != null) ? newContextParams : AttributeMap.empty();
+        originalContextParams = originalContextParams != null ? originalContextParams : AttributeMap.empty();
+        Validate.validState(
+                Objects.equals(originalContextParams.get(S3ClientContextParams.CROSS_REGION_ACCESS_ENABLED),
+                        newContextParams.get(S3ClientContextParams.CROSS_REGION_ACCESS_ENABLED)),
+                "CROSS_REGION_ACCESS_ENABLED cannot be modified by request level plugins");
         updateRetryStrategyClientConfiguration(configuration);
         return configuration.build();
     }
  • In the current implementation updateSdkClientConfiguration always calls clientConfiguration.toBuilder() even though there is no plugin configured, which may be costly.
        List<SdkPlugin> plugins = request.overrideConfiguration().map(c -> c.plugins()).orElse(Collections.emptyList());
        SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();
        if (plugins.isEmpty()) {
            return configuration.build();
        }
       ...

Modifications

  • Reuse updateSdkClientConfiguration methods in sync and async codegen classes so that the generated methods are the same for sync and async clients.
  • Optimized the pattern to use early return, avoiding object creation when plugins are empty:
if (plugins.isEmpty()) {
    return clientConfiguration;  // Direct return, no object creation
}
SdkClientConfiguration.Builder configuration = clientConfiguration.toBuilder();

Testing

Add new codegen tests and update existing tests fixture

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

zoewangg added 2 commits July 3, 2025 13:25
…c code paths so that the generated code is the same
… plugin configured to avoid client config toBuilder call
@zoewangg zoewangg requested a review from a team as a code owner July 3, 2025 22:24
Copy link

sonarqubecloud bot commented Jul 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant