Enable compiled endpoint rules for all services and fix regionId parameter mismatch bug - #7265
Enable compiled endpoint rules for all services and fix regionId parameter mismatch bug#7265S-Saranya1 wants to merge 5 commits into
Conversation
…meter mismatch bug
RanVaknin
left a comment
There was a problem hiding this comment.
The current test suite doesn't cover the scenario that was actually broken. All existing fixtures use services that reference the region, so they only exercise the happy path.
Could you add coverage for a service that declares a Region parameter but never uses it in its rules (with enableGenerateCompiledEndpointRules": true)?
Good point, added a test with a service model where the root rule delegates without directly using region. |
… but never referenced
Motivation and Context
Compiled endpoint rules generate endpoint resolution logic as direct Java code at codegen time, rather than interpreting rules at runtime. This provides ~40% better performance. The feature was behind a flag (
enableGenerateCompiledEndpointRules) and already enabled for 344 services externally. This PR enables it for all remaining internal services by flipping the flag totrue.However, simply flipping the flag exposed a bug in the compiled endpoint provider codegen. The resolveEndpoint method extracts the region as a local String variable and always passes it to the root rule method:
But the root rule method's signature is generated based on scope analysis, it only includes regionId as a parameter if that method directly uses it. For most services, the root rule directly uses region (e.g., to look up the partition), so the 2-arg call matches:
private static RuleResult endpointRule0(Params params, String regionId) { ... }// 2 params - worksBut for some services, the root rule just delegates to a child rule without using region itself:
private static RuleResult endpointRule0(Params params) { ... }// 1 param - compile error!This creates a mismatch: the call site passes 2 arguments but the method only accepts 1.
This PR fixes the bug by adding a regionId() method to the endpoint params class that returns the region as a String (null-safe). The codegen now emits params.regionId() wherever the rules need the region as a string, eliminating the local variable and the parameter passing mismatch entirely.
Modifications
enableGenerateCompiledEndpointRulesdefault from false to trueRegion region = params.region();String regionId = ...) fromresolveEndpointMethod(). UpdateinitSymbolTable()to mark region params viaaddRegionParam()instead of creating a localString regionParamNamewithSet<String> regionParams. AddisRegionParam()andaddRegionParam()methodsregionParamName()accessorparams.regionId()(append "Id" to accessor name) instead ofparams.region()regionId()method for Region-typed params:return region == null ? null : region.id()regionId()default method to the interfaceregionId()overriderulesEngineResourceFiles2()so compiled rules codegen works when running from exploded classes in test environmentsTesting
params.regionId()patternScreenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License