Skip to content

Conversation

@lidezhu
Copy link
Collaborator

@lidezhu lidezhu commented Jan 7, 2026

What problem does this PR solve?

Issue Number: close #3951

What is changed and how it works?

  • Concurrency Refactor for GC Operations: The gcManager.run function has been significantly refactored to execute delete and compaction tasks in separate goroutines. This change allows these operations to run concurrently, preventing one from blocking the other and addressing a potential 'stuck problem' in the garbage collection process.
  • Optimized Delete Range Processing: A new function, mergeDeleteRanges, has been introduced to coalesce contiguous or overlapping delete ranges before processing. This optimization reduces the number of individual delete operations, improving efficiency, especially when the delete goroutine might be blocked for extended periods.
  • Write-Ahead Logging (WAL) Enabled: Write-Ahead Logging has been enabled for the underlying Pebble databases used by both the event store and schema store. Previously disabled, enabling WAL enhances data durability and consistency, providing better recovery capabilities in case of system failures.
  • Enhanced Logging and Metrics: Detailed logging for GC delete range progress has been added, providing insights into batch counts, deleted range counts, average ranges per batch, and batch durations. Additionally, a new metric, EventStoreDeleteRangeFetchedCount, has been introduced to track the number of delete range items fetched before coalescing, offering a clearer view of GC activity.

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

Summary of Changes

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!

This pull request addresses a potential 'stuck problem' within the event store's garbage collection mechanism by improving concurrency and data durability. It refactors the GC manager to allow deletion and compaction tasks to run independently, preventing mutual blocking. Additionally, it enables Write-Ahead Logging for the underlying Pebble databases, enhancing data consistency and recovery capabilities.

Highlights

  • Concurrency Refactor: The gcManager.run function has been refactored to execute the delete and compact operations in separate goroutines. This change prevents one operation from blocking the other, addressing a potential 'stuck problem' within the garbage collection process.
  • Enhanced Logging for GC: Detailed logging for GC delete range progress has been introduced, providing insights into batch counts, deleted range counts, average ranges per batch, and batch durations. Compaction logging also now includes the operation's duration.
  • Write-Ahead Logging Enabled: Write-Ahead Logging (WAL) has been enabled for the Pebble databases used by both the event store and schema store. Previously, WAL was disabled, which could impact data durability and recovery. Enabling it improves the robustness of the system.

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

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 7, 2026
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 addresses a potential "stuck" issue within the eventstore's garbage collection manager by separating the deletion and compaction processes into distinct goroutines. This change prevents a slow operation in one task from impeding the other. The pull request also enhances system durability by enabling the Write-Ahead Log (WAL) for the underlying Pebble data stores. Additionally, it introduces more comprehensive logging for both deletion and compaction tasks, which will improve system observability. The proposed changes are sound and contribute to a more robust and transparent system. I have one suggestion to refactor the new logging logic to enhance its readability and maintainability.

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 7, 2026
@lidezhu
Copy link
Collaborator Author

lidezhu commented Jan 7, 2026

/gemini summary

@gemini-code-assist
Copy link

Summary of Changes

This pull request aims to resolve a potential 'stuck problem' within the event store's garbage collection mechanism by significantly enhancing its robustness and efficiency. It achieves this by introducing concurrent execution for deletion and compaction tasks, optimizing delete operations through intelligent range coalescing, and bolstering data durability by enabling Write-Ahead Logging for the underlying Pebble databases. These changes collectively improve the stability and performance of the event store's garbage collection.

Highlights

  • Concurrency Refactor for GC Operations: The gcManager.run function has been significantly refactored to execute delete and compaction tasks in separate goroutines. This change allows these operations to run concurrently, preventing one from blocking the other and addressing a potential 'stuck problem' in the garbage collection process.
  • Optimized Delete Range Processing: A new function, mergeDeleteRanges, has been introduced to coalesce contiguous or overlapping delete ranges before processing. This optimization reduces the number of individual delete operations, improving efficiency, especially when the delete goroutine might be blocked for extended periods.
  • Write-Ahead Logging (WAL) Enabled: Write-Ahead Logging has been enabled for the underlying Pebble databases used by both the event store and schema store. Previously disabled, enabling WAL enhances data durability and consistency, providing better recovery capabilities in case of system failures.
  • Enhanced Logging and Metrics: Detailed logging for GC delete range progress has been added, providing insights into batch counts, deleted range counts, average ranges per batch, and batch durations. Additionally, a new metric, EventStoreDeleteRangeFetchedCount, has been introduced to track the number of delete range items fetched before coalescing, offering a clearer view of GC activity.

🧠 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/gc.go
    • Refactored gcManager.run to use separate goroutines for delete and compact operations, improving concurrency.
    • Added mergeDeleteRanges function to coalesce contiguous or overlapping delete ranges, reducing redundant operations.
    • Introduced detailed logging for delete range progress, including batch statistics and durations.
    • Added sort package import.
  • logservice/eventstore/gc_test.go
    • Added comprehensive unit tests for the new mergeDeleteRanges function, covering various scenarios including overlapping, contiguous, and non-overlapping ranges, and fast-path checks.
  • logservice/eventstore/pebble.go
    • Changed DisableWAL option from true to false in newPebbleOptions, enabling Write-Ahead Logging for the event store's Pebble database.
  • logservice/schemastore/persist_storage.go
    • Changed DisableWAL option from true to false in openDB, enabling Write-Ahead Logging for the schema store's Pebble database.
  • pkg/metrics/event_store.go
    • Updated the help text for EventStoreDeleteRangeCount to clarify it tracks operations after coalescing.
    • Added a new Prometheus counter, EventStoreDeleteRangeFetchedCount, to track the number of delete range items fetched before coalescing.
    • Registered the new EventStoreDeleteRangeFetchedCount metric.
Activity
  • The ti-chi-bot[bot] posted an APPROVALNOTIFIER comment, indicating the PR is not yet approved and suggesting sdojjy for approval.
  • The gemini-code-assist[bot] provided an initial summary of changes and highlights for the pull request.
  • The ti-chi-bot[bot] posted a FORMAT CHECKER NOTIFICATION regarding a missing linked issue number in the PR body.
  • The author lidezhu requested a /gemini summary.
  • The gemini-code-assist[bot] provided a review comment suggesting a simplification for the logDeleteRangeStats function, proposing a refactored version for improved readability and maintainability.

@lidezhu lidezhu changed the title eventstore: fix potential stuck problem eventstore: improve GC robustness and observability Jan 7, 2026
@flowbehappy flowbehappy self-requested a review January 13, 2026 07:27
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 13, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flowbehappy

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:

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
Copy link

ti-chi-bot bot commented Jan 13, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-13 07:27:50.573111969 +0000 UTC m=+342514.634976891: ☑️ agreed by flowbehappy.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compact range stuck

3 participants