Repository navigation
fix(datastore): reset transport-default host when switching transport via toBuilder - #15414
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a hasCustomHost flag in DatastoreOptions to track whether a host was explicitly overridden by the caller or populated as a transport default. This prevents stale default endpoints from carrying over when switching transports (e.g., between gRPC and HTTP) via toBuilder(). It also adds a utility method DatastoreUtils.isDefaultHost() to identify default hosts for both transports and updates the RPC implementations and tests accordingly. The review feedback suggests a minor improvement in DatastoreOptions.java to use the existing setHost(null) helper method instead of manually setting the host field and calling the superclass method.
| @@ -192,6 +206,9 @@ public Builder setTransportOptions(GrpcTransportOptions transportOptions) { | |||
| @Override | |||
| public Builder setHost(String host) { | |||
| this.host = host; | |||
| // Treat null or default Datastore endpoints as non-custom so universe-domain resolution and | |||
| // transport switching still apply. | |||
| this.hasCustomHost = host != null && !DatastoreUtils.isDefaultHost(host); | |||
There was a problem hiding this comment.
qq, I might not be wrapping my head around this. Do we need to track hasCustomHost? Isn't this the same as isDefaultHost?
There was a problem hiding this comment.
Thanks for the feedback. I agree that we do not need to track this, as this is redundant. Removed.
| if (transportChanged && !this.hasCustomHost) { | ||
| // Reset transport-defaulted host (e.g., gRPC's datastore.googleapis.com:443 or HTTP's | ||
| // https://datastore.googleapis.com) so build() populates the new transport's default. | ||
| this.host = null; | ||
| super.setHost(null); | ||
| } |
There was a problem hiding this comment.
Ah, I didn't realize there was both setHost and setTransportOptions. We are resetting the host to null when we set a transportOption. Perhaps we should do all this logic in the build().
.setHost().setTransportOptions() would reset the host to null
.setTransportOptions.setHost() would keep the custom host
this might be a bit confusing
There was a problem hiding this comment.
Thanks for the feedback. Good idea, as this simplifies the code. I've updated the code as suggested.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces host normalization logic via a new DatastoreUtils.isDefaultHost helper to ensure that switching transports (e.g., via toBuilder()) correctly resets default hosts while preserving custom host overrides. It also updates gRPC and HTTP RPC classes to leverage this helper and adds comprehensive unit tests. The feedback suggests minor code cleanups: removing a redundant cast to TransportOptions in the tests and reordering conditions in HttpDatastoreRpc to check for an empty host first for better efficiency.
|
@gemini-code-assist review |
fbaefd3 to
1eeb2cc
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a utility method isDefaultHost in DatastoreUtils to recognize default Datastore service hosts for both HTTP and gRPC transports. This allows the library to correctly normalize default hosts and prevent stale default endpoints from carrying over when switching transports via toBuilder(), while ensuring that custom universe-domain endpoint resolution can properly distinguish default hosts from explicit custom host overrides. Comprehensive unit tests have been added to verify these behaviors. There are no review comments, so I have no additional feedback to provide.
b/588887355#comment11
Reset transport-defaulted host when switching between gRPC and HTTP via
DatastoreOptions.toBuilder().setTransportOptions(...)and recognize both transport defaults inDatastoreUtils.isDefaultHost().