Skip to content

Conversation

@wk989898
Copy link
Collaborator

@wk989898 wk989898 commented Feb 9, 2026

What problem does this PR solve?

Issue Number: close #4142

What is changed and how it works?

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`.

Summary by CodeRabbit

  • Refactor
    • Optimized internal subscription removal logic to improve code maintainability.

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Feb 9, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 9, 2026

[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 flowbehappy 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

@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 refactors the method used to remove subscription states within the event store. By adopting the slices.Delete function, it aims to enhance code clarity and leverage standard library utilities for common slice manipulation tasks, improving maintainability and reducing potential for off-by-one errors.

Highlights

  • Refactor Subscription Removal: The manual slice deletion logic for removing subscription states has been replaced with the more idiomatic and concise slices.Delete function.

🧠 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.

Changelog
  • logservice/eventstore/event_store.go
    • Replaced the manual slice deletion append(tableState.Subscriptions[:targetIndex], tableState.Subscriptions[targetIndex+1:]...) with slices.Delete(tableState.Subscriptions, targetIndex, targetIndex+1) for removing subscription states.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
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.

@ti-chi-bot ti-chi-bot bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 9, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

This PR refactors subscription removal logic in the event store by replacing manual slice manipulation with Go's standard slices.Delete helper function. The change maintains existing behavior while addressing a potential memory leak by ensuring proper cleanup of the subscriptions slice.

Changes

Cohort / File(s) Summary
Subscription Removal Refactoring
logservice/eventstore/event_store.go
Replaced manual slice splice with slices.Delete helper during SubscriptionChangeTypeRemove operations, improving slice cleanup and addressing memory leak concerns.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested labels

lgtm, approved

Suggested reviewers

  • asddongmen
  • lidezhu

Poem

🐰 A slice was leaking, oh what a sight,
Manual splicing made memory tight,
But slices.Delete comes to save the day,
Cleaner and safer in every way!
Hops away with glee 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provides the issue number but lacks implementation details explaining the memory leak, the fix, or test coverage. Add explanation of the memory leak issue, the refactoring changes made, and confirm which tests were included.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: refactoring subscription removal to use slices.Delete helper function.
Linked Issues check ✅ Passed The code change (replacing manual slice splice with slices.Delete) directly addresses the memory leak reported in issue #4142 by improving memory handling in subscription removal.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to refactoring subscription removal logic in event_store.go, directly related to addressing the memory leak issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wk989898-patch-7

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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 refactors the subscription removal logic in event_store.go to use the slices.Delete function, which is a good improvement for code readability. However, the slices package is not imported in the file, which will cause a compilation error. This critical issue needs to be addressed.

log.Panic("cannot find subscription state", zap.Uint64("subscriptionID", change.SubID))
}
tableState.Subscriptions = append(tableState.Subscriptions[:targetIndex], tableState.Subscriptions[targetIndex+1:]...)
tableState.Subscriptions = slices.Delete(tableState.Subscriptions, targetIndex, targetIndex+1)

Choose a reason for hiding this comment

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

critical

Using slices.Delete improves readability, which is a good refactoring. However, the slices package is not imported in this file, which will cause a compilation error. Please add "slices" to the import block to resolve this.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@logservice/eventstore/event_store.go`:
- Line 1492: The code calls slices.Delete on tableState.Subscriptions (line
using slices.Delete) but the "slices" package is not imported; add the standard
library import "slices" to the import block so the call to slices.Delete
compiles, ensuring the import is placed with other stdlib imports and not in a
separate grouped import.

log.Panic("cannot find subscription state", zap.Uint64("subscriptionID", change.SubID))
}
tableState.Subscriptions = append(tableState.Subscriptions[:targetIndex], tableState.Subscriptions[targetIndex+1:]...)
tableState.Subscriptions = slices.Delete(tableState.Subscriptions, targetIndex, targetIndex+1)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Check the import block and search for slices usage
head -50 logservice/eventstore/event_store.go | tail -35

# Also search for all slices usages
echo "---"
rg -n 'slices\.' logservice/eventstore/event_store.go

Repository: pingcap/ticdc

Length of output: 1172


Missing slices import — this won't compile.

slices.Delete is used at line 1492 but the "slices" package is not imported. Add "slices" to the standard library import group:

 import (
 	"bytes"
 	"context"
 	"fmt"
 	"math"
 	"os"
+	"slices"
 	"strconv"
 	"sync"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tableState.Subscriptions = slices.Delete(tableState.Subscriptions, targetIndex, targetIndex+1)
import (
"bytes"
"context"
"fmt"
"math"
"os"
"slices"
"strconv"
"sync"
// ... rest of imports
)
🤖 Prompt for AI Agents
In `@logservice/eventstore/event_store.go` at line 1492, The code calls
slices.Delete on tableState.Subscriptions (line using slices.Delete) but the
"slices" package is not imported; add the standard library import "slices" to
the import block so the call to slices.Delete compiles, ensuring the import is
placed with other stdlib imports and not in a separate grouped import.

Signed-off-by: wk989898 <nhsmwk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible memory leak in eventStore

1 participant