Skip to content

fix(datastore): reset transport-default host when switching transport via toBuilder - #15414

Merged
jinseopkim0 merged 4 commits into
mainfrom
fix/datastore-tobuilder-transport-host
Dec 3, 2026
Merged

jinseopkim0 merged 4 commits into
mainfrom
fix/datastore-tobuilder-transport-host

Conversation

@jinseopkim0

@jinseopkim0 jinseopkim0 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

b/588887355#comment11

Reset transport-defaulted host when switching between gRPC and HTTP via DatastoreOptions.toBuilder().setTransportOptions(...) and recognize both transport defaults in DatastoreUtils.isDefaultHost().

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq, I might not be wrapping my head around this. Do we need to track hasCustomHost? Isn't this the same as isDefaultHost?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I agree that we do not need to track this, as this is redundant. Removed.

Comment on lines +184 to +189
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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Good idea, as this simplifies the code. I've updated the code as suggested.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@jinseopkim0
jinseopkim0 force-pushed the fix/datastore-tobuilder-transport-host branch from fbaefd3 to 1eeb2cc Compare December 3, 2026 19:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jinseopkim0
jinseopkim0 requested a review from lqiu96 December 3, 2026 20:02
@jinseopkim0
jinseopkim0 requested a review from lqiu96 December 3, 2026 20:48
@jinseopkim0
jinseopkim0 merged commit 43544ea into main Dec 3, 2026
195 checks passed
@jinseopkim0
jinseopkim0 deleted the fix/datastore-tobuilder-transport-host branch December 3, 2026 21:12
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.

2 participants