8000 puller: fix resolved ts calculation by lidezhu · Pull Request #1411 · pingcap/ticdc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

puller: fix resolved ts calculation #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 6, 2025
Merged

puller: fix resolved ts calculation #1411

merged 20 commits into from
Jun 6, 2025

Conversation

lidezhu
Copy link
Collaborator
@lidezhu lidezhu commented Jun 6, 2025

What problem does this PR solve?

Issue Number: close #1395 #1382

What is changed and how it works?

Use a new heap library and update heap when resolved ts changes every time.

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 do-not-merge/needs-linked-issue 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 Jun 6, 2025
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.

Hello @lidezhu, 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!

Summary of Changes

Hello! Gemini-code-assist has analyzed this pull request titled "puller: fix resolved ts calculation" authored by @lidezhu. Based on the provided title and the code changes, the primary intent of this PR appears to be to improve the correctness and robustness of how resolved timestamps are handled within the log puller and event store components. The changes introduce explicit checks and logging to identify potential issues with event timestamps being older than the current resolved timestamp, add filtering logic in the event store to prevent processing such events, and refactor the internal heap structure used for tracking resolved timestamps across different regions and ranges. This work seems crucial for ensuring data consistency and proper progress tracking in the changefeed process.

Highlights

  • Resolved Timestamp Validation and Logging: Introduced new warning logs and checks in regionEventHandler and subscriptionClient to detect scenarios where event commit timestamps are less than or equal to the region's resolved timestamp, or where a newly received resolved timestamp is less than the previously recorded one for a region. This helps in identifying potential issues with the timestamp flow.
  • Event Filtering in Event Store: Modified the eventStore to include the subscription's resolved timestamp when queuing events. Before writing events to the underlying Pebble DB, the code now explicitly filters out any events whose commit timestamp is strictly less than the resolved timestamp associated with the event batch. This prevents processing stale data.
  • Range Lock Heap Refactor: Replaced the standard library's container/heap implementation with a custom heap implementation (utils/heap) within the RangeLock component. This involved adding heap-specific fields and methods (heapIndex, SetHeapIndex, GetHeapIndex, LessThan) to the LockedRangeState struct and updating the RangeLock methods (NewRangeLock, UnlockRange, GetHeapMinTs, tryLockRange, and a new UpdateLockedRangeStateHeap) to correctly interact with the new heap structure.
  • Debug Information for Resolved TS: Added a debugInfo struct to the subscriptionClient to maintain a map tracking the latest resolved timestamp for each region within a subscription. This map is used by the new logging checks to compare incoming event timestamps and resolved timestamps against the last known values.

Changelog

Click here to see the changelog
  • logservice/eventstore/event_store.go
    • Added filterTs field to the eventWithCallback struct to carry the resolved timestamp.
    • Removed a warning log in consumeKVEvents that checked commitTs against resolvedTs.
    • Added the current resolvedTs as filterTs when pushing events to the event channel.
    • Implemented filtering logic in writeEvents to skip KVs with commitTs less than the event's filterTs before writing to Pebble DB.
  • logservice/logpuller/region_event_handler.go
    • Imported the math package.
    • Added a warning log in Handle if the minimum commitTs in the kvEventsCache is less than the new resolvedTs.
    • Added a warning log in handleEventEntries if a committed entry's CommitTs is less than or equal to the region's last resolvedTs.
    • Removed a commented-out line related to appending kvEvents.
    • Added a call to span.rangeLock.UpdateLockedRangeStateHeap in handleResolvedTs to update the heap when a region's resolvedTs changes.
  • logservice/logpuller/regionlock/range_ts_map.go
    • Imported the go.uber.org/zap package.
    • Added an info log in getMinTs when an unlocked range is found during the minimum timestamp calculation.
  • logservice/logpuller/regionlock/region_range_lock.go
    • Removed the import of container/heap.
    • Imported the custom github.com/pingcap/ticdc/utils/heap.
    • Added heapIndex, SetHeapIndex, GetHeapIndex, and LessThan methods to LockedRangeState to make it compatible with the custom heap.
    • Removed the old rangeLockEntryHeap type and its associated methods.
    • Replaced the rangeLockEntryHeap field in RangeLock with lockedRangeStateHeap using the new custom heap type.
    • Updated the heap initialization in NewRangeLock to use heap.NewHeap.
    • Updated the heap removal logic in UnlockRange to use l.lockedRangeStateHeap.Remove.
    • Added the UpdateLockedRangeStateHeap method to add or update a LockedRangeState in the heap.
    • Updated GetHeapMinTs to use l.lockedRangeStateHeap.PeekTop to get the minimum timestamp.
    • Updated the heap insertion logic in tryLockRange to use l.lockedRangeStateHeap.AddOrUpdate.
  • logservice/logpuller/regionlock/region_range_lock_test.go
    • Added a helper function updateLockedRangeResolvedTs to simplify updating a locked range's resolvedTs and the heap.
    • Updated TestRangeLockGetHeapMinTs to use the new helper function for setting resolved timestamps.
  • logservice/logpuller/subscription_client.go
    • Added a debugInfo struct with a mutex and resolvedTsMap to track region resolved timestamps per subscription.
    • Initialized the debugInfo.resolvedTsMap in NewSubscriptionClient.
    • Added debug logging within pushRegionEventToDS to warn about decreasing region resolvedTs or committed event commitTs less than or equal to the region's resolvedTs.
  • pkg/eventservice/event_broker.go
    • Removed a blank line in the doScan function.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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 primarily focuses on fixing the resolved timestamp calculation for event filtering in the puller, and refactors the heap implementation within the region lock mechanism. The core change involves introducing a filterTs to eventWithCallback, ensuring events are filtered against the resolved timestamp active at the time of their reception. The heap refactoring to a generic implementation is a good improvement for maintainability.

Overall, the changes look reasonable and address the intended fix. There are a couple of points to discuss, particularly a TODO comment and the new debug logging.

Summary of Findings

  • TODO for Filtering Logic: A TODO comment in eventstore/event_store.go questions whether events with commitTs == filterTs should be filtered. This needs clarification as it impacts event processing semantics.
  • Debug Logging Performance and Verbosity: New debug logging in logpuller/subscription_client.go might have performance implications due to locking and operations on a hot path. Its intended use (temporary debug vs. permanent diagnostic) and log levels should be confirmed.
  • Heap Refactoring: The refactoring of rangeLockEntryHeap in logpuller/regionlock/region_range_lock.go to use a generic heap (utils/heap.Heap) is a good improvement for code maintainability and reusability.
  • Resolved Timestamp Filtering Fix: The core logic of capturing resolvedTs as filterTs at event reception and using it for filtering in writeEvents appears to correctly address issues with resolved timestamp calculations for event filtering.
  • Potentially Noisy Logging (Not Commented Due to Severity Settings): In logservice/logpuller/regionlock/range_ts_map.go, getMinTs now includes log.Info("getMinTs with unlocked range", ...). This could be verbose if frequently triggered. This was not commented on directly due to the 'low' severity and review settings.

Merge Readiness

The pull request introduces a key fix for resolved timestamp calculation and a beneficial heap refactoring. Before merging, I recommend addressing the TODO comment regarding the filtering logic and clarifying the intent and potential impact of the new debug logging in subscription_client.go. Once these points are clarified or addressed, the PR should be in good shape for merging. As an AI assistant, I am not authorized to approve pull requests; please ensure further review and approval from team members.

Copy link
ti-chi-bot bot commented Jun 6, 2025

@gemini-code-assist[bot]: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

Code Review

This pull request primarily focuses on fixing the resolved timestamp calculation for event filtering in the puller, and refactors the heap implementation within the region lock mechanism. The core change involves introducing a filterTs to eventWithCallback, ensuring events are filtered against the resolved timestamp active at the time of their reception. The heap refactoring to a generic implementation is a good improvement for maintainability.

Overall, the changes look reasonable and address the intended fix. There are a couple of points to discuss, particularly a TODO comment and the new debug logging.

Summary of Findings

  • TODO for Filtering Logic: A TODO comment in eventstore/event_store.go questions whether events with commitTs == filterTs should be filtered. This needs clarification as it impacts event processing semantics.
  • Debug Logging Performance and Verbosity: New debug logging in logpuller/subscription_client.go might have performance implications due to locking and operations on a hot path. Its intended use (temporary debug vs. permanent diagnostic) and log levels should be confirmed.
  • Heap Refactoring: The refactoring of rangeLockEntryHeap in logpuller/regionlock/region_range_lock.go to use a generic heap (utils/heap.Heap) is a good improvement for code maintainability and reusability.
  • Resolved Timestamp Filtering Fix: The core logic of capturing resolvedTs as filterTs at event reception and using it for filtering in writeEvents appears to correctly address issues with resolved timestamp calculations for event filtering.
  • Potentially Noisy Logging (Not Commented Due to Severity Settings): In logservice/logpuller/regionlock/range_ts_map.go, getMinTs now includes log.Info("getMinTs with unlocked range", ...). This could be verbose if frequently triggered. This was not commented on directly due to the 'low' severity and review settings.

Merge Readiness

The pull request introduces a key fix for resolved timestamp calculation and a beneficial heap refactoring. Before merging, I recommend addressing the TODO comment regarding the filtering logic and clarifying the intent and potential impact of the new debug logging in subscription_client.go. Once these points are clarified or addressed, the PR should be in good shape for merging. As an AI assistant, I am not authorized to approve pull requests; please ensure further review and approval from team members.

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.

Copy link
ti-chi-bot bot commented Jun 6, 2025

@lidezhu: The following test 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-pulsar-integration-light 8fd4d84 link false /test pull-cdc-pulsar-integration-light

Full PR test history. Your PR dashboard.

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.

Copy link
ti-chi-bot bot commented Jun 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: asddongmen

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

The pull request process is described here

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

Copy link
ti-chi-bot bot commented Jun 6, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-06 10:38:18.732614398 +0000 UTC m=+5876.960929660: ☑️ agreed by asddongmen.

@ti-chi-bot ti-chi-bot bot merged commit ef77f82 into master Jun 6, 2025
14 of 15 checks passed
@ti-chi-bot ti-chi-bot bot deleted the ldz/fix-puller0604 branch June 6, 2025 10:45
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
3D6E
Development

Successfully merging this pull request may close these issues.

event store received kv with commitTs less than resolvedTs
2 participants
0