Skip to content

Conversation

@wk989898
Copy link
Collaborator

@wk989898 wk989898 commented Dec 31, 2025

What problem does this PR solve?

Issue Number: close #3784

What is changed and how it works?

  • Index File-Based DML Path Parsing: The storage consumer now determines DML file indices by first identifying and reading a dedicated '.index' file. This index file contains the actual DML file name, from which the numeric index is then extracted.
  • Refactored File Index Extraction: The logic for extracting file indices from DML file names has been refactored into a new, public utility function FetchIndexFromFileName. This function utilizes regular expressions for more robust and flexible parsing of the index from the file name string.
  • Dedicated Index Path Parsing: The ParseDMLFilePath function has been renamed to ParseIndexFilePath and its responsibility narrowed. It now specifically parses the metadata (such as schema, table, version, partition, date, and dispatcher ID) from the path of an index file, rather than attempting to extract the DML file index directly from it.

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?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 31, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @wk989898, 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 significantly refactors how the storage consumer identifies and processes DML (Data Manipulation Language) files. Instead of directly parsing the DML file path to extract its index, the system now relies on a separate '.index' file. This new workflow involves reading the content of the '.index' file to retrieve the corresponding DML file name, and then using a newly introduced, regex-based parsing utility to extract the DML file's numeric index. This change aims to enhance the flexibility and reliability of DML file path resolution within the storage consumer component.

Highlights

  • Index File-Based DML Path Parsing: The storage consumer now determines DML file indices by first identifying and reading a dedicated '.index' file. This index file contains the actual DML file name, from which the numeric index is then extracted.
  • Refactored File Index Extraction: The logic for extracting file indices from DML file names has been refactored into a new, public utility function FetchIndexFromFileName. This function utilizes regular expressions for more robust and flexible parsing of the index from the file name string.
  • Dedicated Index Path Parsing: The ParseDMLFilePath function has been renamed to ParseIndexFilePath and its responsibility narrowed. It now specifically parses the metadata (such as schema, table, version, partition, date, and dispatcher ID) from the path of an index file, rather than attempting to extract the DML file index directly from it.

🧠 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 correctly refactors the DML file path parsing logic to use index files, which is a good architectural improvement. The implementation is mostly solid, but I've identified a couple of performance concerns related to repeated regular expression compilation in potentially hot paths. I've also noted a minor inconsistency in error handling. Addressing these points will improve the performance and maintainability of the code.

Comment on lines +402 to +407
pathRE, err := regexp.Compile(`CDC(?:_(\w+)_)?(\d+).\w+`)
if err != nil {
return 0, err
}

return fileIdx, nil
matches := pathRE.FindStringSubmatch(fileName)

Choose a reason for hiding this comment

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

high

This regular expression is compiled on every function call, which can be inefficient if this function is on a hot path. It's better to compile it once at the package level using regexp.MustCompile and reuse the compiled object.

For example, you can define a package-level variable:

var fileNameRe = regexp.MustCompile(`CDC(?:_(\w+)_)?(\d+).\w+`)

And then use fileNameRe in this function.

Additionally, the error message on line 409 (cannot match dml path pattern) could be more precise, for instance: cannot match dml file name pattern.

Suggested change
pathRE, err := regexp.Compile(`CDC(?:_(\w+)_)?(\d+).\w+`)
if err != nil {
return 0, err
}
return fileIdx, nil
matches := pathRE.FindStringSubmatch(fileName)
matches := fileNameRe.FindStringSubmatch(fileName)

Comment on lines 131 to 134
pathRE, err := regexp.Compile(str)
if err != nil {
return nil, err
return "", err
}

Choose a reason for hiding this comment

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

high

This regular expression is compiled on every function call. Since dateSeparator has a small, fixed set of possible values, you can pre-compile the regex for each value and store them in a package-level map to avoid repeated compilation. This will improve performance, especially if this function is called frequently.

fileName := strings.TrimSuffix(string(data), "\n")
fileIdx, err := cloudstorage.FetchIndexFromFileName(fileName, c.fileExtension)
if err != nil {
return err

Choose a reason for hiding this comment

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

medium

For consistency with the error handling in the rest of this function and to provide better debugging information with stack traces, it's recommended to wrap the returned error with errors.Trace().

Suggested change
return err
return errors.Trace(err)

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 6, 2026

/test all

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 6, 2026
@ti-chi-bot ti-chi-bot bot added the lgtm label Jan 7, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 7, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, hongyunyan

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [3AceShowHand,hongyunyan]

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jan 7, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 7, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-06 04:47:43.520255243 +0000 UTC m=+677619.338563665: ☑️ agreed by hongyunyan.
  • 2026-01-07 03:47:00.994080538 +0000 UTC m=+760376.812388980: ☑️ agreed by 3AceShowHand.

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 7, 2026

/retest

6 similar comments
@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 7, 2026

/retest

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 8, 2026

/retest

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 8, 2026

/retest

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 8, 2026

/retest

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 8, 2026

/retest

@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 8, 2026

/retest

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

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

storage consumer lost some dml events

3 participants