Skip to content

feat(spanner): add Request ID header support - #16448

Merged
scotthart merged 1 commit into
googleapis:mainfrom
scotthart:spanner_request_id_phase1
Sep 23, 2026
Merged

scotthart merged 1 commit into
googleapis:mainfrom
scotthart:spanner_request_id_phase1

Conversation

@scotthart

@scotthart scotthart commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

This PR adds the spanner_internal::OperationContextFactory and integrates the previous PRs to complete the Request ID header functionality.

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

Copy link
Copy Markdown

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 generalized OperationContext mechanism to inject request IDs and track attempt lifecycles across retries, generalizing the Bigtable generator option and implementing a robust request ID tracking system in the Spanner client. The review feedback highlights critical thread-safety and correctness issues: a broken double-checked locking pattern in DefaultSpannerOperationContextFactory::StaticPrefix() that introduces data races, a thread-safety hazard in ProcessRandomId() due to returning a reference to a mutable static string instead of returning by value, and a bug in BatchWriteGuard where premature stream cancellation incorrectly reports a successful status.

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.89286% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.34%. Comparing base (19d0185) to head (ef1dddb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/spanner/internal/session_pool.cc 81.08% 21 Missing ⚠️
...nner/internal/spanner_operation_context_factory.cc 82.08% 12 Missing ⚠️
...internal/spanner_operation_context_factory_test.cc 87.20% 11 Missing ⚠️
google/cloud/spanner/internal/connection_impl.cc 96.29% 5 Missing ⚠️
...gle/cloud/spanner/internal/connection_impl_test.cc 97.61% 1 Missing ⚠️
google/cloud/spanner/internal/session_pool_test.cc 98.64% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16448      +/-   ##
==========================================
- Coverage   92.34%   92.34%   -0.01%     
==========================================
  Files        2254     2257       +3     
  Lines      215168   215559     +391     
==========================================
+ Hits       198699   199058     +359     
- Misses      16469    16501      +32     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scotthart

Copy link
Copy Markdown
Member Author

/gemini review

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

Copy link
Copy Markdown

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 SpannerOperationContextFactory and its default implementation to manage the creation of OperationContext instances across various Spanner operations, enabling better tracking of request IDs, channel IDs, and attempt counts. It updates ConnectionImpl, SessionPool, and associated tests and benchmarks to utilize this factory, and adds channel ID tracking to maintain channel affinity. Feedback on the changes highlights a potential null pointer dereference in the DefaultSpannerOperationContextFactory constructor if process_random_id is null, suggesting a defensive fallback to ProcessRandomId().

@scotthart
scotthart force-pushed the spanner_request_id_phase1 branch from 6269e2b to ef1dddb Compare September 22, 2026 21:59
@scotthart scotthart changed the title spanner request id prototype feat(spanner): add Request ID header support Sep 22, 2026
@scotthart
scotthart marked this pull request as ready for review September 22, 2026 22:02
@scotthart
scotthart requested a review from a team as a code owner September 22, 2026 22:02
@scotthart
scotthart merged commit a1c61a0 into googleapis:main Sep 23, 2026
68 checks passed

This branch was previously deployed

1 inactive deployment
false — ef1dddba Deployed Sep 22, 2026 by scotthart via Save PR ref #11936
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