-
Notifications
You must be signed in to change notification settings - Fork 54
orchestrator: clear stale capture tombstones on re-register #4696
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
ti-chi-bot
merged 5 commits into
pingcap:master
from
hongyunyan:fix-4695-clear-stale-capture-tombstone
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9be5e80
fix: clear stale capture tombstones on re-register
hongyunyan f47b876
test: remove cluster id coupling from capture helpers
hongyunyan 08b58f9
test: stabilize coordinator scale-node coverage
hongyunyan 2d4dd69
test: register scale-node cleanup eagerly
hongyunyan dd85b61
fix: let node removal override finished move operators
hongyunyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2026 PingCAP, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package orchestrator | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/pingcap/ticdc/pkg/config" | ||
| "github.com/pingcap/ticdc/pkg/etcd" | ||
| "github.com/pingcap/ticdc/pkg/orchestrator/util" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGlobalReactorStateKeepsCaptureAfterReRegister(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| state := NewGlobalState(etcd.DefaultCDCClusterID, 0) | ||
| state.captureRemoveTTL = 10 | ||
|
|
||
| captureID := config.CaptureID("capture-1") | ||
| var removed []config.CaptureID | ||
| state.SetOnCaptureRemoved(func(id config.CaptureID) { | ||
| removed = append(removed, id) | ||
| }) | ||
|
|
||
| mustUpdateCapture(t, state, captureID, "127.0.0.1:8300") | ||
| mustDeleteCapture(t, state, captureID) | ||
| state.toRemoveCaptures[captureID] = time.Now().Add(-11 * time.Second) | ||
| mustUpdateCapture(t, state, captureID, "127.0.0.1:8301") | ||
|
|
||
| state.UpdatePendingChange() | ||
|
|
||
| require.Contains(t, state.Captures, captureID) | ||
| require.Equal(t, "127.0.0.1:8301", state.Captures[captureID].AdvertiseAddr) | ||
| require.Empty(t, removed) | ||
| require.NotContains(t, state.toRemoveCaptures, captureID) | ||
| } | ||
|
|
||
| func TestGlobalReactorStateRemovesCaptureAfterTombstoneExpires(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| state := NewGlobalState(etcd.DefaultCDCClusterID, 0) | ||
| state.captureRemoveTTL = 10 | ||
|
|
||
| captureID := config.CaptureID("capture-1") | ||
| var removed []config.CaptureID | ||
| state.SetOnCaptureRemoved(func(id config.CaptureID) { | ||
| removed = append(removed, id) | ||
| }) | ||
|
|
||
| mustUpdateCapture(t, state, captureID, "127.0.0.1:8300") | ||
| mustDeleteCapture(t, state, captureID) | ||
|
|
||
| state.UpdatePendingChange() | ||
| require.Contains(t, state.Captures, captureID) | ||
| require.Empty(t, removed) | ||
|
|
||
| state.toRemoveCaptures[captureID] = time.Now().Add(-11 * time.Second) | ||
| state.UpdatePendingChange() | ||
|
|
||
| require.NotContains(t, state.Captures, captureID) | ||
| require.Equal(t, []config.CaptureID{captureID}, removed) | ||
| require.NotContains(t, state.toRemoveCaptures, captureID) | ||
| } | ||
|
|
||
| func mustUpdateCapture( | ||
| t *testing.T, | ||
| state *GlobalReactorState, | ||
| captureID config.CaptureID, | ||
| advertiseAddr string, | ||
| ) { | ||
| t.Helper() | ||
|
|
||
| info := &config.CaptureInfo{ | ||
| ID: captureID, | ||
| AdvertiseAddr: advertiseAddr, | ||
| } | ||
| data, err := info.Marshal() | ||
| require.NoError(t, err) | ||
|
|
||
| err = state.Update(util.NewEtcdKey(etcd.GetEtcdKeyCaptureInfo(state.ClusterID, string(captureID))), data, false) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func mustDeleteCapture(t *testing.T, state *GlobalReactorState, captureID config.CaptureID) { | ||
| t.Helper() | ||
|
|
||
| err := state.Update(util.NewEtcdKey(etcd.GetEtcdKeyCaptureInfo(state.ClusterID, string(captureID))), nil, false) | ||
| require.NoError(t, err) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pingcap/ticdc
Length of output: 7895
Wait for the gRPC serve loop and track its errors.
stop()only waits onres.wg, butstartMaintainerNodeincrements that wait group once at line 737 while launching two goroutines: the outer function and the inner gRPC serve loop at line 744. This means cleanup can return before the serve loop exits. Additionally, ifgrpcServer.Serve(lis)fails unexpectedly beforemaintainerM.Run(ctx)completes, the error is swallowed andgrpcServer.Stop()is never called, leaving the serve goroutine hanging.♻️ Suggested change
func startMaintainerNode(ctx context.Context, node *node.Info, mc messaging.MessageCenter, nodeManager *watcher.NodeManager, lis net.Listener, ) *maintainNode { nodeManager.RegisterNodeChangeHandler(node.ID, mc.OnNodeChanges) ctx, cancel := context.WithCancel(ctx) maintainerM := NewMaintainerManager(mc) + var opts []grpc.ServerOption + grpcServer := grpc.NewServer(opts...) + mcs := messaging.NewMessageCenterServer(mc) + proto.RegisterMessageServiceServer(grpcServer, mcs) res := &maintainNode{ cancel: cancel, mc: mc, manager: maintainerM, } - res.wg.Add(1) + res.wg.Add(2) go func() { defer res.wg.Done() - var opts []grpc.ServerOption - grpcServer := grpc.NewServer(opts...) - mcs := messaging.NewMessageCenterServer(mc) - proto.RegisterMessageServiceServer(grpcServer, mcs) - go func() { - _ = grpcServer.Serve(lis) - }() + defer grpcServer.Stop() _ = maintainerM.Run(ctx) - grpcServer.Stop() + }() + go func() { + defer res.wg.Done() + if err := grpcServer.Serve(lis); err != nil && ctx.Err() == nil { + log.Warn("maintainer test grpc server exited unexpectedly", zap.Error(err)) + } }() return res }As per coding guidelines for
**/*_test.go: favor deterministic tests and usetestify/require.Also applies to: 732-749
🤖 Prompt for AI Agents