Skip to content

Conversation

@wlwilliamx
Copy link
Collaborator

@wlwilliamx wlwilliamx commented Jan 23, 2026

What problem does this PR solve?

Issue Number: close #4056

What is changed and how it works?

  • Introduce EventsGroup.ResolveInto to copy out resolved events and clear the resolved prefix pointers before reslicing, avoiding Go GC retention of already-flushed DMLEvents.
  • Switch kafka-consumer / pulsar-consumer to use ResolveInto when flushing by watermark or before executing DDL.
  • Downgrade several high-frequency per-event logs from INFO/WARN to DEBUG to reduce log flooding under heavy workloads.
  • Add unit tests for ResolveInto to ensure correctness and prevent pointer-retention regressions.

Check List

Tests

  • Unit test

Questions

Will it cause performance regression or break compatibility?

No expected compatibility impact. The additional clear(...) is O(n) over resolved events and happens on the flush path; it prevents unbounded memory growth and improves stability under long-running workloads.

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

No.

Release note

Fix a memory retention issue in kafka-consumer/pulsar-consumer that could cause unbounded memory growth and OOM under long-running workloads.

@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 Jan 23, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @wlwilliamx, 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 addresses a critical memory retention issue within the Kafka and Pulsar consumers, which could lead to unbounded memory growth and potential Out-Of-Memory (OOM) errors in long-running workloads. The core solution involves a new ResolveInto method that ensures already-processed DML events are properly dereferenced, allowing Go's garbage collector to reclaim memory efficiently. Additionally, it refines logging levels to reduce noise under heavy system load, improving overall system stability and performance.

Highlights

  • Memory Retention Fix: Introduced EventsGroup.ResolveInto to prevent Go GC memory retention of DMLEvents by copying resolved events to a destination slice and then explicitly clearing the pointers in the group's internal slice.
  • Consumer Integration: Updated both Kafka and Pulsar consumers to utilize the new ResolveInto method when flushing events by watermark or before DDL execution, ensuring proper memory management.
  • Logging Optimization: Reduced log verbosity by downgrading several high-frequency INFO/WARN level log messages to DEBUG level across consumer components.
  • Unit Testing: Added comprehensive unit tests for EventsGroup.ResolveInto to ensure its correctness, validate pointer clearing, and prevent future memory retention regressions.

🧠 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 effectively addresses a memory retention issue in the Kafka and Pulsar consumers by introducing a new EventsGroup.ResolveInto method. This method correctly copies out resolved events and clears the pointers in the backing array, preventing the Go garbage collector from retaining flushed DMLEvent objects. The changes are cleanly applied to both kafka-consumer and pulsar-consumer.

Additionally, the PR includes several beneficial log level reductions from INFO/WARN to DEBUG for high-frequency operations, which will help reduce log volume and improve performance under heavy workloads.

The new ResolveInto function is well-documented, and the accompanying unit tests are thorough, covering main functionality and edge cases, ensuring the correctness of the fix and preventing future regressions.

Overall, this is a high-quality contribution that improves the stability and performance of the consumers.

@wlwilliamx
Copy link
Collaborator Author

/test all

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

ti-chi-bot bot commented Jan 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tenfyzhong, wk989898

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 [tenfyzhong,wk989898]

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 30, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 30, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-30 10:34:49.945565707 +0000 UTC m=+1354117.559522553: ☑️ agreed by tenfyzhong.
  • 2026-01-30 11:06:45.093596741 +0000 UTC m=+1356032.707553617: ☑️ agreed by wk989898.

@wlwilliamx wlwilliamx merged commit 46d0546 into pingcap:master Jan 30, 2026
19 checks passed
lidezhu pushed a commit that referenced this pull request Jan 31, 2026
* consumer: fix EventsGroup memory retention

* add copyright
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.

Kafka consumer OOM due to memory retention in util.EventsGroup.Resolve

3 participants