Skip to content

logcoordinator: improve log#4206

Open
lidezhu wants to merge 2 commits intomasterfrom
ldz/fix-resign-log-coordinator
Open

logcoordinator: improve log#4206
lidezhu wants to merge 2 commits intomasterfrom
ldz/fix-resign-log-coordinator

Conversation

@lidezhu
Copy link
Collaborator

@lidezhu lidezhu commented Feb 13, 2026

What problem does this PR solve?

Issue Number: ref #2751

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

  • Bug Fixes

    • Improved resilience of log-coordinator resignation so campaigns no longer fail on resignation timeouts or soft errors.
  • New Features

    • Capture and surface the log-coordinator revision/version in campaign and exit logs for better observability.
  • Tests

    • Added unit tests covering revision retrieval and resignation edge cases.
  • Chores

    • Added supporting mocks and client API to enable revision retrieval in tests and runtime.

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

ti-chi-bot bot commented Feb 13, 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 hicqu 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 @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 enhances the stability and correctness of the log coordinator's resignation process. The changes ensure that the system handles server shutdown and resignation timeouts more gracefully, preventing potential issues during critical operational phases. The modifications improve the robustness of the election mechanism by refining how resignation attempts are managed and how errors are propagated.

Highlights

  • Log Coordinator Resignation Logic: Refactored the campaignLogCoordinator function to correctly call resignLogCoordinator and adjusted its error handling to prevent premature exits when the server is stopping.
  • Improved Resignation Error Handling: Modified the resignLogCoordinator function to use defer cancel() for context management and refined the error handling for resignation timeouts, ensuring that a timeout during resignation is logged as a warning but does not prevent the process from continuing.

🧠 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
  • server/module_election.go
    • Updated the call from e.resign(ctx) to e.resignLogCoordinator() within the campaignLogCoordinator function.
    • Adjusted the error return logic in campaignLogCoordinator when the server is stopping and resignation fails, to allow the process to continue.
    • Introduced defer cancel() in resignLogCoordinator to ensure context cancellation.
    • Modified error logging and return behavior in resignLogCoordinator for context.DeadlineExceeded errors, logging them as warnings and returning nil.
Activity
  • No human activity has been recorded on 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Adds retrieval of log coordinator revision from etcd and updates campaign resignation behavior to log and return nil on resignation timeouts/failures; includes interface, client, mock, and test additions for the new revision lookup.

Changes

Cohort / File(s) Summary
Election logic
server/module_election.go
Adjusts log-coordinator resignation flow: use resignLogCoordinator() with defer cancel(), treat resignation timeouts/failures as non-fatal (log and return nil), include logCoordinatorVersion in logs, and change some log levels.
Etcd owner API & impl
pkg/etcd/etcd.go
Adds OwnerCaptureInfoClient.GetLogCoordinatorRevision(ctx, captureID) (int64, error) and implements it in CDCEtcdClientImpl to read LogCoordinatorKey and validate ownership, returning the key's ModRevision on success.
Etcd mocks
pkg/etcd/etcd_mock.go
Adds gomock methods/recorders for GetLogCoordinatorRevision to mock owner capture info client and CDC etcd client.
Etcd tests
pkg/etcd/etcd_test.go
Adds TestCDCEtcdClientImpl_GetLogCoordinatorRevision covering leader fetch error, not found, not owner, and success cases.

Sequence Diagram(s)

sequenceDiagram
    participant Campaign as "Campaign Manager"
    participant Etcd as "Etcd (OwnerCaptureInfoClient)"
    participant LogCoord as "Log Coordinator Process"

    Campaign->>Etcd: GetLogCoordinatorRevision(captureID)
    Etcd-->>Campaign: (modRevision or error)
    Campaign->>LogCoord: start campaign (include revision)
    LogCoord-->>Campaign: campaign result (success/error)
    Campaign->>LogCoord: resign (with 5s timeout)
    alt resign timeout or failure
        LogCoord-->>Campaign: timeout/error (logged, treated as nil)
    else successful resign
        LogCoord-->>Campaign: success
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped to check the log's old mark,
Found revisions hidden in the dark,
I eased resigns with kinder cheer,
Logs tell tales, no faults to fear,
The burrow hums — campaigns stay clear.

🚥 Pre-merge checks | ❌ 4
❌ Failed checks (3 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is mostly a template with placeholders. While it includes an issue reference (ref #2751), the 'What is changed and how it works?' section is empty, and the checklist/questions/release note sections lack substantive content. Complete the description by filling in the 'What is changed and how it works?' section with implementation details, answer the questions about performance/compatibility/documentation, and provide a release note or 'None' if not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (7 files):

⚔️ deployments/kafka-consumer.Dockerfile (content)
⚔️ logservice/eventstore/event_store.go (content)
⚔️ pkg/etcd/etcd.go (content)
⚔️ pkg/etcd/etcd_mock.go (content)
⚔️ pkg/etcd/etcd_test.go (content)
⚔️ server/module_election.go (content)
⚔️ tests/integration_tests/ddl_wait/run.sh (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
Title check ❓ Inconclusive The title 'logcoordinator: improve log' is vague and does not clearly convey the specific changes made, using the generic term 'improve' without indicating what was actually improved. Revise the title to be more specific and descriptive, such as 'logcoordinator: handle resignation timeouts and track log coordinator version' to better reflect the actual changes.

✏️ 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 ldz/fix-resign-log-coordinator
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch ldz/fix-resign-log-coordinator
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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 fixes a bug in the log coordinator's resign logic. The changes correctly replace a generic resign call with the specific resignLogCoordinator function and address incorrect error handling and logging within it. The logic for handling resign failures during server shutdown is also improved for clarity. My review includes a suggestion to remove a redundant log message, which will make the error handling cleaner and more consistent with the existing codebase.

Comment on lines +290 to +292
log.Info("log coordinator resign failed",
zap.String("nodeID", nodeID), zap.Error(resignErr))
return errors.Trace(resignErr)

Choose a reason for hiding this comment

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

medium

This log message is redundant. The primary caller of resignLogCoordinator in campaignLogCoordinator (line 231) already logs a WARN message when this function returns an error. To avoid duplicate logs and to keep the function's responsibility focused on the resign action, it's better to remove this log.Info call and just return the error. This change would also align resignLogCoordinator with the pattern used in the resign function, which does not perform logging itself.

return errors.Trace(resignErr)

@lidezhu lidezhu changed the title logcoordinator: fix resign logcoordinator: improve log Feb 13, 2026
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2026
Copy link
Contributor

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/module_election.go (1)

250-259: ⚠️ Potential issue | 🟡 Minor

Original co.Run error is lost when resignLogCoordinator fails.

On line 253, if resignLogCoordinator() returns an error, that resign error is returned immediately via errors.Trace(resignErr), but the original err from co.Run(ctx) (which triggered the resign) is never logged. Consider logging the original error before returning the resign error.

Proposed fix
 		if err != nil && !errors.Is(err, context.Canceled) {
 			if !errors.ErrNotOwner.Equal(err) {
 				if resignErr := e.resignLogCoordinator(); resignErr != nil {
+					log.Warn("log coordinator resign failed after run error",
+						zap.String("nodeID", nodeID),
+						zap.Int64("logCoordinatorVersion", logCoordinatorVersion),
+						zap.Error(err))
 					return errors.Trace(resignErr)
 				}
 			}
🧹 Nitpick comments (2)
pkg/etcd/etcd.go (1)

604-620: Reusing ErrOwnerNotFound / ErrNotOwner for a log coordinator role is semantically misleading.

Lines 613 and 617 return ErrOwnerNotFound and ErrNotOwner respectively, but this method checks log coordinator ownership, not the coordinator/owner role. The caller in module_election.go (line 251) checks errors.ErrNotOwner.Equal(err) to decide whether to resign, so reusing these errors works functionally, but it conflates two distinct election roles in diagnostics and error messages.

Consider introducing ErrLogCoordinatorNotFound and ErrNotLogCoordinator for clarity, or at minimum add a comment explaining why the owner errors are intentionally reused here.

pkg/etcd/etcd_test.go (1)

280-291: Missing defer ctrl.Finish() in subtests — inconsistent with existing tests.

The existing TestCDCEtcdClientImpl_GetChangefeedInfoAndStatus (line 257) explicitly calls defer ctrl.Finish(). Each subtest here creates a gomock.Controller but omits the deferred Finish(). While gomock v1.5+ auto-registers cleanup, being consistent with the rest of the file avoids confusion.

Add `defer ctrl.Finish()` after each `gomock.NewController` call
 	t.Run("get leader failed", func(t *testing.T) {
 		ctrl := gomock.NewController(t)
+		defer ctrl.Finish()
 		client := NewMockClient(ctrl)

Apply similarly for the other three subtests.

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

1 participant