Skip to content

Conversation

@tenfyzhong
Copy link
Collaborator

@tenfyzhong tenfyzhong commented Dec 30, 2025

What problem does this PR solve?

Issue Number: close #3914

What is changed and how it works?

The changes in this PR primarily involve refactoring the PD client usage to support both the classic and next-gen PD clients through build tags.

Create a dedicated go.mod for next-gen mode.

Here's a breakdown of the key changes:

  • Introduced pkg/pdtype: This new package provides an abstraction layer for PD client functionalities. It defines interfaces and implementations for both classic and next-generation PD clients.
  • Conditional Compilation: Build tags (!nextgen and nextgen) are used to conditionally compile the appropriate PD client implementation based on the build environment.
  • Refactored PD Client Usage: All existing usages of the PD client have been updated to use the new abstraction layer in pkg/pdtype. This ensures that the code remains consistent regardless of the PD client version.
  • Makefile and Go Module Updates: The Makefile and go.mod files have been updated to include the necessary dependencies and build configurations for the next-generation PD client.
  • API Changes: Minor API changes were made in pkg/txnutil/gc and pkg/common to align with the new PD client abstraction. Specifically, SetServiceGCSafepoint, GetServiceGCSafepoint, RemoveServiceGCSafepoint, and KeyspaceOfStorage now correctly handle keyspace information.
  • DDL Handler Updates: The DDL handlers in logservice/schemastore have been updated to use the new tidbtype.CIStr and tidbtype.NewCIStr for table names, ensuring compatibility with the next-generation PD client.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?

No, this change is designed to be backward compatible and should not introduce performance regressions. The abstraction layer ensures that the behavior remains consistent with the classic PD client.

Do you need to update user documentation, design documentation or monitoring documentation?

No, user-facing documentation does not need to be updated as this is an internal refactoring. Design documentation may benefit from an update to reflect the new PD client abstraction.

Release note

NONE

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. labels Dec 30, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 30, 2025

[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 3aceshowhand 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 30, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @tenfyzhong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring effort to unify the codebase for compatibility with both classic and next-generation PD clients. By introducing new abstraction layers and leveraging Go build tags, the changes streamline PD client interactions and TiDB type handling. This ensures the system can seamlessly operate across different PD environments while maintaining backward compatibility and improving overall code maintainability.

Highlights

  • PD Client Abstraction: Introduced a new pkg/pdtype package to provide an abstraction layer for PD client functionalities, supporting both classic and next-generation PD clients through a unified interface.
  • Conditional Compilation: Implemented build tags (!nextgen and nextgen) across the codebase to enable conditional compilation, allowing the system to adapt to different PD client implementations based on the build environment.
  • Unified GC Safepoint Management: Refactored the garbage collection (GC) safepoint and barrier update logic, consolidating TryUpdateGCSafePoint to handle keyspace-aware operations and removing redundant methods like TryUpdateKeyspaceGCBarrier.
  • TiDB Type Abstraction: Created pkg/tidbtype to abstract TiDB-specific types such as CIStr, NewCIStr, IndexTypeBtree, SetSchemaLease, and DefMaxAllowedPacket, enhancing compatibility and modularity.
  • Dedicated Next-Gen Go Module: A nextgen.go.mod file was added, along with corresponding Makefile updates, to manage dependencies specifically for next-generation builds, ensuring proper module resolution.
  • Dependency Updates: Updated various Go module dependencies to newer versions, including gin, mailru/easyjson, pingcap/kvproto, pingcap/tidb, pingcap/tidb-dashboard, pingcap/tidb/pkg/parser, pingcap/tiflow, tikv/client-go/v2, tikv/pd, tikv/pd/client, and golang.org/x/* packages.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 is a significant refactoring to support both classic and next-gen PD clients using build tags. The changes are extensive and well-structured, introducing an abstraction layer (pkg/pdtype, etc.) to handle conditional compilation. The overall approach is sound and the implementation appears correct and consistent with the goal of unifying the branches. I have one suggestion for the Makefile to improve code clarity and maintainability.

@tenfyzhong
Copy link
Collaborator Author

/test all

@tenfyzhong
Copy link
Collaborator Author

/test next-gen

1. Use a dedicated go.mod for nextgen mode.
2. Use the 8.5 branch as the default dependency.

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Rename `UnifyGetServiceGCSafepoint` to `GetServiceGCSafepoint`
- Rename `UnifyDeleteGcSafepoint` to `RemoveServiceGCSafepoint`
- Update all callers to use new function names

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Extract TiDB-specific constants and functions from `common` package to new `tidbtype` package
- Create separate files for classic and nextgen builds to handle different TiDB versions
- Update all imports to use new package location for `JobTableID`, `JobHistoryID`, and `ValidateKeyspace`
- Maintain backward compatibility through package restructuring

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Migrate from `github.com/pingcap/tidb/pkg/parser/ast` to internal `github.com/pingcap/ticdc/pkg/tidbtype` for CIStr
- Replace `github.com/pingcap/tidb/pkg/sessionctx/vardef` with internal tidbtype for DefMaxAllowedPacket
- Update PD client method signatures to use internal types
- Add nextgen-specific initialization files to handle conditional builds
- Fix test expectations for row key encoding changes

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Update expected value in TestRowKey to match new behavior
- Add TODO comment for follow-up verification of expected value difference

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Correct package name from 'common' to 'simple' in simple codec test
- Correct package name from 'common' to 'mysql' in MySQL sink test
- Add missing import for kerneltype in all three test files

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Include `-modfile=nextgen.go.mod` in unit_test_in_verify_ci_next_gen rule
- Include `-modfile=nextgen.go.mod` in unit_test_pkg_next_gen rule

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Split GetServiceDiscovery method into separate files for classic and nextgen builds
- Use `!nextgen` build tag for classic PD client interface
- Use `nextgen` build tag for new PD service discovery interface
- Remove generic implementation from main test file to avoid compilation issues

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Sort imports to maintain consistent ordering across test files
- Move tidbtype import before util import in multiple test files

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Add separate tidy checks for classic and nextgen go.mod files
- Use `-modfile` flag to target specific module files
- Improve error handling and output messages for both modules
- Maintain backward compatibility with existing tidy workflow

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Temporarily rename *_nextgen.go and *_nextgen_test.go files to .bak extensions when tidying classic go.mod
- Temporarily rename *_classic.go and *_classic_test.go files when tidying nextgen go.mod
- Temporarily swap go.mod/go.sum with nextgen.go.mod/nextgen.go.sum when tidying nextgen modules
- Restore all files to original names after tidying operations
- This prevents go mod tidy from parsing files meant for the other module configuration

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Remove separate check for classic go.mod/go.sum files
- Consolidate tidy check to include all go.mod and go.sum files
- Update error message to point to `make tidy` command

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Promote github.com/pingcap/sysutil from indirect to direct dependency
- Update both go.mod and nextgen.go.mod files
- Remove sysutil from indirect dependencies section

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Extract file hiding/restoration logic into reusable functions
- Add switch_to_nextgen and restore_classic functions for go.mod management
- Implement cleanup trap to ensure proper file restoration on exit
- Fix backtick escaping in error message
- Improve script readability and maintainability

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Update column and index name initialization in test cases to use tidbtype.CIStr instead of ast.CIStr
- Maintain test functionality while aligning with type usage patterns

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Merge separate `-modfile` flag into same line as other test flags in `unit_test_in_verify_ci_next_gen` target
- Combine `-modfile` flag with coverage arguments in `unit_test_pkg_next_gen` target

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Change single quotes to double quotes in awk command to ensure proper shell interpretation
- This resolves potential issues with command execution in make targets

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Remove redundant -modfile flag duplication in conditional branches
- Add -modfile flag once after conditional logic for cleaner code

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Move parallel test flag `P` definition closer to its usage context
- Refactor `TEST_FLAG` variable to include race detection and parallel execution parameters
- Consolidate `GOTEST` command by using expanded `TEST_FLAG` variable
- Increase test timeout from 300s to 1200s for unit tests
- Simplify next-gen test targets by reusing existing ones with `NEXT_GEN=1`
- Remove redundant test command duplication for next-gen configurations

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Changed gotestsum -p parameter from 3 to 8 for faster test execution

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
@tenfyzhong
Copy link
Collaborator Author

/test all

@tenfyzhong
Copy link
Collaborator Author

/test next-gen

@tenfyzhong
Copy link
Collaborator Author

/retest

…lity

- Update import from `github.com/pingcap/tidb/pkg/parser/ast` to `github.com/pingcap/ticdc/pkg/tidbtype`
- Replace `ast.NewCIStr()` with `tidbtype.NewCIStr()` for creating case-insensitive strings

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
@tenfyzhong
Copy link
Collaborator Author

/test all

@tenfyzhong
Copy link
Collaborator Author

/test next-gen

- Change `--tags intest` to `-tags intest` for correct go test flag syntax
- Maintain compatibility with NEXT_GEN build option

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
- Replace `pd.NewClientWithContext` with `pdtype.NewClientWithContext` in resolve lock test
- Add conditional build tag support for nextgen in test runner script

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
@tenfyzhong
Copy link
Collaborator Author

/test all

@tenfyzhong
Copy link
Collaborator Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 5, 2026
@tenfyzhong
Copy link
Collaborator Author

/retest

@tenfyzhong
Copy link
Collaborator Author

/test next-gen

Add GO_RUN_TAGS environment variable to test_prepare that is set to
'-tags=nextgen' when NEXT_GEN=1, otherwise empty. This allows all
integration test scripts to use a single 'go run $GO_RUN_TAGS ...'
command instead of duplicated if-else blocks for NEXT_GEN handling.

This simplifies the test scripts and makes it easier to add new tests
that need to support both classic and nextgen builds.

Signed-off-by: tenfyzhong <tenfy@tenfy.cn>
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 5, 2026

@tenfyzhong: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cdc-mysql-integration-heavy 13adcac link true /test pull-cdc-mysql-integration-heavy
pull-cdc-pulsar-integration-light 13adcac link false /test pull-cdc-pulsar-integration-light
pull-error-log-review 447c13f link true /test pull-error-log-review

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify branches 8.5 and master

1 participant