Skip to content

client/tso: encapsulate request metadata - #11084

Open
disksing wants to merge 4 commits into
masterfrom
apiv3-client-tso-legacy-tests
Open

client/tso: encapsulate request metadata#11084
disksing wants to merge 4 commits into
masterfrom
apiv3-client-tso-legacy-tests

Conversation

@disksing

@disksing disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #10989

The API V3 client work needs to extend the metadata carried by TSO requests. Before adding new identity fields, the existing keyspace-ID path should be covered by characterization tests and represented as one internal value so later changes remain focused and reviewable.

What is changed and how does it work?

Add characterization tests for the existing PD and standalone TSO stream
adapters and keyspace-group lookup behavior.

Group the existing cluster ID, keyspace ID, and keyspace group ID into an
internal request metadata value. The generated protobuf requests and response
handling remain unchanged.

This PR:

  • tests the exact legacy requests and responses for both TSO stream adapters;
  • tests the current keyspace-group lookup request and error handling;
  • introduces an internal tsoRequestMetadata value for the existing request fields;
  • does not add API V3 types or change protocol behavior.

Check List

Tests

  • Unit test

Code changes

  • None

Side effects

  • None

Related changes

  • None

Release note

None.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when routing timestamp requests through legacy and modern service protocols.
    • Preserved keyspace-group information throughout timestamp request processing.
    • Strengthened handling of service discovery errors, stale data, missing groups, and connection changes.
  • Tests

    • Expanded coverage for timestamp request conversion and legacy service discovery scenarios.
    • Added validation for successful responses, failures, revision checks, and connection cleanup.

Signed-off-by: disksing <i@disksing.com>
Signed-off-by: disksing <i@disksing.com>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. labels Aug 3, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cabinfeverb for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f789952-36c4-4704-b760-6894e87c7326

📥 Commits

Reviewing files that changed from the base of the PR and between 1986f03 and 19b1f27.

📒 Files selected for processing (1)
  • client/servicediscovery/tso_service_discovery_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/servicediscovery/tso_service_discovery_test.go

📝 Walkthrough

Walkthrough

TSO request identifiers now use a shared metadata structure. Stream adapters, dispatch logic, queued requests, and tests use the new contract. Legacy service-discovery tests cover successful and failing protocol responses.

Changes

TSO metadata propagation

Layer / File(s) Summary
Metadata contract and stream propagation
client/clients/tso/stream.go, client/clients/tso/dispatcher.go
TSO request identifiers now use tsoRequestMetadata. Dispatch, queuing, and PD and microservice stream adapters pass this structure.
Protocol conversion validation
client/clients/tso/stream_test.go
Tests and benchmarks use the metadata-based stream contract. Mock PD and TSO streams validate request conversion and response decoding.
Legacy discovery validation
client/servicediscovery/tso_service_discovery_test.go
Tests validate legacy TSO responses, request fields, revisions, RPC errors, missing groups, callee mismatches, and connection removal.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • tikv/pd#11024: Both changes modify TSO stream metadata handling. This change groups request identifiers, while that PR updates protobuf oneof encoding.

Suggested reviewers: jmpotato

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: grouping TSO request metadata into an internal value.
Description check ✅ Passed The description covers the problem, issue reference, implementation, tests, side effects, related changes, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch apiv3-client-tso-legacy-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/servicediscovery/tso_service_discovery_test.go`:
- Around line 66-68: Update the goroutine invoking grpcServer.Serve to capture
its returned error and handle it explicitly, using the test’s existing failure
or shutdown pattern where appropriate; do not discard the Serve result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 62e535b2-cfc5-4b4d-b1e0-4162368e9702

📥 Commits

Reviewing files that changed from the base of the PR and between a187877 and bb9079b.

📒 Files selected for processing (4)
  • client/clients/tso/dispatcher.go
  • client/clients/tso/stream.go
  • client/clients/tso/stream_test.go
  • client/servicediscovery/tso_service_discovery_test.go

Comment thread client/servicediscovery/tso_service_discovery_test.go
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.38%. Comparing base (a187877) to head (19b1f27).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11084      +/-   ##
==========================================
+ Coverage   79.17%   79.38%   +0.20%     
==========================================
  Files         541      541              
  Lines       76487    76655     +168     
==========================================
+ Hits        60558    60849     +291     
+ Misses      11629    11541      -88     
+ Partials     4300     4265      -35     
Flag Coverage Δ
unittests 79.38% <100.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

handled the grpc server serve error in the test as suggested

@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/test pull-unit-test-next-gen-2

Copilot AI 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.

Pull request overview

This PR prepares the client-side TSO path for future API V3 identity expansion by (1) adding characterization tests for existing/legacy request shapes and keyspace-group lookup behavior, and (2) encapsulating the existing cluster/keyspace/keyspace-group identifiers into an internal tsoRequestMetadata value so later identity additions can remain localized.

Changes:

  • Add characterization tests for legacy FindGroupByKeyspaceID behavior (requests, responses, error paths, and connection removal on callee mismatch).
  • Introduce internal tsoRequestMetadata and thread it through the TSO stream adapter/dispatcher path without changing wire protocol behavior.
  • Add characterization tests for the PD and standalone TSO stream adapters’ exact request/response conversion.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
client/servicediscovery/tso_service_discovery_test.go Adds a gRPC test server and characterization tests for legacy FindGroupByKeyspaceID request/response/error handling.
client/clients/tso/stream.go Introduces tsoRequestMetadata and updates stream adapter Send signature to take metadata as a single value.
client/clients/tso/stream_test.go Adds characterization tests for PD/TSO stream adapter request generation and response decoding; updates mocks to use metadata.
client/clients/tso/dispatcher.go Builds and passes tsoRequestMetadata into stream request processing.

modRevision,
)

request := <-server.requests
@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

addressed the review: bounded the wait for the FindGroupByKeyspaceID request with a 5s timeout in the characterization test

@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/test pull-integration-realcluster-test

2 similar comments
@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/test pull-integration-realcluster-test

@disksing

disksing commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/test pull-integration-realcluster-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants