Skip to content

pd: distinguish unsupported GC RPCs and propagate safe-point errors - #255

Open
rafa-w7 wants to merge 1 commit into
tikv:masterfrom
rafa-w7:wry/pd-gc-rpc-errors
Open

rafa-w7 wants to merge 1 commit into
tikv:masterfrom
rafa-w7:wry/pd-gc-rpc-errors

Conversation

@rafa-w7

@rafa-w7 rafa-w7 commented Nov 19, 2026 •

Copy link
Copy Markdown

Why this change is needed

A caller that reads a GC safe point needs to distinguish an unsupported PD method from a temporary failure. When an older PD returns gRPC UNIMPLEMENTED for GetGCState, its numeric status (12) collides with ServerIsBusy in the client. The caller can then keep retrying a method the server cannot provide. The legacy safe-point methods can also return the protobuf default timestamp when the RPC succeeds but the PD response header contains an error.

What changes

getGCState translates gRPC UNIMPLEMENTED into the existing GRPCNotImplemented client error before triggering a leader refresh. Other RPC errors continue through their existing handling. Both legacy safe-point methods check the PD response header before returning the timestamp. Callers retain control over whether to fall back and which keyspace to use.

Validation

  • The focused PDGCClient.DistinguishesUnsupportedRPCAndRejectsHeaderErrors regression passed against a test gRPC service. It exercises a successful lookup, unsupported and transient RPC errors, and errors returned in response headers.
  • A downstream Linux amd64 TiFlash integration run used this exact client commit (293e94cd). A clean TiUP deployment initialized both table replicas, applied committed changes, and caught up after a restart. All ten SQL result comparisons agreed with TiKV. At one transaction snapshot after restart, both engines returned 11,869 ordinary rows and 8,113 Blob rows. This integration also included the downstream changes that select the appropriate fallback.

Summary by CodeRabbit

  • Bug Fixes
    • GC state requests now report unsupported operations distinctly, while other service failures continue to raise errors.
    • GC safe-point requests now surface errors returned in successful responses, instead of treating them as valid results.
    • Keyspace-specific GC requests continue to use the requested keyspace when retrieving state and safe points.

Classify UNIMPLEMENTED at the gRPC boundary so callers can retain keyspace scope when falling back. Reject legacy safe-point responses carrying PD header errors.

Signed-off-by: ruiyu.wu <ruiyu.wu@pingcap.cn>
@ti-chi-bot ti-chi-bot Bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Nov 19, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

[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 kennytm 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 contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. labels Nov 19, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

Welcome @rafa-w7!

It looks like this is your first PR to tikv/client-c 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/client-c. 😃

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PD client now checks response headers in both GC safe-point methods. getGCState maps gRPC UNIMPLEMENTED failures to GRPCNotImplemented. Tests cover these cases and keyspace propagation.

Changes: PD GC client behavior

Layer / File(s) Summary
GC error handling and tests
src/pd/Client.cc, src/test/pd_gc_test.cc, src/test/CMakeLists.txt
Both safe-point methods throw InternalError when a successful RPC response has a non-OK header. getGCState maps UNIMPLEMENTED to GRPCNotImplemented before warning and leader-recheck handling; other failures retain the existing handling. The test service and test verify these behaviors, keyspace propagation, and safe-point results. The test is added to the kv_client_ut sources.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 293e9

The change lets callers tell an unsupported PD GC method apart from a transient failure. It also stops legacy safe-point calls from returning a default timestamp when PD reports a header error. The reported tests and the downstream integration run support the intended behavior, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes in the PR: distinguishing unsupported GC RPCs (gRPC UNIMPLEMENTED mapped to GRPCNotImplemented without the leader refresh) and propagating safe-point errors (legac…
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.
Full details: Title check

Explanation

The title names the two main changes in the PR: distinguishing unsupported GC RPCs (gRPC UNIMPLEMENTED mapped to GRPCNotImplemented without the leader refresh) and propagating safe-point errors (legacy getGCSafePoint and getGCSafePointV2 now throw InternalError on non-OK PD header errors). The raw summary, the test file, and the objectives all match these changes. The title is specific, concise, and free of file lists or vague terms.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef0af16e-69e6-4179-8818-1535113499e7
Commits

Reviewing files that changed from the base of the PR and between 89df87e and 293e94c.

Files selected for processing: 3

  • src/pd/Client.cc
  • src/test/CMakeLists.txt
  • src/test/pd_gc_test.cc

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant