diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager.go b/downstreamadapter/dispatchermanager/dispatcher_manager.go index 089386ee1c..6d034f4260 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager.go @@ -121,6 +121,8 @@ type DispatcherManager struct { // Entries must be deleted on completion, otherwise future requests for the // same dispatcherID will be ignored. currentOperatorMap sync.Map // map[common.DispatcherID]SchedulerDispatcherRequest (in dispatcher manager, not heartbeatpb) + // mergeOperatorMap keeps in-flight merge requests so bootstrap can reconstruct merge operators after maintainer failover. + mergeOperatorMap sync.Map // map[mergedDispatcherID.String()]*heartbeatpb.MergeDispatcherRequest // schemaIDToDispatchers is shared in the DispatcherManager, // it store all the infos about schemaID->Dispatchers // Dispatchers may change the schemaID when meets some special events, such as rename ddl @@ -230,6 +232,7 @@ func NewDispatcherManager( ctx: ctx, dispatcherMap: newDispatcherMap[*dispatcher.EventDispatcher](), currentOperatorMap: sync.Map{}, + mergeOperatorMap: sync.Map{}, changefeedID: changefeedID, keyspaceID: keyspaceID, pdClock: pdClock, @@ -931,6 +934,7 @@ func (e *DispatcherManager) aggregateDispatcherHeartbeats(needCompleteStatus boo } } } + e.cleanupFinishedMergeOperators() e.metricCheckpointTs.Set(float64(message.Watermark.CheckpointTs)) e.metricResolvedTs.Set(float64(message.Watermark.ResolvedTs)) diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go b/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go new file mode 100644 index 0000000000..b2921c1b1f --- /dev/null +++ b/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go @@ -0,0 +1,150 @@ +// Copyright 2025 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 dispatchermanager + +import ( + "github.com/gogo/protobuf/proto" + "github.com/pingcap/log" + "github.com/pingcap/ticdc/downstreamadapter/dispatcher" + "github.com/pingcap/ticdc/heartbeatpb" + "github.com/pingcap/ticdc/pkg/common" + "go.uber.org/zap" +) + +// TrackMergeOperator records an in-flight merge request so bootstrap can restore it after maintainer failover. +func (e *DispatcherManager) TrackMergeOperator(req *heartbeatpb.MergeDispatcherRequest) { + if req == nil || req.MergedDispatcherID == nil { + return + } + mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + if mergedID.IsZero() { + log.Warn("ignore merge operator with invalid merged dispatcher ID", + zap.Stringer("changefeedID", e.changefeedID), + zap.Int64("mode", req.Mode)) + return + } + e.mergeOperatorMap.Store(mergedID.String(), proto.Clone(req).(*heartbeatpb.MergeDispatcherRequest)) +} + +// RemoveMergeOperator drops a persisted merge request that no longer needs bootstrap recovery. +func (e *DispatcherManager) RemoveMergeOperator(mergedDispatcherID common.DispatcherID) { + e.mergeOperatorMap.Delete(mergedDispatcherID.String()) +} + +// MaybeCleanupMergeOperator removes a persisted merge request when the merged dispatcher is already complete or gone. +func (e *DispatcherManager) MaybeCleanupMergeOperator(req *heartbeatpb.MergeDispatcherRequest) { + if req == nil || req.MergedDispatcherID == nil { + return + } + mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + if e.isMergeOperatorFinished(req) { + e.RemoveMergeOperator(mergedID) + return + } + if e.hasMergedDispatcher(req) { + return + } + log.Info("cleanup merge operator because merged dispatcher not found", + zap.Stringer("changefeedID", e.changefeedID), + zap.String("dispatcherID", mergedID.String()), + zap.Int64("mode", req.Mode)) + e.RemoveMergeOperator(mergedID) +} + +func (e *DispatcherManager) cleanupFinishedMergeOperators() { + e.mergeOperatorMap.Range(func(_, value any) bool { + req, ok := value.(*heartbeatpb.MergeDispatcherRequest) + if !ok || req == nil || req.MergedDispatcherID == nil { + return true + } + if !e.isMergeOperatorFinished(req) { + return true + } + mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + log.Info("cleanup finished merge operator", + zap.Stringer("changefeedID", e.changefeedID), + zap.String("dispatcherID", mergedID.String()), + zap.Int64("mode", req.Mode)) + e.RemoveMergeOperator(mergedID) + return true + }) +} + +func (e *DispatcherManager) isMergeOperatorFinished(req *heartbeatpb.MergeDispatcherRequest) bool { + if req == nil || req.MergedDispatcherID == nil || len(req.DispatcherIDs) < 2 { + return true + } + if common.IsRedoMode(req.Mode) { + if !e.IsRedoReady() { + return false + } + return isMergeOperatorFinished(req, e.redoDispatcherMap) + } + return isMergeOperatorFinished(req, e.dispatcherMap) +} + +func isMergeOperatorFinished[T dispatcher.Dispatcher]( + req *heartbeatpb.MergeDispatcherRequest, + dispatcherMap *DispatcherMap[T], +) bool { + for _, idPB := range req.DispatcherIDs { + if idPB == nil { + continue + } + dispatcherID := common.NewDispatcherIDFromPB(idPB) + if _, ok := dispatcherMap.Get(dispatcherID); ok { + // Keep the merge journal while any source dispatcher still exists. A maintainer failover + // in this window must restore the merge intent so late source terminal statuses do not + // recreate spans that are already covered by the merged dispatcher. + return false + } + } + + mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + mergedDispatcher, ok := dispatcherMap.Get(mergedID) + if !ok { + return true + } + return mergedDispatcher.GetComponentStatus() == heartbeatpb.ComponentState_Working +} + +func (e *DispatcherManager) hasMergedDispatcher(req *heartbeatpb.MergeDispatcherRequest) bool { + if req == nil || req.MergedDispatcherID == nil { + return false + } + mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) + if common.IsRedoMode(req.Mode) { + if !e.IsRedoReady() { + return false + } + _, ok := e.redoDispatcherMap.Get(mergedID) + return ok + } + _, ok := e.dispatcherMap.Get(mergedID) + return ok +} + +// GetMergeOperators returns cloned in-flight merge requests for maintainer bootstrap. +func (e *DispatcherManager) GetMergeOperators() []*heartbeatpb.MergeDispatcherRequest { + operators := make([]*heartbeatpb.MergeDispatcherRequest, 0) + e.mergeOperatorMap.Range(func(_, value any) bool { + req, ok := value.(*heartbeatpb.MergeDispatcherRequest) + if !ok || req == nil { + return true + } + operators = append(operators, proto.Clone(req).(*heartbeatpb.MergeDispatcherRequest)) + return true + }) + return operators +} diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager_test.go b/downstreamadapter/dispatchermanager/dispatcher_manager_test.go index 5806df543c..e8ff54b036 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager_test.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager_test.go @@ -1006,6 +1006,108 @@ func TestDoMerge(t *testing.T) { require.False(t, exists) } +// TestDoMergeKeepsMergeJournalUntilSourcesAreCleaned covers maintainer failover between merged +// dispatcher commit and source dispatcher cleanup. The test tracks a merge request, runs doMerge, +// verifies the journal is still reported while sources are being removed, then marks the merged +// dispatcher Working and expects heartbeat cleanup to drop the finished journal. +func TestDoMergeKeepsMergeJournalUntilSourcesAreCleaned(t *testing.T) { + manager := createTestManager(t) + + dispatcher1 := createTestDispatcher(t, manager, + common.NewDispatcherID(), + 1, + []byte("a"), + []byte("m"), + ) + dispatcher2 := createTestDispatcher(t, manager, + common.NewDispatcherID(), + 1, + []byte("m"), + []byte("z"), + ) + + manager.dispatcherMap.Set(dispatcher1.GetId(), dispatcher1) + manager.dispatcherMap.Set(dispatcher2.GetId(), dispatcher2) + + mergedID := common.NewDispatcherID() + mergeReq := &heartbeatpb.MergeDispatcherRequest{ + ChangefeedID: manager.changefeedID.ToPB(), + DispatcherIDs: []*heartbeatpb.DispatcherID{dispatcher1.GetId().ToPB(), dispatcher2.GetId().ToPB()}, + MergedDispatcherID: mergedID.ToPB(), + Mode: common.DefaultMode, + } + manager.TrackMergeOperator(mergeReq) + task := manager.mergeEventDispatcher([]common.DispatcherID{ + dispatcher1.GetId(), + dispatcher2.GetId(), + }, mergedID) + require.NotNil(t, task) + + doMerge(task, task.manager.dispatcherMap) + require.Len(t, manager.GetMergeOperators(), 1) + + manager.aggregateDispatcherHeartbeats(false) + require.Len(t, manager.GetMergeOperators(), 1) + _, exists := manager.dispatcherMap.Get(dispatcher1.GetId()) + require.False(t, exists) + _, exists = manager.dispatcherMap.Get(dispatcher2.GetId()) + require.False(t, exists) + + mergedDispatcher, exists := manager.dispatcherMap.Get(mergedID) + require.True(t, exists) + mergedDispatcher.SetComponentStatus(heartbeatpb.ComponentState_Working) + manager.aggregateDispatcherHeartbeats(false) + require.Empty(t, manager.GetMergeOperators()) +} + +// TestTrackMergeOperatorClonesRequest verifies that the merge journal owns its request data. +// It mutates the original request and one returned snapshot, then confirms later reads retain +// the tracked epoch and nested dispatcher IDs. +func TestTrackMergeOperatorClonesRequest(t *testing.T) { + manager := createTestManager(t) + sourceDispatcherID := common.NewDispatcherID() + mergeReq := &heartbeatpb.MergeDispatcherRequest{ + ChangefeedID: manager.changefeedID.ToPB(), + DispatcherIDs: []*heartbeatpb.DispatcherID{ + sourceDispatcherID.ToPB(), + common.NewDispatcherID().ToPB(), + }, + MergedDispatcherID: common.NewDispatcherID().ToPB(), + Mode: common.DefaultMode, + MaintainerEpoch: 7, + } + + manager.TrackMergeOperator(mergeReq) + mergeReq.MaintainerEpoch = 8 + mergeReq.DispatcherIDs[0].Low ^= 1 + + operators := manager.GetMergeOperators() + require.Len(t, operators, 1) + require.Equal(t, uint64(7), operators[0].MaintainerEpoch) + require.Equal(t, sourceDispatcherID.ToPB(), operators[0].DispatcherIDs[0]) + + operators[0].MaintainerEpoch = 9 + operators[0].DispatcherIDs[0].Low ^= 1 + operators = manager.GetMergeOperators() + require.Len(t, operators, 1) + require.Equal(t, uint64(7), operators[0].MaintainerEpoch) + require.Equal(t, sourceDispatcherID.ToPB(), operators[0].DispatcherIDs[0]) +} + +// TestTrackMergeOperatorRejectsZeroMergedDispatcherID covers a malformed merge request. +// The test tracks a request with an all-zero merged ID and verifies it cannot occupy the shared +// zero-value map key or appear in later bootstrap responses. +func TestTrackMergeOperatorRejectsZeroMergedDispatcherID(t *testing.T) { + manager := createTestManager(t) + manager.TrackMergeOperator(&heartbeatpb.MergeDispatcherRequest{ + ChangefeedID: manager.changefeedID.ToPB(), + DispatcherIDs: []*heartbeatpb.DispatcherID{common.NewDispatcherID().ToPB(), common.NewDispatcherID().ToPB()}, + MergedDispatcherID: (&common.DispatcherID{}).ToPB(), + Mode: common.DefaultMode, + }) + require.Empty(t, manager.GetMergeOperators()) +} + func TestDoMergeWithThreeDispatchers(t *testing.T) { manager := createTestManager(t) diff --git a/downstreamadapter/dispatchermanager/heartbeat_collector.go b/downstreamadapter/dispatchermanager/heartbeat_collector.go index 415842ab6c..2d23b741b0 100644 --- a/downstreamadapter/dispatchermanager/heartbeat_collector.go +++ b/downstreamadapter/dispatchermanager/heartbeat_collector.go @@ -288,6 +288,8 @@ func (c *HeartBeatCollector) RecvMessages(_ context.Context, msg *messaging.Targ NewRedoMetaMessage(msg.From, redoMessage)) case messaging.TypeMergeDispatcherRequest: mergeDispatcherRequest := msg.Message[0].(*heartbeatpb.MergeDispatcherRequest) + // The handler owns journaling because it first applies the maintainer fence. + // Tracking here would let stale requests leak into bootstrap recovery. c.mergeDispatcherRequestDynamicStream.Push( common.NewChangefeedGIDFromPB(mergeDispatcherRequest.ChangefeedID), NewMergeDispatcherRequest(msg.From, mergeDispatcherRequest)) diff --git a/downstreamadapter/dispatchermanager/helper.go b/downstreamadapter/dispatchermanager/helper.go index 63eb629033..cfbb2f6a97 100644 --- a/downstreamadapter/dispatchermanager/helper.go +++ b/downstreamadapter/dispatchermanager/helper.go @@ -936,11 +936,21 @@ func (h *MergeDispatcherRequestHandler) Handle(dispatcherManager *DispatcherMana ) { return false } + // Journal only an admitted request. Persisting a stale maintainer's merge would + // make the next bootstrap restore an operation that the epoch fence rejected. + dispatcherManager.TrackMergeOperator(mergeDispatcherRequest.MergeDispatcherRequest) dispatcherIDs := make([]common.DispatcherID, 0, len(mergeDispatcherRequest.DispatcherIDs)) for _, id := range mergeDispatcherRequest.DispatcherIDs { dispatcherIDs = append(dispatcherIDs, common.NewDispatcherIDFromPB(id)) } - dispatcherManager.MergeDispatcher(dispatcherIDs, common.NewDispatcherIDFromPB(mergeDispatcherRequest.MergedDispatcherID), mergeDispatcherRequest.Mode) + task := dispatcherManager.MergeDispatcher( + dispatcherIDs, + common.NewDispatcherIDFromPB(mergeDispatcherRequest.MergedDispatcherID), + mergeDispatcherRequest.Mode, + ) + if task == nil { + dispatcherManager.MaybeCleanupMergeOperator(mergeDispatcherRequest.MergeDispatcherRequest) + } return false } diff --git a/downstreamadapter/dispatchermanager/helper_test.go b/downstreamadapter/dispatchermanager/helper_test.go index a230f62372..4bdf3e5f5b 100644 --- a/downstreamadapter/dispatchermanager/helper_test.go +++ b/downstreamadapter/dispatchermanager/helper_test.go @@ -367,6 +367,36 @@ func TestHeartBeatResponseHandlerDropsStaleMaintainerEpoch(t *testing.T) { }) } +func TestMergeDispatcherRequestHandlerDropsStaleEpochBeforeTracking(t *testing.T) { + // Scenario: an old maintainer retries a merge after ownership has moved to a newer epoch. + // Steps: send the stale request through the handler and verify it is neither executed nor + // persisted in the bootstrap merge journal. + t.Parallel() + + changefeedID := common.NewChangeFeedIDWithName("test-changefeed", "test-namespace") + dispatcherManager := &DispatcherManager{changefeedID: changefeedID} + dispatcherManager.meta.maintainerID = "current-maintainer" + dispatcherManager.meta.maintainerEpoch = 2 + + staleRequest := NewMergeDispatcherRequest( + "old-maintainer", + &heartbeatpb.MergeDispatcherRequest{ + ChangefeedID: changefeedID.ToPB(), + DispatcherIDs: []*heartbeatpb.DispatcherID{ + common.NewDispatcherID().ToPB(), + common.NewDispatcherID().ToPB(), + }, + MergedDispatcherID: common.NewDispatcherID().ToPB(), + Mode: common.DefaultMode, + MaintainerEpoch: 1, + }, + ) + + handler := &MergeDispatcherRequestHandler{} + require.False(t, handler.Handle(dispatcherManager, staleRequest)) + require.Empty(t, dispatcherManager.GetMergeOperators()) +} + func TestRedoControlMessagesAllowedByMaintainerEpoch(t *testing.T) { t.Parallel() diff --git a/downstreamadapter/dispatchermanager/task.go b/downstreamadapter/dispatchermanager/task.go index d212822149..2d2ec92a29 100644 --- a/downstreamadapter/dispatchermanager/task.go +++ b/downstreamadapter/dispatchermanager/task.go @@ -208,6 +208,7 @@ func abortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *Dispa } removeDispatcher(t.manager, t.mergedDispatcher.GetId(), dispatcherMap, sinkType) + t.manager.RemoveMergeOperator(t.mergedDispatcher.GetId()) } func doMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T]) { diff --git a/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go b/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go index d4814e91c5..7b95269e62 100644 --- a/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go +++ b/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go @@ -971,6 +971,8 @@ func retrieveOperatorsForBootstrapResponse( proto.Clone(req.ScheduleDispatcherRequest).(*heartbeatpb.ScheduleDispatcherRequest)) return true }) + + response.MergeOperators = append(response.MergeOperators, manager.GetMergeOperators()...) } func isDispatcherInLiveMap( diff --git a/heartbeatpb/heartbeat.pb.go b/heartbeatpb/heartbeat.pb.go index e585796bef..1c80d844f1 100644 --- a/heartbeatpb/heartbeat.pb.go +++ b/heartbeatpb/heartbeat.pb.go @@ -2242,6 +2242,8 @@ type MaintainerBootstrapResponse struct { RedoCheckpointTs uint64 `protobuf:"varint,5,opt,name=redo_checkpoint_ts,json=redoCheckpointTs,proto3" json:"redo_checkpoint_ts,omitempty"` Operators []*ScheduleDispatcherRequest `protobuf:"bytes,6,rep,name=operators,proto3" json:"operators,omitempty"` MaintainerEpoch uint64 `protobuf:"varint,7,opt,name=maintainer_epoch,json=maintainerEpoch,proto3" json:"maintainer_epoch,omitempty"` + // merge_operators contains in-flight merge dispatcher requests for bootstrap recovery. + MergeOperators []*MergeDispatcherRequest `protobuf:"bytes,8,rep,name=merge_operators,json=mergeOperators,proto3" json:"merge_operators,omitempty"` } func (m *MaintainerBootstrapResponse) Reset() { *m = MaintainerBootstrapResponse{} } @@ -2326,6 +2328,13 @@ func (m *MaintainerBootstrapResponse) GetMaintainerEpoch() uint64 { return 0 } +func (m *MaintainerBootstrapResponse) GetMergeOperators() []*MergeDispatcherRequest { + if m != nil { + return m.MergeOperators + } + return nil +} + type MaintainerPostBootstrapRequest struct { ChangefeedID *ChangefeedID `protobuf:"bytes,1,opt,name=changefeedID,proto3" json:"changefeedID,omitempty"` TableTriggerEventDispatcherId *DispatcherID `protobuf:"bytes,2,opt,name=table_trigger_event_dispatcher_id,json=tableTriggerEventDispatcherId,proto3" json:"table_trigger_event_dispatcher_id,omitempty"` @@ -3993,195 +4002,196 @@ func init() { func init() { proto.RegisterFile("heartbeatpb/heartbeat.proto", fileDescriptor_6d584080fdadb670) } var fileDescriptor_6d584080fdadb670 = []byte{ - // 2998 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x3a, 0x4d, 0x73, 0x1b, 0xc7, - 0xb1, 0xda, 0xc5, 0x17, 0xd1, 0x24, 0xa8, 0xd5, 0x48, 0xa2, 0x28, 0x89, 0xa2, 0xe8, 0x7d, 0x7e, - 0xaf, 0x68, 0xd8, 0x4f, 0x7a, 0x92, 0xad, 0x97, 0xc4, 0x71, 0xec, 0x40, 0x00, 0x6d, 0xa1, 0x44, - 0x90, 0xac, 0x01, 0x6d, 0xa5, 0x9c, 0x03, 0xb2, 0xdc, 0x1d, 0x81, 0x6b, 0x02, 0x3b, 0xf0, 0xee, - 0x42, 0x94, 0x54, 0x95, 0xa4, 0x5c, 0x49, 0x6e, 0x39, 0x24, 0xb7, 0x1c, 0xe2, 0x4b, 0x4e, 0x39, - 0xa5, 0xf2, 0x07, 0x52, 0xc9, 0x21, 0x87, 0x9c, 0x52, 0x3e, 0xa5, 0x7c, 0x4a, 0x5c, 0xf6, 0x3d, - 0x95, 0xaa, 0x54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 0x92, 0xd8, 0x07, 0xc1, 0x78, 0xd8, 0x21, 0xa1, 0x85, 0xfe, 0x2f, 0x3a, 0xdb, 0x79, 0xb9, 0x45, - 0x44, 0x99, 0x3a, 0xe3, 0x75, 0x30, 0x6c, 0x15, 0xdf, 0x25, 0x1f, 0xca, 0x79, 0x26, 0xf0, 0xe6, - 0x4f, 0x35, 0xb8, 0xac, 0xfc, 0x89, 0x80, 0x84, 0x91, 0x44, 0x74, 0x09, 0x4a, 0xe2, 0xc5, 0x44, - 0x6c, 0xa2, 0x00, 0x98, 0xe7, 0x3c, 0xa5, 0xfe, 0x03, 0xb6, 0xb9, 0xf2, 0xfa, 0x91, 0x20, 0x5a, - 0x82, 0xf2, 0x53, 0xea, 0x6f, 0xd2, 0x43, 0x79, 0x6e, 0x25, 0x24, 0xb2, 0xaf, 0x21, 0xe7, 0x28, - 0xca, 0xc6, 0x8e, 0x00, 0x19, 0x47, 0x30, 0x1e, 0x32, 0x0e, 0x91, 0xf8, 0x4a, 0x88, 0xa5, 0x82, - 0x6b, 0xb9, 0x3a, 0x35, 0xec, 0x83, 0x59, 0xed, 0xc2, 0x25, 0x28, 0xa9, 0x5d, 0x61, 0x01, 0xe4, - 0xfe, 0x53, 0x42, 0xfe, 0xa1, 0xaa, 0x18, 0xff, 0xa1, 0xca, 0xfc, 0x8b, 0x06, 0x66, 0xae, 0x7e, - 0xe2, 0xfe, 0x99, 0x51, 0x30, 0x39, 0x83, 0x86, 0xe8, 0x4d, 0x98, 0x8b, 0x76, 0x9a, 0xdb, 0x36, - 0xfb, 0x77, 0x9c, 0x5c, 0xed, 0x71, 0xcc, 0x53, 0xbf, 0x11, 0x25, 0x4f, 0xa8, 0x0a, 0xa5, 0x47, - 0xbe, 0x1b, 0x12, 0xe3, 0x1c, 0x9a, 0x83, 0xe2, 0x8e, 0x15, 0x04, 0x86, 0x56, 0x5f, 0x17, 0xb9, - 0x91, 0xf2, 0xda, 0x0b, 0x50, 0x6e, 0xfa, 0xc4, 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a, 0x7d, 0xc1, - 0xdf, 0x0d, 0x79, 0xba, 0x25, 0x34, 0x17, 0x76, 0x74, 0x0c, 0x1d, 0x19, 0xb0, 0xd0, 0xf6, 0xdc, - 0xd0, 0xb5, 0x06, 0xee, 0x73, 0x46, 0x5b, 0x40, 0x35, 0xa8, 0xee, 0xf8, 0x64, 0x64, 0xf9, 0x0c, - 0x2c, 0xa2, 0x45, 0x00, 0x6e, 0x4e, 0x4c, 0x2c, 0xe7, 0x99, 0x51, 0x62, 0x0c, 0x8f, 0x2c, 0x37, - 0x74, 0xbd, 0xbe, 0xb0, 0x72, 0xb9, 0xfe, 0x75, 0xa8, 0xa5, 0xe2, 0x0a, 0xba, 0x00, 0xb5, 0x77, - 0xb7, 0xda, 0x5b, 0xed, 0xdd, 0x76, 0x63, 0xb3, 0xfd, 0xfe, 0x46, 0x4b, 0x98, 0xbb, 0xd3, 0xee, - 0x76, 0x1a, 0xbb, 0xcd, 0x07, 0x86, 0xc6, 0x56, 0x26, 0x3e, 0xf5, 0xfb, 0x6f, 0xfe, 0xe1, 0xf3, - 0x55, 0xed, 0x93, 0xcf, 0x57, 0xb5, 0xcf, 0x3e, 0x5f, 0xd5, 0x7e, 0xf2, 0xc5, 0xea, 0xb9, 0x4f, - 0xbe, 0x58, 0x3d, 0xf7, 0xe9, 0x17, 0xab, 0xe7, 0xde, 0x7f, 0xb1, 0xef, 0x86, 0xfb, 0xe3, 0xbd, - 0x5b, 0x36, 0x1d, 0xde, 0x1e, 0xb9, 0x5e, 0xdf, 0xb6, 0x46, 0xb7, 0x43, 0xd7, 0x76, 0xec, 0xdb, - 0x8a, 0x6b, 0xee, 0x95, 0xf9, 0xab, 0xc7, 0xab, 0xff, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xeb, 0x05, - 0xdf, 0xf4, 0x18, 0x2b, 0x00, 0x00, + // 3020 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0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0x70, 0x39, 0xe6, 0x6f, 0x72, 0x60, 0x8c, 0xaf, 0xfc, 0xac, 0xbe, 0x74, 0x1d, 0x80, 0x7d, + 0x75, 0x99, 0xfd, 0x08, 0x5f, 0x74, 0x05, 0x57, 0x18, 0x86, 0x89, 0x27, 0xe8, 0x36, 0x14, 0xc4, + 0x48, 0xd6, 0x51, 0x6b, 0xd0, 0xc1, 0x90, 0x7a, 0xc4, 0x0b, 0x39, 0x2d, 0x16, 0x94, 0xe8, 0x79, + 0xa8, 0x26, 0xd7, 0x52, 0x37, 0x8c, 0x13, 0xfb, 0xd4, 0x5d, 0x25, 0xab, 0x91, 0x42, 0x86, 0xe3, + 0x4e, 0x54, 0x23, 0xe8, 0x4b, 0xb0, 0xb0, 0x47, 0x69, 0x18, 0x84, 0xbe, 0x35, 0xec, 0x3a, 0xd4, + 0x23, 0x32, 0x6c, 0x55, 0x63, 0x6c, 0x93, 0x7a, 0x64, 0xa2, 0xa0, 0x28, 0x4d, 0x16, 0x14, 0xa8, + 0x0e, 0x0b, 0xc2, 0xf4, 0x43, 0xe9, 0x1d, 0xcb, 0x65, 0x6e, 0xaf, 0x74, 0x7e, 0x9c, 0xf2, 0x1f, + 0x5c, 0x75, 0x52, 0xee, 0x94, 0xe5, 0xdd, 0x95, 0x6c, 0xef, 0xfe, 0x87, 0x06, 0x55, 0xe6, 0x5e, + 0x89, 0x63, 0xdf, 0x85, 0x72, 0xdf, 0x7d, 0x4c, 0x3c, 0x36, 0xb3, 0x96, 0x11, 0x7a, 0x18, 0xf5, + 0xa6, 0x24, 0xc0, 0x31, 0x29, 0xdb, 0x25, 0xee, 0xbb, 0xaa, 0x6b, 0x56, 0x18, 0x46, 0x38, 0x66, + 0x13, 0x6e, 0x28, 0x1e, 0x29, 0x16, 0x38, 0xe6, 0xf2, 0x39, 0xbe, 0xb3, 0xd7, 0x12, 0x32, 0xbe, + 0xc6, 0x5d, 0xf5, 0x04, 0xd4, 0xe1, 0xfa, 0x34, 0x29, 0x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x3c, 0x10, 0xc9, 0xd4, 0x34, 0x41, 0x98, 0x1f, 0xea, 0x70, 0x01, 0xd3, 0x51, 0x48, 0xb8, + 0xa8, 0xba, 0x33, 0x70, 0x03, 0x5e, 0xb1, 0xd4, 0xc0, 0xe8, 0xd0, 0x91, 0x6f, 0x13, 0x25, 0x3a, + 0x88, 0x3a, 0x6e, 0x02, 0x8f, 0xd6, 0x61, 0x51, 0xe0, 0xc6, 0x8f, 0xf4, 0x38, 0x9a, 0x49, 0x15, + 0xd5, 0x88, 0x22, 0x55, 0x14, 0x3e, 0x13, 0x78, 0x26, 0x55, 0xe0, 0x12, 0xa9, 0x79, 0x21, 0x75, + 0x0c, 0x8d, 0xde, 0x80, 0xa2, 0x6c, 0x85, 0x16, 0xf8, 0x9e, 0xa4, 0x53, 0x85, 0x8c, 0xd5, 0x45, + 0x6f, 0x53, 0xe2, 0xd7, 0xf4, 0x60, 0x21, 0xb2, 0x96, 0x70, 0xad, 0x23, 0x2c, 0xbd, 0x06, 0x73, + 0xdb, 0x7d, 0x67, 0xcc, 0xd8, 0x2a, 0x8a, 0x51, 0x6c, 0x91, 0xc3, 0xb1, 0xdd, 0x54, 0x51, 0xe6, + 0x7f, 0x72, 0x50, 0x10, 0x87, 0x77, 0x05, 0x2a, 0xad, 0x80, 0xbf, 0x58, 0xc9, 0x22, 0xbd, 0x8c, + 0x13, 0x04, 0xd3, 0x82, 0x7f, 0x26, 0x3d, 0x73, 0x09, 0xa2, 0x37, 0x61, 0x4e, 0x7c, 0x46, 0xa1, + 0x79, 0xb2, 0x81, 0x3c, 0xee, 0xc0, 0x58, 0xe5, 0x40, 0x0f, 0xe0, 0xfc, 0x16, 0x21, 0x4e, 0xd3, + 0xa7, 0xc3, 0x61, 0x44, 0x21, 0xd3, 0xf4, 0x63, 0xc4, 0x4c, 0xf2, 0xa1, 0xd7, 0x61, 0x91, 0x21, + 0xeb, 0x8e, 0x13, 0x8b, 0x12, 0x2d, 0x2d, 0x34, 0x19, 0x5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 0x5e, 0xb6, 0x89, 0x04, 0xc8, 0x38, 0x82, 0xd1, 0x80, 0x71, + 0x88, 0xc4, 0x57, 0x42, 0x2c, 0x15, 0x5c, 0xcb, 0xd4, 0xa9, 0x6e, 0x1f, 0xcc, 0x6a, 0x17, 0x2e, + 0x42, 0x41, 0xed, 0x31, 0x0b, 0x20, 0xf3, 0x7f, 0x17, 0xf2, 0xef, 0x59, 0xf9, 0xf8, 0xef, 0x59, + 0xe6, 0xdf, 0x35, 0x30, 0x33, 0xf5, 0x13, 0xf7, 0xcf, 0x8c, 0x82, 0xc9, 0x19, 0x34, 0x44, 0x6f, + 0x40, 0x39, 0xda, 0x69, 0x6e, 0xdb, 0xf1, 0x3f, 0xf7, 0x64, 0x6a, 0x8f, 0x63, 0x9e, 0xda, 0xf5, + 0x28, 0x79, 0x42, 0x15, 0x28, 0x3c, 0xf4, 0xdd, 0x90, 0x18, 0xe7, 0x50, 0x19, 0xf2, 0x3b, 0x56, + 0x10, 0x18, 0x5a, 0x6d, 0x5d, 0xe4, 0x46, 0xca, 0xdb, 0x31, 0x40, 0xb1, 0xe1, 0x13, 0x8b, 0xd3, + 0x01, 0x14, 0x45, 0x53, 0xd5, 0xd0, 0x6a, 0x6d, 0x98, 0x57, 0x9f, 0x8c, 0x99, 0xb8, 0xed, 0x6e, + 0xdd, 0x71, 0x8c, 0x73, 0x68, 0x1e, 0xca, 0xdb, 0xdd, 0x88, 0x90, 0x31, 0x6d, 0x77, 0xdb, 0xec, + 0x5b, 0x47, 0x73, 0x50, 0xda, 0xee, 0xf2, 0x6c, 0xd4, 0xc8, 0x09, 0x80, 0xb7, 0x58, 0x8c, 0x7c, + 0xed, 0x2e, 0xcc, 0xab, 0x2f, 0x14, 0x4c, 0x5c, 0x7d, 0xb3, 0xf5, 0xee, 0x86, 0x10, 0xd7, 0xc4, + 0xf5, 0xd6, 0x56, 0x6b, 0xeb, 0x6d, 0x43, 0x63, 0x50, 0x67, 0x77, 0x7b, 0x67, 0x87, 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0xbb, 0xd5, 0x69, 0xd7, 0x77, 0x1b, 0xf7, 0x0d, 0x8d, 0xad, 0x4c, 0x7c, + 0xea, 0xf7, 0xde, 0xf8, 0xd3, 0x67, 0xab, 0xda, 0xc7, 0x9f, 0xad, 0x6a, 0x9f, 0x7e, 0xb6, 0xaa, + 0xfd, 0xec, 0xf3, 0xd5, 0x73, 0x1f, 0x7f, 0xbe, 0x7a, 0xee, 0x93, 0xcf, 0x57, 0xcf, 0xbd, 0xf7, + 0x42, 0xcf, 0x0d, 0xf7, 0x47, 0x7b, 0x37, 0x6d, 0x3a, 0xb8, 0x35, 0x74, 0xbd, 0x9e, 0x6d, 0x0d, + 0x6f, 0x85, 0xae, 0xed, 0xd8, 0xb7, 0x14, 0xd7, 0xdc, 0x2b, 0xf2, 0x37, 0x94, 0x57, 0xfe, 0x1b, + 0x00, 0x00, 0xff, 0xff, 0x50, 0xf3, 0xe4, 0x7c, 0x66, 0x2b, 0x00, 0x00, } func (m *TableSpan) Marshal() (dAtA []byte, err error) { @@ -5708,6 +5718,20 @@ func (m *MaintainerBootstrapResponse) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if len(m.MergeOperators) > 0 { + for iNdEx := len(m.MergeOperators) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MergeOperators[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintHeartbeat(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + } if m.MaintainerEpoch != 0 { i = encodeVarintHeartbeat(dAtA, i, uint64(m.MaintainerEpoch)) i-- @@ -7733,6 +7757,12 @@ func (m *MaintainerBootstrapResponse) Size() (n int) { if m.MaintainerEpoch != 0 { n += 1 + sovHeartbeat(uint64(m.MaintainerEpoch)) } + if len(m.MergeOperators) > 0 { + for _, e := range m.MergeOperators { + l = e.Size() + n += 1 + l + sovHeartbeat(uint64(l)) + } + } return n } @@ -12663,6 +12693,40 @@ func (m *MaintainerBootstrapResponse) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MergeOperators", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeartbeat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthHeartbeat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthHeartbeat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MergeOperators = append(m.MergeOperators, &MergeDispatcherRequest{}) + if err := m.MergeOperators[len(m.MergeOperators)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipHeartbeat(dAtA[iNdEx:]) diff --git a/heartbeatpb/heartbeat.proto b/heartbeatpb/heartbeat.proto index 88487513e1..f675d88357 100644 --- a/heartbeatpb/heartbeat.proto +++ b/heartbeatpb/heartbeat.proto @@ -288,6 +288,8 @@ message MaintainerBootstrapResponse { uint64 redo_checkpoint_ts = 5; repeated ScheduleDispatcherRequest operators = 6; uint64 maintainer_epoch = 7; + // merge_operators contains in-flight merge dispatcher requests for bootstrap recovery. + repeated MergeDispatcherRequest merge_operators = 8; } message MaintainerPostBootstrapRequest { diff --git a/maintainer/maintainer_controller_bootstrap.go b/maintainer/maintainer_controller_bootstrap.go index 180b0fa31f..51ebb9692a 100644 --- a/maintainer/maintainer_controller_bootstrap.go +++ b/maintainer/maintainer_controller_bootstrap.go @@ -16,6 +16,7 @@ package maintainer import ( "bytes" "context" + "sort" "time" "github.com/pingcap/log" @@ -133,6 +134,19 @@ func (c *Controller) FinishBootstrap( } } + // Restore merge operators after task state is rebuilt from bootstrap spans/operators. + // Merge restoration needs the per-dispatcher task map from buildTaskInfo, but must run + // before we discard any leftover working tasks as dropped-table artifacts. + mergeTableSplitMaps := map[int64]map[int64]bool{ + common.DefaultMode: buildTableSplitMap(tables), + } + if c.enableRedo { + mergeTableSplitMaps[common.RedoMode] = buildTableSplitMap(redoTables) + } + if err := c.restoreCurrentMergeOperators(allNodesResp, mergeTableSplitMaps); err != nil { + return nil, errors.Trace(err) + } + // Step 4: Handle any remaining working tasks (likely dropped tables) c.handleRemainingWorkingTasks(workingTaskMap, redoWorkingTaskMap) @@ -206,11 +220,11 @@ func (c *Controller) buildWorkingTaskMap( spanController := c.getSpanController(mode) for node, resp := range allNodesResp { for _, spanInfo := range resp.Spans { - if spanInfo.Mode != mode { + if spanInfo == nil || spanInfo.ID == nil || spanInfo.Span == nil || spanInfo.Mode != mode { continue } dispatcherID := common.NewDispatcherIDFromPB(spanInfo.ID) - if spanController.IsDDLDispatcher(dispatcherID) { + if dispatcherID.IsZero() || spanController.IsDDLDispatcher(dispatcherID) { continue } splitEnabled := spanController.ShouldEnableSplit(tableSplitMap[spanInfo.Span.TableID]) @@ -291,7 +305,7 @@ func (c *Controller) processTableSpans( if c.enableTableAcrossNodes { if !isTableWorking && tableSpans == nil { - tableSpans = utils.NewBtreeMap[*heartbeatpb.TableSpan, *replica.SpanReplication](common.LessTableSpan) + tableSpans = utils.NewBtreeMap[*heartbeatpb.TableSpan, *replica.SpanReplication](lessBootstrapTableSpan) } if isTableSpanExists { for _, replicaSet := range replicaSets { @@ -337,10 +351,7 @@ func (c *Controller) buildTaskInfo( error, ) { // Build table splitability map for later use - tableSplitMap := make(map[int64]bool, len(tables)) - for _, tbl := range tables { - tableSplitMap[tbl.TableID] = tbl.Splitable - } + tableSplitMap := buildTableSplitMap(tables) workingTaskMap := c.buildWorkingTaskMap(allNodesResp, tableSplitMap, mode) // Restore current working operators first so spanController reflects "in-flight scheduling intent" // captured by dispatcher managers. This avoids bootstrap creating duplicate tasks for a dispatcherID @@ -348,10 +359,19 @@ func (c *Controller) buildTaskInfo( if err := c.restoreCurrentWorkingOperators(allNodesResp, tableSplitMap, mode); err != nil { return nil, nil, err } + c.removeUnexpectedBootstrapOverlaps(workingTaskMap, allNodesResp, mode) schemaInfos := c.processTablesAndBuildSchemaInfo(tables, workingTaskMap, isMysqlCompatibleBackend, mode) return workingTaskMap, schemaInfos, nil } +func buildTableSplitMap(tables []commonEvent.Table) map[int64]bool { + tableSplitMap := make(map[int64]bool, len(tables)) + for _, tbl := range tables { + tableSplitMap[tbl.TableID] = tbl.Splitable + } + return tableSplitMap +} + func (c *Controller) handleRemainingWorkingTasks( workingTaskMap, redoWorkingTaskMap map[int64]utils.Map[*heartbeatpb.TableSpan, *replica.SpanReplication], ) { @@ -454,46 +474,363 @@ func addToWorkingTaskMap( ) { tableSpans, ok := workingTaskMap[span.TableID] if !ok { - tableSpans = utils.NewBtreeMap[*heartbeatpb.TableSpan, *replica.SpanReplication](common.LessTableSpan) + tableSpans = utils.NewBtreeMap[*heartbeatpb.TableSpan, *replica.SpanReplication](lessBootstrapTableSpan) workingTaskMap[span.TableID] = tableSpans } tableSpans.ReplaceOrInsert(span, spanReplication) } -// findHoles returns an array of Span that are not covered in the range -func findHoles(currentSpan utils.Map[*heartbeatpb.TableSpan, *replica.SpanReplication], totalSpan *heartbeatpb.TableSpan) []*heartbeatpb.TableSpan { - lastSpan := &heartbeatpb.TableSpan{ - TableID: totalSpan.TableID, - StartKey: totalSpan.StartKey, - EndKey: totalSpan.StartKey, - KeyspaceID: totalSpan.KeyspaceID, +// lessBootstrapTableSpan keeps spans with the same start key but different end keys distinct. +// Merge bootstrap snapshots can contain a source span and its covering merged span with the same +// start key, so the normal start-key-only comparator would silently replace one of them. +func lessBootstrapTableSpan(left, right *heartbeatpb.TableSpan) bool { + if left.TableID != right.TableID { + return left.TableID < right.TableID + } + if cmp := bytes.Compare(left.StartKey, right.StartKey); cmp != 0 { + return cmp < 0 + } + if cmp := bytes.Compare(left.EndKey, right.EndKey); cmp != 0 { + // Put the narrower span first. If a merge target is not backed by valid merge evidence, + // preserving the source topology is safer than accepting an abortable covering target. + return cmp < 0 + } + return left.KeyspaceID < right.KeyspaceID +} + +type bootstrapMergeEvidence struct { + sourceToTargets map[common.DispatcherID]map[common.DispatcherID]struct{} +} + +func buildBootstrapMergeEvidence( + allNodesResp map[node.ID]*heartbeatpb.MaintainerBootstrapResponse, + mode int64, +) bootstrapMergeEvidence { + evidence := bootstrapMergeEvidence{ + sourceToTargets: make(map[common.DispatcherID]map[common.DispatcherID]struct{}), + } + for _, resp := range allNodesResp { + if resp == nil { + continue + } + spanInfoByID := indexBootstrapSpans(resp.Spans, mode) + for _, mergeReq := range resp.MergeOperators { + if mergeReq == nil || mergeReq.MergedDispatcherID == nil || mergeReq.Mode != mode { + continue + } + mergedID := common.NewDispatcherIDFromPB(mergeReq.MergedDispatcherID) + if mergedID.IsZero() { + continue + } + mergedSpanInfo := spanInfoByID[mergedID] + if mergedSpanInfo == nil || mergedSpanInfo.Span == nil || + !isMergeTargetState(mergedSpanInfo.ComponentStatus) { + continue + } + + sourceIDs := make(map[common.DispatcherID]struct{}, len(mergeReq.DispatcherIDs)) + sourceSpans := make([]*heartbeatpb.TableSpan, 0, len(mergeReq.DispatcherIDs)) + valid := true + for _, idPB := range mergeReq.DispatcherIDs { + if idPB == nil { + valid = false + break + } + dispatcherID := common.NewDispatcherIDFromPB(idPB) + if dispatcherID.IsZero() || dispatcherID == mergedID { + valid = false + break + } + if _, ok := sourceIDs[dispatcherID]; ok { + continue + } + spanInfo := spanInfoByID[dispatcherID] + if spanInfo == nil || spanInfo.Span == nil || + spanInfo.ComponentStatus != heartbeatpb.ComponentState_WaitingMerge || + spanInfo.Span.TableID != mergedSpanInfo.Span.TableID || + spanInfo.Span.KeyspaceID != mergedSpanInfo.Span.KeyspaceID { + valid = false + break + } + sourceIDs[dispatcherID] = struct{}{} + sourceSpans = append(sourceSpans, spanInfo.Span) + } + if !valid || len(sourceIDs) < 2 { + continue + } + sort.Slice(sourceSpans, func(i, j int) bool { + return bytes.Compare(sourceSpans[i].StartKey, sourceSpans[j].StartKey) < 0 + }) + if !bytes.Equal(sourceSpans[0].StartKey, mergedSpanInfo.Span.StartKey) || + !bytes.Equal(sourceSpans[len(sourceSpans)-1].EndKey, mergedSpanInfo.Span.EndKey) { + continue + } + for i := 1; i < len(sourceSpans); i++ { + if !common.IsTableSpanConsecutive(sourceSpans[i-1], sourceSpans[i]) { + valid = false + break + } + } + if !valid { + continue + } + + for dispatcherID := range sourceIDs { + addBootstrapMergeEvidence(evidence, dispatcherID, mergedID) + } + } + } + return evidence +} + +func addBootstrapMergeEvidence( + evidence bootstrapMergeEvidence, + dispatcherID common.DispatcherID, + mergeID common.DispatcherID, +) { + targets, ok := evidence.sourceToTargets[dispatcherID] + if !ok { + targets = make(map[common.DispatcherID]struct{}) + evidence.sourceToTargets[dispatcherID] = targets + } + targets[mergeID] = struct{}{} +} + +func (e bootstrapMergeEvidence) relates(left, right common.DispatcherID) bool { + if _, ok := e.sourceToTargets[left][right]; ok { + return true + } + _, ok := e.sourceToTargets[right][left] + return ok +} + +func spansOverlap(left, right *heartbeatpb.TableSpan) bool { + if left == nil || right == nil || + left.TableID != right.TableID || + left.KeyspaceID != right.KeyspaceID { + return false + } + return bytes.Compare(left.StartKey, right.EndKey) < 0 && + bytes.Compare(right.StartKey, left.EndKey) < 0 +} + +func isMergeTargetState(status heartbeatpb.ComponentState) bool { + switch status { + case heartbeatpb.ComponentState_Preparing, + heartbeatpb.ComponentState_MergeReady, + heartbeatpb.ComponentState_Initializing, + heartbeatpb.ComponentState_Working: + return true + default: + return false + } +} + +func isCommittedMergeTargetState(status heartbeatpb.ComponentState) bool { + return status == heartbeatpb.ComponentState_Initializing || + status == heartbeatpb.ComponentState_Working +} + +func isWaitingMergeSpanCoveredByTarget( + source, target *replica.SpanReplication, +) bool { + if source == nil || target == nil || source.Span == nil || target.Span == nil { + return false + } + sourceStatus := source.GetStatus() + targetStatus := target.GetStatus() + if sourceStatus == nil || targetStatus == nil || + sourceStatus.ComponentStatus != heartbeatpb.ComponentState_WaitingMerge || + !isCommittedMergeTargetState(targetStatus.ComponentStatus) { + return false + } + return source.GetMode() == target.GetMode() && + source.Span.TableID == target.Span.TableID && + source.Span.KeyspaceID == target.Span.KeyspaceID && + bytes.Compare(target.Span.StartKey, source.Span.StartKey) <= 0 && + bytes.Compare(target.Span.EndKey, source.Span.EndKey) >= 0 +} + +func isExpectedBootstrapOverlap( + left, right *replica.SpanReplication, + evidence bootstrapMergeEvidence, +) bool { + if evidence.relates(left.ID, right.ID) { + return true + } + return isWaitingMergeSpanCoveredByTarget(left, right) || + isWaitingMergeSpanCoveredByTarget(right, left) +} + +// removeUnexpectedBootstrapOverlaps gives every unproven overlap a cleanup owner. The rejected +// runtime span remains temporary coverage until removal is confirmed, so bootstrap neither trusts +// it as permanent desired state nor schedules a replacement that can race with it. +func (c *Controller) removeUnexpectedBootstrapOverlaps( + workingTaskMap map[int64]utils.Map[*heartbeatpb.TableSpan, *replica.SpanReplication], + allNodesResp map[node.ID]*heartbeatpb.MaintainerBootstrapResponse, + mode int64, +) { + evidence := buildBootstrapMergeEvidence(allNodesResp, mode) + operatorController := c.getOperatorController(mode) + for tableID, tableSpans := range workingTaskMap { + candidates := make([]*replica.SpanReplication, 0, tableSpans.Len()) + tableSpans.Ascend(func(_ *heartbeatpb.TableSpan, candidate *replica.SpanReplication) bool { + candidates = append(candidates, candidate) + return true + }) + sort.SliceStable(candidates, func(i, j int) bool { + leftStatus := candidates[i].GetStatus() + rightStatus := candidates[j].GetStatus() + leftAbortableTarget := leftStatus != nil && + (leftStatus.ComponentStatus == heartbeatpb.ComponentState_Preparing || + leftStatus.ComponentStatus == heartbeatpb.ComponentState_MergeReady) + rightAbortableTarget := rightStatus != nil && + (rightStatus.ComponentStatus == heartbeatpb.ComponentState_Preparing || + rightStatus.ComponentStatus == heartbeatpb.ComponentState_MergeReady) + if leftAbortableTarget != rightAbortableTarget { + // Sources survive when an unvalidated merge is still abortable. + return !leftAbortableTarget + } + return lessBootstrapTableSpan(candidates[i].Span, candidates[j].Span) + }) + + accepted := make([]*replica.SpanReplication, 0, tableSpans.Len()) + for _, candidate := range candidates { + rejected := false + for _, existing := range accepted { + if !spansOverlap(existing.Span, candidate.Span) { + continue + } + // Ordinary bootstrap operators also prove that the overlap is already converging. + if operatorController.GetOperator(existing.ID) != nil || + operatorController.GetOperator(candidate.ID) != nil || + isExpectedBootstrapOverlap(existing, candidate, evidence) { + continue + } + + log.Warn("remove unexpected overlapping dispatcher reported during bootstrap", + zap.Stringer("changefeed", c.changefeedID), + zap.Int64("tableID", tableID), + zap.String("keptDispatcherID", existing.ID.String()), + zap.String("removedDispatcherID", candidate.ID.String()), + zap.String("keptSpan", common.FormatTableSpan(existing.Span)), + zap.String("removedSpan", common.FormatTableSpan(candidate.Span)), + zap.Int64("mode", mode)) + c.addBootstrapCleanupOperator(candidate) + rejected = true + break + } + if !rejected { + accepted = append(accepted, candidate) + } + } + } +} + +// addBootstrapCleanupOperator tracks a runtime span until its remove reaches a terminal state. +func (c *Controller) addBootstrapCleanupOperator(replicaSet *replica.SpanReplication) bool { + if replicaSet == nil || replicaSet.ID.IsZero() || replicaSet.GetNodeID() == "" { + return false + } + spanController := c.getSpanController(replicaSet.GetMode()) + operatorController := c.getOperatorController(replicaSet.GetMode()) + if spanController == nil || operatorController == nil { + return false } + if spanController.GetTaskByID(replicaSet.ID) == nil { + // Keep the runtime dispatcher as temporary coverage while its remove operator is active. + // This prevents the scheduler from creating a replacement before removal is confirmed. + spanController.AddReplicatingSpan(replicaSet) + } + op := operator.NewRemoveDispatcherOperator( + spanController, + replicaSet, + heartbeatpb.OperatorType_O_Remove, + operatorController.MaintainerEpoch(), + func() { + spanController.RemoveReplicatingSpan(replicaSet) + c.repairBootstrapTableCoverage(replicaSet) + }, + ) + if !operatorController.AddOperator(op) { + log.Warn("failed to add cleanup operator for unexpected bootstrap dispatcher", + zap.Stringer("changefeed", c.changefeedID), + zap.String("dispatcherID", replicaSet.ID.String()), + zap.String("nodeID", replicaSet.GetNodeID().String()), + zap.Int64("mode", replicaSet.GetMode())) + return false + } + return true +} + +// repairBootstrapTableCoverage creates absent spans only after temporary runtime coverage is gone. +func (c *Controller) repairBootstrapTableCoverage(removedReplicaSet *replica.SpanReplication) { + if removedReplicaSet == nil || removedReplicaSet.Span == nil { + return + } + spanController := c.getSpanController(removedReplicaSet.GetMode()) + if spanController == nil { + return + } + currentSpans := utils.NewBtreeMap[*heartbeatpb.TableSpan, *replica.SpanReplication](lessBootstrapTableSpan) + for _, replicaSet := range spanController.GetTasksByTableID(removedReplicaSet.Span.TableID) { + if replicaSet == nil || replicaSet.Span == nil { + continue + } + currentSpans.ReplaceOrInsert(replicaSet.Span, replicaSet) + } + totalSpan := common.TableIDToComparableSpan( + removedReplicaSet.Span.KeyspaceID, + removedReplicaSet.Span.TableID, + ) + holes := findHoles(currentSpans, &heartbeatpb.TableSpan{ + TableID: removedReplicaSet.Span.TableID, + StartKey: totalSpan.StartKey, + EndKey: totalSpan.EndKey, + KeyspaceID: removedReplicaSet.Span.KeyspaceID, + }) + spanController.AddNewSpans( + removedReplicaSet.GetSchemaID(), + holes, + c.startTs, + removedReplicaSet.IsSplitEnabled(), + ) +} + +// findHoles returns the uncovered sub-spans in totalSpan. +// +// Bootstrap snapshots can temporarily contain overlapping spans during in-flight merge recovery: +// for example, source dispatchers in WaitingMerge can coexist with a merged dispatcher in +// Preparing/Initializing. We therefore compute holes from the union of reported coverage instead +// of assuming the input spans are strictly non-overlapping. +func findHoles(currentSpan utils.Map[*heartbeatpb.TableSpan, *replica.SpanReplication], totalSpan *heartbeatpb.TableSpan) []*heartbeatpb.TableSpan { + coveredEnd := totalSpan.StartKey var holes []*heartbeatpb.TableSpan // table span is sorted currentSpan.Ascend(func(current *heartbeatpb.TableSpan, _ *replica.SpanReplication) bool { - ord := bytes.Compare(lastSpan.EndKey, current.StartKey) - if ord < 0 { + // Skip spans that are fully covered by earlier overlaps. This preserves complete table + // coverage without manufacturing holes for legitimate bootstrap overlap. + if bytes.Compare(current.EndKey, coveredEnd) <= 0 { + return true + } + if bytes.Compare(coveredEnd, current.StartKey) < 0 { // Find a hole. holes = append(holes, &heartbeatpb.TableSpan{ TableID: totalSpan.TableID, - StartKey: lastSpan.EndKey, + StartKey: coveredEnd, EndKey: current.StartKey, KeyspaceID: totalSpan.KeyspaceID, }) - } else if ord > 0 { - log.Panic("map is out of order", - zap.String("lastSpan", lastSpan.String()), - zap.String("current", current.String())) } - lastSpan = current + coveredEnd = current.EndKey return true }) // Check if there is a hole in the end. - // the lastSpan not reach the totalSpan end - if !bytes.Equal(lastSpan.EndKey, totalSpan.EndKey) { + // coveredEnd not reach the totalSpan end + if !bytes.Equal(coveredEnd, totalSpan.EndKey) { holes = append(holes, &heartbeatpb.TableSpan{ TableID: totalSpan.TableID, - StartKey: lastSpan.EndKey, + StartKey: coveredEnd, EndKey: totalSpan.EndKey, KeyspaceID: totalSpan.KeyspaceID, }) @@ -802,14 +1139,15 @@ func (c *Controller) restoreCurrentWorkingRemoveAction( replicaSet.SetNodeID(nodeID) } - if err := c.handleCurrentWorkingRemove(req, spanController, replicaSet, nodeID, resp); err != nil { + _, tableExists := tableSplitMap[span.TableID] + if err := c.handleCurrentWorkingRemove(req, spanController, replicaSet, nodeID, resp, tableExists); err != nil { return err } // If the table is already dropped (not present in schema store at startTs), keep the remove operator so the // runtime dispatcher can be cleaned up, but remove the task to avoid rescheduling a table that no longer exists. if req.OperatorType == heartbeatpb.OperatorType_O_Remove { - if _, ok := tableSplitMap[span.TableID]; !ok { + if !tableExists { spanController.RemoveReplicatingSpan(replicaSet) } } @@ -866,6 +1204,7 @@ func (c *Controller) handleCurrentWorkingRemove( replicaSet *replica.SpanReplication, node node.ID, resp *heartbeatpb.MaintainerBootstrapResponse, + tableExists bool, ) error { operatorController := c.getOperatorController(req.Config.Mode) // handleCurrentWorkingRemove translates a bootstrap Remove request back into a maintainer-side operator. @@ -879,12 +1218,22 @@ func (c *Controller) handleCurrentWorkingRemove( switch req.OperatorType { // 1. If the original operator is remove, just finish it directly by adding a new remove operator. case heartbeatpb.OperatorType_O_Remove: + var postFinish func() + if tableExists { + // The reported dispatcher is temporary coverage while its restored remove is active. A terminal + // status is consumed by this operator, so its finalizer must remove that stale coverage and create + // absent replicas for only the ranges that are no longer covered by other bootstrap spans. + postFinish = func() { + spanController.RemoveReplicatingSpan(replicaSet) + c.repairBootstrapTableCoverage(replicaSet) + } + } op := operator.NewRemoveDispatcherOperator( spanController, replicaSet, heartbeatpb.OperatorType_O_Remove, operatorController.MaintainerEpoch(), - nil, + postFinish, ) if ok := operatorController.AddOperator(op); !ok { log.Error("add operator failed when dealing current working operators in bootstrap, should not happen", @@ -928,3 +1277,450 @@ func (c *Controller) handleCurrentWorkingRemove( } return nil } + +// restoreCurrentMergeOperators rebuilds maintainer-side merge operators from bootstrap snapshots. +// +// Dispatcher managers persist in-flight merge requests independently from create/remove scheduling requests. +// After a maintainer failover, we restore those merge requests so source spans keep converging instead of +// remaining stuck in scheduling state or leaking an incomplete merged dispatcher. +func (c *Controller) restoreCurrentMergeOperators( + allNodesResp map[node.ID]*heartbeatpb.MaintainerBootstrapResponse, + tableSplitMaps map[int64]map[int64]bool, +) error { + for nodeID, resp := range allNodesResp { + if len(resp.MergeOperators) == 0 { + continue + } + + for _, mergeReq := range resp.MergeOperators { + if mergeReq == nil || mergeReq.MergedDispatcherID == nil { + continue + } + if len(mergeReq.DispatcherIDs) < 2 { + log.Warn("merge operator has insufficient dispatcher IDs", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String())) + continue + } + + tableSplitMap, ok := tableSplitMapForMode(mergeReq.Mode, tableSplitMaps) + if !ok { + log.Warn("skip restoring merge operator due to unavailable mode", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.Int64("mode", mergeReq.Mode)) + continue + } + spanController := c.getSpanController(mergeReq.Mode) + operatorController := c.getOperatorController(mergeReq.Mode) + if spanController == nil || operatorController == nil { + log.Warn("skip restoring merge operator due to uninitialized controller", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.Int64("mode", mergeReq.Mode)) + continue + } + spanInfoByID := indexBootstrapSpans(resp.Spans, mergeReq.Mode) + mergedDispatcherID := common.NewDispatcherIDFromPB(mergeReq.MergedDispatcherID) + if mergedDispatcherID.IsZero() { + log.Warn("skip restoring merge operator due to invalid merged dispatcher ID", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.Int64("mode", mergeReq.Mode)) + continue + } + + sourceReplicaSets := make([]*replica.SpanReplication, 0, len(mergeReq.DispatcherIDs)) + createdSourceReplicaSets := make([]*replica.SpanReplication, 0, len(mergeReq.DispatcherIDs)) + cleanupCreatedSourceReplicaSets := func() { + for _, replicaSet := range createdSourceReplicaSets { + spanController.RemoveReplicatingSpan(replicaSet) + } + } + sourceComplete := true + skipMerge := false + seenSources := make(map[common.DispatcherID]struct{}, len(mergeReq.DispatcherIDs)) + for _, idPB := range mergeReq.DispatcherIDs { + if idPB == nil { + sourceComplete = false + break + } + dispatcherID := common.NewDispatcherIDFromPB(idPB) + if dispatcherID.IsZero() { + sourceComplete = false + break + } + if _, ok := seenSources[dispatcherID]; ok { + continue + } + seenSources[dispatcherID] = struct{}{} + + replicaSet := spanController.GetTaskByID(dispatcherID) + if replicaSet == nil { + spanInfo := spanInfoByID[dispatcherID] + if spanInfo == nil || spanInfo.Span == nil { + sourceComplete = false + break + } + splitable, tableExists := tableSplitMap[spanInfo.Span.TableID] + if !tableExists { + log.Warn("skip restoring merge operator because source table is missing from schema snapshot", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", dispatcherID.String()), + zap.Int64("tableID", spanInfo.Span.TableID), + zap.Int64("mode", mergeReq.Mode)) + skipMerge = true + break + } + splitEnabled := spanController.ShouldEnableSplit(splitable) + replicaSet = c.createSpanReplication(spanInfo, nodeID, splitEnabled) + spanController.AddReplicatingSpan(replicaSet) + createdSourceReplicaSets = append(createdSourceReplicaSets, replicaSet) + } else if replicaSet.Span == nil { + sourceComplete = false + break + } else if _, tableExists := tableSplitMap[replicaSet.Span.TableID]; !tableExists { + log.Warn("skip restoring merge operator because source table is missing from schema snapshot", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", dispatcherID.String()), + zap.Int64("tableID", replicaSet.Span.TableID), + zap.Int64("mode", mergeReq.Mode)) + skipMerge = true + break + } + sourceReplicaSets = append(sourceReplicaSets, replicaSet) + } + if skipMerge { + cleanupCreatedSourceReplicaSets() + continue + } + + mergedSpanInfo := spanInfoByID[mergedDispatcherID] + mergedReplicaSet := spanController.GetTaskByID(mergedDispatcherID) + if mergedSpanInfo != nil { + if mergedSpanInfo.Span == nil { + log.Warn("skip restoring merge operator because merged span is missing", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Int64("mode", mergeReq.Mode)) + cleanupCreatedSourceReplicaSets() + continue + } + if _, tableExists := tableSplitMap[mergedSpanInfo.Span.TableID]; !tableExists { + log.Warn("skip restoring merge operator because merged table is missing from schema snapshot", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Int64("tableID", mergedSpanInfo.Span.TableID), + zap.Int64("mode", mergeReq.Mode)) + cleanupCreatedSourceReplicaSets() + continue + } + } + if mergedReplicaSet != nil && mergedReplicaSet.Span != nil { + if _, tableExists := tableSplitMap[mergedReplicaSet.Span.TableID]; !tableExists { + log.Warn("skip restoring merge operator because merged table is missing from schema snapshot", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Int64("tableID", mergedReplicaSet.Span.TableID), + zap.Int64("mode", mergeReq.Mode)) + cleanupCreatedSourceReplicaSets() + continue + } + } + + conflictingDispatcherID, conflictingOperatorType, hasConflict := findBootstrapMergeOperatorConflict(operatorController, sourceReplicaSets, mergedDispatcherID) + if hasConflict { + // Regular create/remove recovery has higher priority than a merge journal because it + // represents a later concrete action for the same dispatcher. Treat the merge record + // as stale instead of failing the entire bootstrap. + log.Warn("skip restoring stale merge operator due to conflicting bootstrap operator", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", conflictingDispatcherID.String()), + zap.String("operatorType", conflictingOperatorType), + zap.String("mergedDispatcher", mergedDispatcherID.String()), + zap.Int64("mode", mergeReq.Mode)) + c.reconcileUnrestorableBootstrapMerge( + mergedReplicaSet, + mergedSpanInfo, + sourceReplicaSets, + ) + continue + } + + if mergedSpanInfo != nil && mergedSpanInfo.ComponentStatus == heartbeatpb.ComponentState_Working { + if mergedReplicaSet == nil { + splitEnabled := spanController.ShouldEnableSplit(tableSplitMap[mergedSpanInfo.Span.TableID]) + mergedReplicaSet = c.createSpanReplication(mergedSpanInfo, nodeID, splitEnabled) + spanController.AddReplicatingSpan(mergedReplicaSet) + } + for _, replicaSet := range sourceReplicaSets { + if mergedReplicaSet != nil && replicaSet.ID == mergedReplicaSet.ID { + continue + } + spanController.RemoveReplicatingSpan(replicaSet) + } + if mergedReplicaSet != nil { + spanController.MarkSpanReplicating(mergedReplicaSet) + } + log.Info("merge already finished during bootstrap", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String())) + continue + } + + if !sourceComplete || len(sourceReplicaSets) < 2 { + log.Warn("skip restoring merge operator due to missing source dispatchers", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String())) + if mergedSpanInfo != nil && + isCommittedMergeTargetState(mergedSpanInfo.ComponentStatus) { + if mergedReplicaSet == nil { + splitEnabled := spanController.ShouldEnableSplit(tableSplitMap[mergedSpanInfo.Span.TableID]) + mergedReplicaSet = c.createSpanReplication(mergedSpanInfo, nodeID, splitEnabled) + spanController.AddReplicatingSpan(mergedReplicaSet) + } else { + spanController.MarkSpanReplicating(mergedReplicaSet) + } + // Initializing is the merge commit point: the target has a real startTs and sources + // are being removed. Keep the committed target and ignore late source terminals. + for _, replicaSet := range sourceReplicaSets { + if replicaSet.ID == mergedReplicaSet.ID { + continue + } + spanController.RemoveReplicatingSpan(replicaSet) + } + log.Info("continue merge from existing merged dispatcher after source loss", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Any("status", mergedSpanInfo.ComponentStatus)) + continue + } + if mergedReplicaSet != nil { + // Preparing and MergeReady are still abortable. Dispatcher manager restores surviving + // sources and removes the target when any source is missing, so maintainer must not + // promote the target into permanent desired state. Keep it only as temporary coverage + // until the cleanup operator observes a terminal status. + c.addBootstrapCleanupOperator(mergedReplicaSet) + targetStatus, _ := bootstrapMergeTargetStatus(mergedSpanInfo, mergedReplicaSet) + log.Info("abort incomplete merge from uncommitted merged dispatcher", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Any("status", targetStatus)) + continue + } + // Without a merged dispatcher snapshot, a merge journal with missing sources is stale + // and cannot be driven by any restored operator. Leave the surviving source spans in + // their bootstrap state so normal scheduling can repair any uncovered table ranges. + cleanupCreatedSourceReplicaSets() + continue + } + + sort.Slice(sourceReplicaSets, func(i, j int) bool { + return bytes.Compare(sourceReplicaSets[i].Span.StartKey, sourceReplicaSets[j].Span.StartKey) < 0 + }) + + if mergedReplicaSet == nil { + if mergedSpanInfo != nil { + splitEnabled := spanController.ShouldEnableSplit(tableSplitMap[mergedSpanInfo.Span.TableID]) + mergedReplicaSet = c.createSpanReplication(mergedSpanInfo, nodeID, splitEnabled) + spanController.AddSchedulingReplicaSet(mergedReplicaSet, nodeID) + } else { + mergedSpan, schemaID, checkpointTs, ok := buildMergedSpanFromReplicas(sourceReplicaSets) + if !ok { + log.Warn("skip restoring merge operator due to invalid merge spans", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String())) + cleanupCreatedSourceReplicaSets() + continue + } + splitEnabled := spanController.ShouldEnableSplit(tableSplitMap[mergedSpan.TableID]) + status := &heartbeatpb.TableSpanStatus{ + ID: mergedDispatcherID.ToPB(), + CheckpointTs: checkpointTs, + Mode: mergeReq.Mode, + ComponentStatus: heartbeatpb.ComponentState_Preparing, + } + mergedReplicaSet = replica.NewWorkingSpanReplication( + c.changefeedID, + mergedDispatcherID, + schemaID, + mergedSpan, + status, + nodeID, + splitEnabled, + ) + spanController.AddSchedulingReplicaSet(mergedReplicaSet, nodeID) + } + } + + if mergedReplicaSet == nil { + log.Warn("merge replica set not found when restoring merge", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String())) + continue + } + + if operatorController.AddRestoredMergeOperator(sourceReplicaSets, mergedReplicaSet) == nil { + log.Warn("skip stale merge operator that cannot be restored", + zap.String("nodeID", nodeID.String()), + zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Any("mergedReplicaSet", mergedReplicaSet), + zap.Any("toMergedReplicaSets", sourceReplicaSets)) + c.reconcileUnrestorableBootstrapMerge( + mergedReplicaSet, + mergedSpanInfo, + sourceReplicaSets, + ) + continue + } + spanController.MarkSpanScheduling(mergedReplicaSet) + } + } + return nil +} + +// bootstrapMergeTargetStatus reads the most concrete target state available during restoration. +func bootstrapMergeTargetStatus( + mergedSpanInfo *heartbeatpb.BootstrapTableSpan, + mergedReplicaSet *replica.SpanReplication, +) (heartbeatpb.ComponentState, bool) { + if mergedSpanInfo != nil { + return mergedSpanInfo.ComponentStatus, true + } + if mergedReplicaSet != nil && mergedReplicaSet.GetStatus() != nil { + return mergedReplicaSet.GetStatus().ComponentStatus, true + } + return heartbeatpb.ComponentState_Working, false +} + +// reconcileUnrestorableBootstrapMerge selects the survivor according to the merge commit point. +func (c *Controller) reconcileUnrestorableBootstrapMerge( + mergedReplicaSet *replica.SpanReplication, + mergedSpanInfo *heartbeatpb.BootstrapTableSpan, + sourceReplicaSets []*replica.SpanReplication, +) { + if mergedReplicaSet == nil { + return + } + targetStatus, hasStatus := bootstrapMergeTargetStatus(mergedSpanInfo, mergedReplicaSet) + spanController := c.getSpanController(mergedReplicaSet.GetMode()) + if spanController == nil { + return + } + if hasStatus && isCommittedMergeTargetState(targetStatus) { + if spanController.GetTaskByID(mergedReplicaSet.ID) == nil { + spanController.AddReplicatingSpan(mergedReplicaSet) + } else { + spanController.MarkSpanReplicating(mergedReplicaSet) + } + for _, replicaSet := range sourceReplicaSets { + if replicaSet == nil || replicaSet.ID == mergedReplicaSet.ID { + continue + } + spanController.RemoveReplicatingSpan(replicaSet) + } + return + } + c.addBootstrapCleanupOperator(mergedReplicaSet) +} + +func findBootstrapMergeOperatorConflict( + operatorController *operator.Controller, + sourceReplicaSets []*replica.SpanReplication, + mergedDispatcherID common.DispatcherID, +) (common.DispatcherID, string, bool) { + if op := operatorController.GetOperator(mergedDispatcherID); op != nil { + return mergedDispatcherID, op.Type(), true + } + for _, replicaSet := range sourceReplicaSets { + if replicaSet == nil { + continue + } + if op := operatorController.GetOperator(replicaSet.ID); op != nil { + return replicaSet.ID, op.Type(), true + } + } + return common.DispatcherID{}, "", false +} + +func tableSplitMapForMode( + mode int64, + tableSplitMaps map[int64]map[int64]bool, +) (map[int64]bool, bool) { + if common.IsRedoMode(mode) { + tableSplitMap, ok := tableSplitMaps[common.RedoMode] + return tableSplitMap, ok + } + tableSplitMap, ok := tableSplitMaps[common.DefaultMode] + return tableSplitMap, ok +} + +// buildMergedSpanFromReplicas synthesizes the merged span shape from consecutive source replica sets. +func buildMergedSpanFromReplicas( + replicaSets []*replica.SpanReplication, +) (*heartbeatpb.TableSpan, int64, uint64, bool) { + if len(replicaSets) < 2 { + return nil, 0, 0, false + } + first := replicaSets[0] + if first == nil || first.Span == nil { + return nil, 0, 0, false + } + + tableID := first.Span.TableID + keyspaceID := first.Span.KeyspaceID + schemaID := first.GetSchemaID() + nodeID := first.GetNodeID() + startKey := first.Span.StartKey + endKey := first.Span.EndKey + firstStatus := first.GetStatus() + if firstStatus == nil { + return nil, 0, 0, false + } + minCheckpoint := firstStatus.CheckpointTs + prevSpan := first.Span + for idx := 1; idx < len(replicaSets); idx++ { + replicaSet := replicaSets[idx] + if replicaSet == nil || replicaSet.Span == nil { + return nil, 0, 0, false + } + if replicaSet.Span.TableID != tableID || + replicaSet.Span.KeyspaceID != keyspaceID || + replicaSet.GetSchemaID() != schemaID || + replicaSet.GetNodeID() != nodeID { + return nil, 0, 0, false + } + if !common.IsTableSpanConsecutive(prevSpan, replicaSet.Span) { + return nil, 0, 0, false + } + status := replicaSet.GetStatus() + if status == nil { + return nil, 0, 0, false + } + if checkpoint := status.CheckpointTs; checkpoint < minCheckpoint { + minCheckpoint = checkpoint + } + prevSpan = replicaSet.Span + endKey = replicaSet.Span.EndKey + } + + return &heartbeatpb.TableSpan{ + TableID: tableID, + StartKey: startKey, + EndKey: endKey, + KeyspaceID: keyspaceID, + }, schemaID, minCheckpoint, true +} diff --git a/maintainer/maintainer_controller_test.go b/maintainer/maintainer_controller_test.go index 56327458bc..fc0102659f 100644 --- a/maintainer/maintainer_controller_test.go +++ b/maintainer/maintainer_controller_test.go @@ -1614,6 +1614,653 @@ func TestFinishBootstrapSkipsStaleCreateOperatorForDroppedTable(t *testing.T) { } } +// TestFinishBootstrapRepairsCoverageAfterRestoredStandaloneRemove covers failover after an +// orphan Working dispatcher has already been journaled under a standalone remove request. The +// test restores that request alongside adjacent live coverage, reports one terminal status, and +// finalizes the operator. The removed range must become an exact absent span that the basic +// scheduler can schedule again, while the adjacent dispatcher remains untouched. +func TestFinishBootstrapRepairsCoverageAfterRestoredStandaloneRemove(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + responses := env.bootstrapResponses( + nil, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_Working), + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_Working), + ) + responses[env.nodeID].Operators = []*heartbeatpb.ScheduleDispatcherRequest{ + env.standaloneRemoveRequest(env.sourceDispatcherID1, env.sourceSpan1), + } + + _, err := env.controller.FinishBootstrap(responses, false) + require.NoError(t, err) + require.Equal(t, 2, env.controller.spanController.GetReplicatingSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + restoredRemove := env.controller.operatorController.GetOperator(env.sourceDispatcherID1) + require.NotNil(t, restoredRemove) + require.Equal(t, "remove", restoredRemove.Type()) + + // A single terminal status finishes the restored operator. The same HandleStatus call still + // sees the operator, so coverage repair must happen when the controller finalizes it. + env.controller.HandleStatus(env.nodeID, []*heartbeatpb.TableSpanStatus{ + { + ID: env.sourceDispatcherID1.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Stopped, + CheckpointTs: 10, + Mode: common.DefaultMode, + }, + }) + require.True(t, restoredRemove.IsFinished()) + require.NotNil(t, env.controller.operatorController.GetOperator(env.sourceDispatcherID1)) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + env.controller.operatorController.Execute() + + require.Nil(t, env.controller.operatorController.GetOperator(env.sourceDispatcherID1)) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID2)) + require.Equal(t, 1, env.controller.spanController.GetReplicatingSize()) + require.Equal(t, 1, env.controller.spanController.GetAbsentSize()) + + var repairedSpan *replica.SpanReplication + for _, task := range env.controller.spanController.GetTasksByTableID(env.sourceSpan1.TableID) { + if task.ID != env.sourceDispatcherID2 { + repairedSpan = task + break + } + } + require.NotNil(t, repairedSpan) + require.Equal(t, env.sourceSpan1.StartKey, repairedSpan.Span.StartKey) + require.Equal(t, env.sourceSpan1.EndKey, repairedSpan.Span.EndKey) + + env.controller.schedulerController.GetScheduler(scheduler.BasicScheduler).Execute() + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.Equal(t, 1, env.controller.spanController.GetSchedulingSize()) + addOp := env.controller.operatorController.GetOperator(repairedSpan.ID) + require.NotNil(t, addOp) + require.Equal(t, "add", addOp.Type()) +} + +// TestFinishBootstrapDoesNotRepairDroppedTableAfterRestoredStandaloneRemove covers the same +// restored remove lifecycle after the table has disappeared from the schema snapshot. The test +// reports the stale runtime dispatcher and its remove journal, finishes that operator with one +// terminal status, and verifies finalization never recreates desired state for the dropped table. +func TestFinishBootstrapDoesNotRepairDroppedTableAfterRestoredStandaloneRemove(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + schemaStore := eventservice.NewMockSchemaStore() + schemaStore.SetTables(nil) + appcontext.SetService(appcontext.SchemaStore, schemaStore) + + responses := env.bootstrapResponses( + nil, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_Working), + ) + responses[env.nodeID].Operators = []*heartbeatpb.ScheduleDispatcherRequest{ + env.standaloneRemoveRequest(env.sourceDispatcherID1, env.sourceSpan1), + } + + _, err := env.controller.FinishBootstrap(responses, false) + require.NoError(t, err) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.Zero(t, env.controller.spanController.GetReplicatingSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + restoredRemove := env.controller.operatorController.GetOperator(env.sourceDispatcherID1) + require.NotNil(t, restoredRemove) + env.controller.HandleStatus(env.nodeID, []*heartbeatpb.TableSpanStatus{ + { + ID: env.sourceDispatcherID1.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Removed, + CheckpointTs: 10, + Mode: common.DefaultMode, + }, + }) + require.True(t, restoredRemove.IsFinished()) + + env.controller.operatorController.Execute() + + require.Nil(t, env.controller.operatorController.GetOperator(env.sourceDispatcherID1)) + require.Empty(t, env.controller.spanController.GetTasksByTableID(env.sourceSpan1.TableID)) + require.Zero(t, env.controller.spanController.GetReplicatingSize()) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) +} + +// TestFinishBootstrapRestoresInFlightMergeWithoutDuplicateCoverage covers maintainer failover in +// the middle of a merge. The bootstrap snapshot contains two source spans in WaitingMerge and the +// overlapping merged target span in Preparing. FinishBootstrap must not panic in findHoles or +// create a fresh absent table task; instead it should rebuild the merge-related tasks/operators +// from the bootstrap snapshot. +func TestFinishBootstrapRestoresInFlightMergeWithoutDuplicateCoverage(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + []*heartbeatpb.MergeDispatcherRequest{env.mergeRequest()}, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, heartbeatpb.ComponentState_Preparing), + ), false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + + // No extra absent table span should be created during bootstrap; only the two source spans and + // the restored merged target should exist. + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.Equal(t, 3, len(env.controller.spanController.GetTasksByTableID(1))) + require.Equal(t, 3, env.controller.spanController.GetSchedulingSize()) + require.Zero(t, env.controller.spanController.GetReplicatingSize()) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID2)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + + mergeOp := env.controller.operatorController.GetOperator(env.mergedDispatcherID) + require.NotNil(t, mergeOp) + _, ok := mergeOp.(*operator.MergeDispatcherOperator) + require.True(t, ok) +} + +// TestFinishBootstrapKeepsOverlapCoveredAfterMergeJournalCleanup covers a later merge-recovery +// window where dispatcher manager has already committed the merged dispatcher and dropped the merge +// journal, but the old source dispatchers are still waiting to be cleaned up. Bootstrap must still +// treat the overlapping spans as complete coverage and avoid creating absent hole tasks. +func TestFinishBootstrapKeepsOverlapCoveredAfterMergeJournalCleanup(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + + // Scenario: + // 1. Source dispatchers are already in WaitingMerge and still present in bootstrap spans. + // 2. The merged dispatcher is committed and visible as Initializing. + // 3. The persisted merge operator is already gone, so bootstrap only has overlapping coverage. + // Expectation: FinishBootstrap succeeds without adding absent spans for fake holes. + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + nil, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, heartbeatpb.ComponentState_Initializing), + ), false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.GreaterOrEqual(t, len(env.controller.spanController.GetTasksByTableID(1)), 2) + require.GreaterOrEqual(t, env.controller.spanController.GetReplicatingSize(), 2) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) +} + +// TestFinishBootstrapRemovesUnexpectedOverlappingWorkingSpan covers a corrupt bootstrap snapshot +// with two partially overlapping Working dispatchers and no operator or merge evidence. The test +// keeps the conflicting dispatcher as temporary coverage under a remove operator, confirms no +// replacement is scheduled early, then repairs the uncovered tail after removal reaches terminal. +func TestFinishBootstrapRemovesUnexpectedOverlappingWorkingSpan(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + overlapStart := appendNew(env.mergedSpan.StartKey, 'a') + keptEnd := appendNew(env.mergedSpan.StartKey, 'b') + keptSpan := &heartbeatpb.TableSpan{ + TableID: env.mergedSpan.TableID, + StartKey: env.mergedSpan.StartKey, + EndKey: keptEnd, + KeyspaceID: env.mergedSpan.KeyspaceID, + } + rejectedSpan := &heartbeatpb.TableSpan{ + TableID: env.mergedSpan.TableID, + StartKey: overlapStart, + EndKey: env.mergedSpan.EndKey, + KeyspaceID: env.mergedSpan.KeyspaceID, + } + keptDispatcherID := common.NewDispatcherID() + rejectedDispatcherID := common.NewDispatcherID() + + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + nil, + env.bootstrapSpan(keptDispatcherID, keptSpan, heartbeatpb.ComponentState_Working), + env.bootstrapSpan(rejectedDispatcherID, rejectedSpan, heartbeatpb.ComponentState_Working), + ), false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + require.NotNil(t, env.controller.spanController.GetTaskByID(keptDispatcherID)) + require.NotNil(t, env.controller.spanController.GetTaskByID(rejectedDispatcherID)) + require.Equal(t, 2, env.controller.spanController.GetReplicatingSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + removeOp := env.controller.operatorController.GetOperator(rejectedDispatcherID) + require.NotNil(t, removeOp) + require.Equal(t, "remove", removeOp.Type()) + env.controller.schedulerController.GetScheduler(scheduler.BasicScheduler).Execute() + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + // The cleanup owner waits for a terminal status before dropping temporary coverage and + // creating the exact replacement range. + removeOp.Check(env.nodeID, &heartbeatpb.TableSpanStatus{ + ID: rejectedDispatcherID.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Stopped, + CheckpointTs: 10, + Mode: common.DefaultMode, + }) + require.True(t, removeOp.IsFinished()) + removeOp.PostFinish() + env.controller.operatorController.RemoveOp(rejectedDispatcherID) + + require.Nil(t, env.controller.spanController.GetTaskByID(rejectedDispatcherID)) + require.Equal(t, 1, env.controller.spanController.GetReplicatingSize()) + require.Equal(t, 1, env.controller.spanController.GetAbsentSize()) + + var repairedTail *replica.SpanReplication + for _, task := range env.controller.spanController.GetTasksByTableID(env.mergedSpan.TableID) { + if task.ID != keptDispatcherID { + repairedTail = task + break + } + } + require.NotNil(t, repairedTail) + require.Equal(t, keptEnd, repairedTail.Span.StartKey) + require.Equal(t, env.mergedSpan.EndKey, repairedTail.Span.EndKey) +} + +// TestFinishBootstrapHandlesMissingMergeSource covers failover after one source disappears. +// Each subtest reports the surviving source and merge journal, optionally reports a target, +// runs bootstrap, and verifies that the merge commit point selects the correct survivor or owner. +func TestFinishBootstrapHandlesMissingMergeSource(t *testing.T) { + type recoveryOutcome int + const ( + skipStaleJournal recoveryOutcome = iota + abortUncommittedTarget + continueCommittedTarget + ) + testCases := []struct { + name string + includeTarget bool + targetStatus heartbeatpb.ComponentState + outcome recoveryOutcome + }{ + // With no target snapshot, the stale journal cannot drive recovery and the surviving source stays active. + {name: "target absent", outcome: skipStaleJournal}, + // Preparing and MergeReady are before the commit point, so the target remains temporary coverage until terminal. + { + name: heartbeatpb.ComponentState_Preparing.String(), + includeTarget: true, + targetStatus: heartbeatpb.ComponentState_Preparing, + outcome: abortUncommittedTarget, + }, + { + name: heartbeatpb.ComponentState_MergeReady.String(), + includeTarget: true, + targetStatus: heartbeatpb.ComponentState_MergeReady, + outcome: abortUncommittedTarget, + }, + // Initializing is the commit point, so bootstrap keeps the target and discards the surviving source. + { + name: heartbeatpb.ComponentState_Initializing.String(), + includeTarget: true, + targetStatus: heartbeatpb.ComponentState_Initializing, + outcome: continueCommittedTarget, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + spans := []*heartbeatpb.BootstrapTableSpan{ + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_WaitingMerge), + } + if tc.includeTarget { + spans = append(spans, env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, tc.targetStatus)) + } + + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + []*heartbeatpb.MergeDispatcherRequest{env.mergeRequest()}, + spans..., + ), false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + + switch tc.outcome { + case skipStaleJournal: + require.Zero(t, env.controller.operatorController.OperatorSize()) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + sourceReplicaSet := env.controller.spanController.GetTaskByID(env.sourceDispatcherID1) + require.NotNil(t, sourceReplicaSet) + require.True(t, env.controller.spanController.IsReplicating(sourceReplicaSet)) + require.Nil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + case abortUncommittedTarget: + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + + // Dispatcher manager aborts pre-commit merges, so terminal target cleanup must + // release temporary coverage before span repair creates the missing range. + removeOp := env.controller.operatorController.GetOperator(env.mergedDispatcherID) + require.NotNil(t, removeOp) + require.Equal(t, "remove", removeOp.Type()) + removeOp.Check(env.nodeID, &heartbeatpb.TableSpanStatus{ + ID: env.mergedDispatcherID.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Stopped, + CheckpointTs: 10, + Mode: common.DefaultMode, + }) + require.True(t, removeOp.IsFinished()) + removeOp.PostFinish() + env.controller.operatorController.RemoveOp(env.mergedDispatcherID) + + require.Nil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.Equal(t, 1, env.controller.spanController.GetReplicatingSize()) + require.Equal(t, 1, env.controller.spanController.GetAbsentSize()) + case continueCommittedTarget: + require.Zero(t, env.controller.operatorController.OperatorSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + require.Equal(t, 1, env.controller.spanController.GetReplicatingSize()) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID2)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + + // A later target heartbeat should update the committed replica directly without an add operator. + env.controller.HandleStatus(env.nodeID, []*heartbeatpb.TableSpanStatus{ + { + ID: env.mergedDispatcherID.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Working, + CheckpointTs: 20, + Mode: common.DefaultMode, + }, + }) + mergedReplicaSet := env.controller.spanController.GetTaskByID(env.mergedDispatcherID) + require.NotNil(t, mergedReplicaSet) + require.Equal(t, heartbeatpb.ComponentState_Working, mergedReplicaSet.GetStatus().ComponentStatus) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + require.Equal(t, 1, env.controller.spanController.GetReplicatingSize()) + default: + require.FailNow(t, "unknown recovery outcome") + } + }) + } +} + +// TestFinishBootstrapRejectsInvalidMergeJournalGeometry covers a stale journal whose source spans +// are not consecutive. Bootstrap must not use dispatcher IDs alone as overlap proof; it removes the +// uncommitted target and creates only the real source gap after the target reaches terminal. +func TestFinishBootstrapRejectsInvalidMergeJournalGeometry(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + gapEnd := appendNew(env.sourceSpan1.EndKey, 'b') + env.sourceSpan2.StartKey = gapEnd + + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + []*heartbeatpb.MergeDispatcherRequest{env.mergeRequest()}, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, heartbeatpb.ComponentState_Preparing), + ), false) + require.NoError(t, err) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + + removeOp := env.controller.operatorController.GetOperator(env.mergedDispatcherID) + require.NotNil(t, removeOp) + require.Equal(t, "remove", removeOp.Type()) + removeOp.Check(env.nodeID, &heartbeatpb.TableSpanStatus{ + ID: env.mergedDispatcherID.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Removed, + CheckpointTs: 10, + Mode: common.DefaultMode, + }) + require.True(t, removeOp.IsFinished()) + removeOp.PostFinish() + env.controller.operatorController.RemoveOp(env.mergedDispatcherID) + + require.Nil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.NotNil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID2)) + require.Equal(t, 2, env.controller.spanController.GetReplicatingSize()) + require.Equal(t, 1, env.controller.spanController.GetAbsentSize()) +} + +type mergeBootstrapTestEnv struct { + controller *Controller + cfID common.ChangeFeedID + nodeID node.ID + sourceSpan1 *heartbeatpb.TableSpan + sourceSpan2 *heartbeatpb.TableSpan + mergedSpan *heartbeatpb.TableSpan + sourceDispatcherID1 common.DispatcherID + sourceDispatcherID2 common.DispatcherID + mergedDispatcherID common.DispatcherID +} + +func newMergeBootstrapTestEnv(t *testing.T) *mergeBootstrapTestEnv { + t.Helper() + + testutil.SetUpTestServices(t) + nodeManager := appcontext.GetService[*watcher.NodeManager](watcher.NodeManagerName) + nodeID := node.ID("node1") + nodeManager.GetAliveNodes()[nodeID] = &node.Info{ID: nodeID} + + tableTriggerEventDispatcherID := common.NewDispatcherID() + cfID := common.NewChangeFeedIDWithName("test", common.DefaultKeyspaceName) + ddlSpan := replica.NewWorkingSpanReplication(cfID, tableTriggerEventDispatcherID, + common.DDLSpanSchemaID, + common.KeyspaceDDLSpan(common.DefaultKeyspaceID), &heartbeatpb.TableSpanStatus{ + ID: tableTriggerEventDispatcherID.ToPB(), + ComponentStatus: heartbeatpb.ComponentState_Working, + CheckpointTs: 1, + }, nodeID, false) + + cfg := config.GetDefaultReplicaConfig().Clone() + cfg.Scheduler = &config.ChangefeedSchedulerConfig{ + EnableTableAcrossNodes: util.AddressOf(true), + BalanceScoreThreshold: util.AddressOf(1), + MinTrafficPercentage: util.AddressOf(0.8), + MaxTrafficPercentage: util.AddressOf(1.2), + } + refresher := replica.NewRegionCountRefresher(cfID, time.Minute) + controller := NewController(cfID, 1, &mockThreadPool{}, cfg, ddlSpan, nil, 1000, 0, refresher, common.DefaultKeyspace, false, testBalanceMoveBatchSize, 0) + + schemaStore := eventservice.NewMockSchemaStore() + schemaStore.SetTables([]commonEvent.Table{ + { + TableID: 1, + SchemaID: 1, + Splitable: true, + SchemaTableName: &commonEvent.SchemaTableName{SchemaName: "test", TableName: "t1"}, + }, + }) + appcontext.SetService(appcontext.SchemaStore, schemaStore) + + totalSpan := common.TableIDToComparableSpan(common.DefaultKeyspaceID, 1) + midKey := appendNew(totalSpan.StartKey, 'a') + return &mergeBootstrapTestEnv{ + controller: controller, + cfID: cfID, + nodeID: nodeID, + sourceSpan1: &heartbeatpb.TableSpan{ + TableID: 1, + StartKey: totalSpan.StartKey, + EndKey: midKey, + KeyspaceID: common.DefaultKeyspaceID, + }, + sourceSpan2: &heartbeatpb.TableSpan{ + TableID: 1, + StartKey: midKey, + EndKey: totalSpan.EndKey, + KeyspaceID: common.DefaultKeyspaceID, + }, + mergedSpan: &heartbeatpb.TableSpan{ + TableID: 1, + StartKey: totalSpan.StartKey, + EndKey: totalSpan.EndKey, + KeyspaceID: common.DefaultKeyspaceID, + }, + sourceDispatcherID1: common.NewDispatcherID(), + sourceDispatcherID2: common.NewDispatcherID(), + mergedDispatcherID: common.NewDispatcherID(), + } +} + +// bootstrapSpan keeps the invariant schema, checkpoint, and mode fields out of +// individual scenarios while leaving the dispatcher, range, and state explicit. +func (env *mergeBootstrapTestEnv) bootstrapSpan( + dispatcherID common.DispatcherID, + span *heartbeatpb.TableSpan, + state heartbeatpb.ComponentState, +) *heartbeatpb.BootstrapTableSpan { + return &heartbeatpb.BootstrapTableSpan{ + ID: dispatcherID.ToPB(), + SchemaID: 1, + Span: span, + ComponentStatus: state, + CheckpointTs: 10, + Mode: common.DefaultMode, + } +} + +// mergeRequest builds the canonical two-source merge journal used by recovery scenarios. +func (env *mergeBootstrapTestEnv) mergeRequest() *heartbeatpb.MergeDispatcherRequest { + return &heartbeatpb.MergeDispatcherRequest{ + ChangefeedID: env.cfID.ToPB(), + DispatcherIDs: []*heartbeatpb.DispatcherID{ + env.sourceDispatcherID1.ToPB(), + env.sourceDispatcherID2.ToPB(), + }, + MergedDispatcherID: env.mergedDispatcherID.ToPB(), + Mode: common.DefaultMode, + } +} + +// standaloneRemoveRequest builds the canonical remove journal used by bootstrap recovery tests. +func (env *mergeBootstrapTestEnv) standaloneRemoveRequest( + dispatcherID common.DispatcherID, + span *heartbeatpb.TableSpan, +) *heartbeatpb.ScheduleDispatcherRequest { + return &heartbeatpb.ScheduleDispatcherRequest{ + ChangefeedID: env.cfID.ToPB(), + Config: &heartbeatpb.DispatcherConfig{ + DispatcherID: dispatcherID.ToPB(), + SchemaID: 1, + Span: span, + StartTs: 10, + Mode: common.DefaultMode, + }, + ScheduleAction: heartbeatpb.ScheduleAction_Remove, + OperatorType: heartbeatpb.OperatorType_O_Remove, + } +} + +// bootstrapResponses builds the single-node snapshot while keeping merge-journal +// presence explicit at each call site because it changes the recovery path. +func (env *mergeBootstrapTestEnv) bootstrapResponses( + mergeOperators []*heartbeatpb.MergeDispatcherRequest, + spans ...*heartbeatpb.BootstrapTableSpan, +) map[node.ID]*heartbeatpb.MaintainerBootstrapResponse { + return map[node.ID]*heartbeatpb.MaintainerBootstrapResponse{ + env.nodeID: { + ChangefeedID: env.cfID.ToPB(), + Spans: spans, + MergeOperators: mergeOperators, + CheckpointTs: 10, + }, + } +} + +// TestFinishBootstrapSkipsMergeOperatorForDroppedTable covers failover after a DROP TABLE +// while dispatcher manager still reports an in-flight merge journal. The test boots from an +// empty schema snapshot, feeds source and merged dispatcher snapshots plus the stale merge +// request, and expects bootstrap to skip restoring ghost table tasks/operators. +func TestFinishBootstrapSkipsMergeOperatorForDroppedTable(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + + schemaStore := eventservice.NewMockSchemaStore() + schemaStore.SetTables(nil) + appcontext.SetService(appcontext.SchemaStore, schemaStore) + + _, err := env.controller.FinishBootstrap(env.bootstrapResponses( + []*heartbeatpb.MergeDispatcherRequest{env.mergeRequest()}, + env.bootstrapSpan(env.sourceDispatcherID1, env.sourceSpan1, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, heartbeatpb.ComponentState_Preparing), + ), false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + require.Zero(t, env.controller.operatorController.OperatorSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + require.Zero(t, env.controller.spanController.GetSchedulingSize()) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID1)) + require.Nil(t, env.controller.spanController.GetTaskByID(env.sourceDispatcherID2)) + require.Nil(t, env.controller.spanController.GetTaskByID(env.mergedDispatcherID)) + require.Empty(t, env.controller.spanController.GetTasksByTableID(env.sourceSpan1.TableID)) +} + +// TestFinishBootstrapSkipsMergeJournalConflictingWithWorkingOperator covers non-atomic bootstrap +// snapshots where a stale merge journal overlaps a newer create or remove request. Each subtest +// restores the regular operator first, then verifies merge recovery yields to it and gives the +// uncommitted merged target a cleanup owner instead of leaving unmanaged overlapping desired state. +func TestFinishBootstrapSkipsMergeJournalConflictingWithWorkingOperator(t *testing.T) { + testCases := []struct { + name string + scheduleAction heartbeatpb.ScheduleAction + operatorType heartbeatpb.OperatorType + includeSourceSnapshot bool + expectedOperatorType string + }{ + { + name: "remove source", + scheduleAction: heartbeatpb.ScheduleAction_Remove, + operatorType: heartbeatpb.OperatorType_O_Remove, + includeSourceSnapshot: true, + expectedOperatorType: "remove", + }, + { + name: "create source", + scheduleAction: heartbeatpb.ScheduleAction_Create, + operatorType: heartbeatpb.OperatorType_O_Add, + expectedOperatorType: "add", + }, + } + + for _, tc := range testCases { + // Scenario: the ordinary operator and merge journal reference the same source dispatcher. + // Steps: restore the ordinary request, process merge snapshots, then ensure the stale journal + // is skipped while the newer create/remove operator remains active. + t.Run(tc.name, func(t *testing.T) { + env := newMergeBootstrapTestEnv(t) + spans := []*heartbeatpb.BootstrapTableSpan{ + env.bootstrapSpan(env.sourceDispatcherID2, env.sourceSpan2, heartbeatpb.ComponentState_WaitingMerge), + env.bootstrapSpan(env.mergedDispatcherID, env.mergedSpan, heartbeatpb.ComponentState_Preparing), + } + if tc.includeSourceSnapshot { + spans = append(spans, env.bootstrapSpan( + env.sourceDispatcherID1, + env.sourceSpan1, + heartbeatpb.ComponentState_WaitingMerge, + )) + } + + responses := env.bootstrapResponses([]*heartbeatpb.MergeDispatcherRequest{env.mergeRequest()}, spans...) + responses[env.nodeID].Operators = []*heartbeatpb.ScheduleDispatcherRequest{ + { + ChangefeedID: env.cfID.ToPB(), + Config: &heartbeatpb.DispatcherConfig{ + DispatcherID: env.sourceDispatcherID1.ToPB(), + SchemaID: 1, + Span: env.sourceSpan1, + StartTs: 10, + Mode: common.DefaultMode, + }, + ScheduleAction: tc.scheduleAction, + OperatorType: tc.operatorType, + }, + } + + _, err := env.controller.FinishBootstrap(responses, false) + require.NoError(t, err) + require.True(t, env.controller.bootstrapped) + + workingOp := env.controller.operatorController.GetOperator(env.sourceDispatcherID1) + require.NotNil(t, workingOp) + require.Equal(t, tc.expectedOperatorType, workingOp.Type()) + mergedCleanupOp := env.controller.operatorController.GetOperator(env.mergedDispatcherID) + require.NotNil(t, mergedCleanupOp) + require.Equal(t, "remove", mergedCleanupOp.Type()) + require.Equal(t, 2, env.controller.operatorController.OperatorSize()) + require.Zero(t, env.controller.spanController.GetAbsentSize()) + }) + } +} + func TestSplitTableWhenBootstrapFinished(t *testing.T) { testutil.SetUpTestServices(t) nodeManager := appcontext.GetService[*watcher.NodeManager](watcher.NodeManagerName) @@ -1759,6 +2406,14 @@ func TestMapFindHole(t *testing.T) { {StartKey: []byte("t1_1"), EndKey: []byte("t2_0")}, }, }, + { // 6. overlapping spans still cover the whole range. + spans: []*heartbeatpb.TableSpan{ + {StartKey: []byte("t1_0"), EndKey: []byte("t1_1")}, + {StartKey: []byte("t1_0"), EndKey: []byte("t2_0")}, + {StartKey: []byte("t1_1"), EndKey: []byte("t2_0")}, + }, + rang: &heartbeatpb.TableSpan{StartKey: []byte("t1_0"), EndKey: []byte("t2_0")}, + }, } for i, cs := range cases { diff --git a/maintainer/operator/operator_controller.go b/maintainer/operator/operator_controller.go index 0158d15f67..46287450a5 100644 --- a/maintainer/operator/operator_controller.go +++ b/maintainer/operator/operator_controller.go @@ -576,6 +576,36 @@ func checkMergeOperator(affectedReplicaSets []*replica.SpanReplication) bool { return true } +// addMergeOccupyOperators reserves every source replica or rolls back the partial reservation. +func (oc *Controller) addMergeOccupyOperators( + affectedReplicaSets []*replica.SpanReplication, +) ([]operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], bool) { + operators := make([]operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], 0, len(affectedReplicaSets)) + for _, replicaSet := range affectedReplicaSets { + occupyOperator := NewOccupyDispatcherOperator(oc.spanController, replicaSet) + if oc.AddOperator(occupyOperator) { + operators = append(operators, occupyOperator) + continue + } + log.Error("failed to add occupy dispatcher operator", + zap.Stringer("changefeedID", oc.changefeedID), + zap.Int64("group", replicaSet.GetGroupID()), + zap.String("span", common.FormatTableSpan(replicaSet.Span)), + zap.String("operator", occupyOperator.String())) + oc.cancelMergeOccupyOperators(operators) + return nil, false + } + return operators, true +} + +func (oc *Controller) cancelMergeOccupyOperators( + operators []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], +) { + for _, op := range operators { + oc.cancelOperator(op.ID()) + } +} + // AddMergeOperator creates a merge operator, which merge consecutive replica sets. // We need create a mergeOperator for the new replicaset, and create len(affectedReplicaSets) empty operator // to occupy these replica set not evolve other scheduling among merging. @@ -586,23 +616,9 @@ func (oc *Controller) AddMergeOperator( return nil } - operators := make([]operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], 0, len(affectedReplicaSets)) - for _, replicaSet := range affectedReplicaSets { - operator := NewOccupyDispatcherOperator(oc.spanController, replicaSet) - ret := oc.AddOperator(operator) - if ret { - operators = append(operators, operator) - } else { - log.Error("failed to add occupy dispatcher operator", - zap.Stringer("changefeedID", oc.changefeedID), - zap.Int64("group", replicaSet.GetGroupID()), - zap.String("span", common.FormatTableSpan(replicaSet.Span)), - zap.String("operator", operator.String())) - for _, op := range operators { - oc.cancelOperator(op.ID()) - } - return nil - } + operators, ok := oc.addMergeOccupyOperators(affectedReplicaSets) + if !ok { + return nil } mergeOperator := NewMergeDispatcherOperator(oc.spanController, affectedReplicaSets, operators, oc.MaintainerEpoch()) @@ -612,9 +628,7 @@ func (oc *Controller) AddMergeOperator( zap.Stringer("changefeedID", oc.changefeedID), zap.Any("mergeSpans", affectedReplicaSets), zap.String("operator", mergeOperator.String())) - for _, op := range operators { - oc.cancelOperator(op.ID()) - } + oc.cancelMergeOccupyOperators(operators) oc.spanController.RemoveReplicatingSpan(mergeOperator.newReplicaSet) return nil } @@ -626,6 +640,47 @@ func (oc *Controller) AddMergeOperator( return mergeOperator } +// AddRestoredMergeOperator rebuilds a merge operator from bootstrap state after maintainer failover. +func (oc *Controller) AddRestoredMergeOperator( + affectedReplicaSets []*replica.SpanReplication, + mergedReplicaSet *replica.SpanReplication, +) operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus] { + if mergedReplicaSet == nil { + return nil + } + if !checkMergeOperator(affectedReplicaSets) { + return nil + } + + operators, ok := oc.addMergeOccupyOperators(affectedReplicaSets) + if !ok { + return nil + } + + mergeOperator := NewRestoredMergeDispatcherOperator( + oc.spanController, + affectedReplicaSets, + mergedReplicaSet, + operators, + oc.MaintainerEpoch(), + ) + ret := oc.AddOperator(mergeOperator) + if !ret { + log.Error("failed to add merge dispatcher operator when restoring merge", + zap.Stringer("changefeedID", oc.changefeedID), + zap.Any("mergeSpans", affectedReplicaSets), + zap.String("operator", mergeOperator.String())) + oc.cancelMergeOccupyOperators(operators) + return nil + } + log.Info("restore merge operator", + zap.String("role", oc.role), + zap.Stringer("changefeedID", oc.changefeedID), + zap.Int("affectedReplicaSets", len(affectedReplicaSets)), + ) + return mergeOperator +} + func (oc *Controller) GetAllOperators() []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus] { oc.mu.RLock() defer oc.mu.RUnlock() diff --git a/maintainer/operator/operator_controller_test.go b/maintainer/operator/operator_controller_test.go index 32f9a77f3f..408b22e407 100644 --- a/maintainer/operator/operator_controller_test.go +++ b/maintainer/operator/operator_controller_test.go @@ -327,11 +327,56 @@ func TestController_AddMergeOperatorFailureCleansOccupyOperators(t *testing.T) { require.Equal(t, 1, oc.OperatorSize()) } +func TestControllerRestoredMergeOperatorSchedule(t *testing.T) { + // Scenario: bootstrap restores an in-flight merge after maintainer failover. + // Steps: restore the merge through the controller, schedule it, and verify the request + // reuses the merged dispatcher ID reported during bootstrap and carries the new epoch. + messageCenter, _, _ := messaging.NewMessageCenterForTest(t) + appcontext.SetService(appcontext.MessageCenter, messageCenter) + + spanController, toMergedReplicaSets, _, nodeA := setupMergeTestEnvironment(t) + nodeManager := appcontext.GetService[*watcher.NodeManager](watcher.NodeManagerName) + setAliveNodes(nodeManager, map[node.ID]*node.Info{nodeA: {ID: nodeA}}) + + const maintainerEpoch = uint64(7) + oc := NewOperatorController(toMergedReplicaSets[0].ChangefeedID, spanController, 1, common.DefaultMode) + oc.SetMaintainerEpoch(maintainerEpoch) + + mergedSpan := &heartbeatpb.TableSpan{ + TableID: toMergedReplicaSets[0].Span.TableID, + StartKey: toMergedReplicaSets[0].Span.StartKey, + EndKey: toMergedReplicaSets[len(toMergedReplicaSets)-1].Span.EndKey, + } + mergedReplicaSet := replica.NewSpanReplication( + toMergedReplicaSets[0].ChangefeedID, + common.NewDispatcherID(), + toMergedReplicaSets[0].GetSchemaID(), + mergedSpan, + toMergedReplicaSets[0].GetStatus().CheckpointTs, + common.DefaultMode, + toMergedReplicaSets[0].IsSplitEnabled(), + ) + spanController.AddSchedulingReplicaSet(mergedReplicaSet, nodeA) + + op := oc.AddRestoredMergeOperator(toMergedReplicaSets, mergedReplicaSet) + require.NotNil(t, op) + msg := op.Schedule() + require.NotNil(t, msg) + + req := msg.Message[0].(*heartbeatpb.MergeDispatcherRequest) + require.Equal(t, mergedReplicaSet.ID.ToPB(), req.MergedDispatcherID) + require.Len(t, req.DispatcherIDs, len(toMergedReplicaSets)) + require.Equal(t, maintainerEpoch, req.MaintainerEpoch) +} + func TestMergeDispatcherOperatorScheduleMaintainerEpoch(t *testing.T) { + // Scenario: a newly scheduled merge must be fenced to its maintainer generation. + // Steps: create and schedule the operator, then verify its request carries the constructor epoch. spanController, toMergedReplicaSets, occupyOperators, _ := setupMergeTestEnvironment(t) op := NewMergeDispatcherOperator(spanController, toMergedReplicaSets, occupyOperators, 7) msg := op.Schedule() + require.NotNil(t, msg) req := msg.Message[0].(*heartbeatpb.MergeDispatcherRequest) require.Equal(t, uint64(7), req.MaintainerEpoch) diff --git a/maintainer/operator/operator_merge.go b/maintainer/operator/operator_merge.go index 300dd5d750..9f0a36532f 100644 --- a/maintainer/operator/operator_merge.go +++ b/maintainer/operator/operator_merge.go @@ -63,11 +63,12 @@ type MergeDispatcherOperator struct { sendThrottler sendThrottler } -func buildMergedSpanInfo(toMergedSpans []*heartbeatpb.TableSpan) string { +func buildMergedSpanInfo(toMergedReplicaSets []*replica.SpanReplication) string { var spansInfo strings.Builder - for _, span := range toMergedSpans { - spansInfo.WriteString(fmt.Sprintf("[%s,%s,%d]", - hex.EncodeToString(span.StartKey), hex.EncodeToString(span.EndKey), span.TableID)) + for _, replicaSet := range toMergedReplicaSets { + span := replicaSet.Span + fmt.Fprintf(&spansInfo, "[%s,%s,%d]", + hex.EncodeToString(span.StartKey), hex.EncodeToString(span.EndKey), span.TableID) } return spansInfo.String() } @@ -98,59 +99,76 @@ func minCheckpointTs(toMergedReplicaSets []*replica.SpanReplication) uint64 { return checkpointTs } -func NewMergeDispatcherOperator( +// newMergeDispatcherOperator initializes state shared by newly scheduled and restored merges. +// Callers remain responsible for creating and registering the merged replica set. +func newMergeDispatcherOperator( spanController *span.Controller, toMergedReplicaSets []*replica.SpanReplication, + mergedReplicaSet *replica.SpanReplication, occupyOperators []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], maintainerEpoch uint64, ) *MergeDispatcherOperator { - toMergedSpans := make([]*heartbeatpb.TableSpan, 0, len(toMergedReplicaSets)) - for _, replicaSet := range toMergedReplicaSets { - toMergedSpans = append(toMergedSpans, replicaSet.Span) + return &MergeDispatcherOperator{ + spanController: spanController, + originNode: toMergedReplicaSets[0].GetNodeID(), + id: mergedReplicaSet.ID, + dispatcherIDs: buildDispatcherIDs(toMergedReplicaSets), + maintainerEpoch: maintainerEpoch, + toMergedReplicaSets: toMergedReplicaSets, + mergedSpanInfo: buildMergedSpanInfo(toMergedReplicaSets), + occupyOperators: occupyOperators, + newReplicaSet: mergedReplicaSet, + sendThrottler: newSendThrottler(), } +} - nodeID := toMergedReplicaSets[0].GetNodeID() +// NewMergeDispatcherOperator creates a merge operator and registers its new target as scheduling. +func NewMergeDispatcherOperator( + spanController *span.Controller, + toMergedReplicaSets []*replica.SpanReplication, + occupyOperators []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], + maintainerEpoch uint64, +) *MergeDispatcherOperator { + firstReplicaSet := toMergedReplicaSets[0] + lastReplicaSet := toMergedReplicaSets[len(toMergedReplicaSets)-1] + nodeID := firstReplicaSet.GetNodeID() newDispatcherID := common.NewDispatcherID() - dispatcherIDs := buildDispatcherIDs(toMergedReplicaSets) - spansInfo := buildMergedSpanInfo(toMergedSpans) - // bind the new replica set to the node. mergeTableSpan := &heartbeatpb.TableSpan{ - TableID: toMergedSpans[0].TableID, - StartKey: toMergedSpans[0].StartKey, - EndKey: toMergedSpans[len(toMergedSpans)-1].EndKey, + TableID: firstReplicaSet.Span.TableID, + StartKey: firstReplicaSet.Span.StartKey, + EndKey: lastReplicaSet.Span.EndKey, KeyspaceID: spanController.GetkeyspaceID(), } checkpointTs := minCheckpointTs(toMergedReplicaSets) newReplicaSet := replica.NewSpanReplication( - toMergedReplicaSets[0].ChangefeedID, + firstReplicaSet.ChangefeedID, newDispatcherID, - toMergedReplicaSets[0].GetSchemaID(), + firstReplicaSet.GetSchemaID(), mergeTableSpan, checkpointTs, - toMergedReplicaSets[0].GetMode(), - toMergedReplicaSets[0].IsSplitEnabled()) + firstReplicaSet.GetMode(), + firstReplicaSet.IsSplitEnabled()) spanController.AddSchedulingReplicaSet(newReplicaSet, nodeID) + return newMergeDispatcherOperator( + spanController, toMergedReplicaSets, newReplicaSet, occupyOperators, maintainerEpoch) +} - op := &MergeDispatcherOperator{ - spanController: spanController, - originNode: nodeID, - id: newDispatcherID, - dispatcherIDs: dispatcherIDs, - maintainerEpoch: maintainerEpoch, - toMergedReplicaSets: toMergedReplicaSets, - checkpointTs: 0, - mergedSpanInfo: spansInfo, - occupyOperators: occupyOperators, - newReplicaSet: newReplicaSet, - sendThrottler: newSendThrottler(), - } - return op +// NewRestoredMergeDispatcherOperator builds a merge operator whose occupy sub-operators were restored from bootstrap. +func NewRestoredMergeDispatcherOperator( + spanController *span.Controller, + toMergedReplicaSets []*replica.SpanReplication, + mergedReplicaSet *replica.SpanReplication, + occupyOperators []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus], + maintainerEpoch uint64, +) *MergeDispatcherOperator { + return newMergeDispatcherOperator( + spanController, toMergedReplicaSets, mergedReplicaSet, occupyOperators, maintainerEpoch) } func setOccupyOperatorsFinished(occupyOperators []operator.Operator[common.DispatcherID, *heartbeatpb.TableSpanStatus]) { diff --git a/tests/integration_tests/_utils/get_table_id b/tests/integration_tests/_utils/get_table_id index cf9a1a0363..7fd050559c 100755 --- a/tests/integration_tests/_utils/get_table_id +++ b/tests/integration_tests/_utils/get_table_id @@ -6,7 +6,7 @@ # parameter 2: table name # parameter 3: retry count -set -ex +set -exo pipefail dbName=${1} tableName=${2} @@ -15,9 +15,9 @@ MAX_RETRIES=5 retries=0 while [ $retries -lt $MAX_RETRIES ]; do - id=$(curl http://127.0.0.1:10080/schema/"${dbName}"/"${tableName}" | jq .id) - if [ -n "$id" ]; then - echo $id + # Follow the configured upstream status endpoint so tests can run against non-default local ports. + if id=$(curl -fsS "http://${UP_TIDB_HOST:-127.0.0.1}:${UP_TIDB_STATUS:-10080}/schema/${dbName}/${tableName}" | jq -er '.id'); then + echo "$id" exit 0 fi retries=$((retries + 1)) diff --git a/tests/integration_tests/maintainer_failover_when_operator/conf/diff_config.toml b/tests/integration_tests/maintainer_failover_when_operator/conf/diff_config.toml index 27d2d57567..7899ec9e3d 100644 --- a/tests/integration_tests/maintainer_failover_when_operator/conf/diff_config.toml +++ b/tests/integration_tests/maintainer_failover_when_operator/conf/diff_config.toml @@ -13,7 +13,7 @@ check-struct-only = false target-instance = "tidb0" - target-check-tables = ["maintainer_failover_when_operator.t1", "maintainer_failover_when_operator.t2", "maintainer_failover_when_operator.t4", "maintainer_failover_when_operator.t5"] + target-check-tables = ["maintainer_failover_when_operator.t1", "maintainer_failover_when_operator.t2", "maintainer_failover_when_operator.t4", "maintainer_failover_when_operator.t5", "maintainer_failover_when_operator.t6"] [data-sources] [data-sources.mysql1] diff --git a/tests/integration_tests/maintainer_failover_when_operator/run.sh b/tests/integration_tests/maintainer_failover_when_operator/run.sh index 06e57003c5..8be0f7020d 100755 --- a/tests/integration_tests/maintainer_failover_when_operator/run.sh +++ b/tests/integration_tests/maintainer_failover_when_operator/run.sh @@ -5,13 +5,14 @@ set -eu # This integration test verifies operator consistency across maintainer failover. # # What it validates: -# - Dispatcher managers persist "in-flight" scheduling requests (Create/Remove with an OperatorType). +# - Dispatcher managers persist "in-flight" scheduling requests (Create/Remove with an OperatorType) +# and merge requests. # - After the maintainer fails over, the new maintainer can restore these unfinished operators from # bootstrap responses and keep table scheduling converging instead of leaking or duplicating dispatchers. # # Main steps (per subcase): # 1) Start a 3-capture CDC cluster and create a changefeed. -# 2) Trigger Move / Split / Remove / Create operators and keep them in-progress using failpoints. +# 2) Trigger Move / Split / Remove / Create / Merge operators and keep them in-progress using failpoints. # 3) Kill the current maintainer capture to force a maintainer move. # 4) Disable failpoints and verify tables eventually converge (scheduled on a live capture, dropped table # stays dropped, and downstream data matches upstream via sync-diff). @@ -25,7 +26,28 @@ ROOT_WORK_DIR=$OUT_DIR/$TEST_NAME CDC_BINARY=cdc.test SINK_TYPE=$1 -CDC_ADDRS=("127.0.0.1:8300" "127.0.0.1:8301" "127.0.0.1:8302") +CDC_ADDRS_OVERRIDE=${CDC_ADDRS_OVERRIDE:-"127.0.0.1:8300 127.0.0.1:8301 127.0.0.1:8302"} +read -r -a CDC_ADDRS <<<"$CDC_ADDRS_OVERRIDE" +if [ "${#CDC_ADDRS[@]}" -ne 3 ]; then + echo "CDC_ADDRS_OVERRIDE must contain exactly 3 addresses" >&2 + exit 1 +fi +# Keep CLI-based helpers (changefeed create/query and move/split/merge operations) pointed at the same +# first capture when the case overrides the CDC addresses for isolated local reruns. The retry helpers +# are separate Bash processes, so export both the server and wrapper functions for them. +export CDC_HOST=${CDC_ADDRS[0]%:*} +export CDC_PORT=${CDC_ADDRS[0]#*:} +export CDC_API_SERVER="http://${CDC_ADDRS[0]}" + +function cdc_cli_changefeed() { + command cdc_cli_changefeed "$@" --server "$CDC_API_SERVER" +} + +function run_cdc_cli() { + command run_cdc_cli "$@" --server "$CDC_API_SERVER" +} +export -f cdc_cli_changefeed run_cdc_cli + FAILPOINT_NOT_READY_TO_CLOSE_DISPATCHER="github.com/pingcap/ticdc/downstreamadapter/dispatcher/NotReadyToCloseDispatcher" FAILPOINT_BLOCK_CREATE_DISPATCHER="github.com/pingcap/ticdc/downstreamadapter/dispatchermanager/BlockCreateDispatcher" @@ -53,6 +75,83 @@ function get_table_replication_count() { jq -r --argjson tid "$table_id" '[.items[].table_ids[] | select(. == $tid)] | length' } +function wait_for_table_replication_count() { + local api_addr=$1 + local changefeed_id=$2 + local table_id=$3 + local target_count=$4 + local comparison_mode=$5 + local mode=$6 + local retry=${7:-30} + + for ((i = 0; i < retry; i++)); do + local count + count=$(get_table_replication_count "$api_addr" "$changefeed_id" "$table_id" "$mode") + if [ -n "$count" ] && [ "$count" != "null" ]; then + case "$comparison_mode" in + eq) + if [ "$count" -eq "$target_count" ]; then + echo "$count" + return 0 + fi + ;; + ge) + if [ "$count" -ge "$target_count" ]; then + echo "$count" + return 0 + fi + ;; + le) + if [ "$count" -le "$target_count" ]; then + echo "$count" + return 0 + fi + ;; + *) + echo "unknown comparison mode: $comparison_mode" >&2 + return 1 + ;; + esac + fi + sleep 2 + done + echo "table $table_id replication count did not satisfy $comparison_mode $target_count" >&2 + return 1 +} + +function wait_for_all_table_replications_on_addr() { + local api_addr=$1 + local changefeed_id=$2 + local table_id=$3 + local target_addr=$4 + local mode=$5 + local retry=${6:-30} + + for ((i = 0; i < retry; i++)); do + local target_id + target_id=$(get_capture_id_by_addr "$api_addr" "$target_addr") + if [ -z "$target_id" ] || [ "$target_id" == "null" ]; then + sleep 2 + continue + fi + + local resp + resp=$(curl -s "http://${api_addr}/api/v2/changefeeds/${changefeed_id}/tables?keyspace=$KEYSPACE_NAME&mode=$mode") + local total_count + total_count=$(echo "$resp" | jq -r --argjson tid "$table_id" '[.items[] | select(.table_ids | index($tid))] | length') + local target_count + target_count=$(echo "$resp" | jq -r --argjson tid "$table_id" --arg target "$target_id" '[.items[] | select((.table_ids | index($tid)) and .node_id == $target)] | length') + if [ "$total_count" != "null" ] && [ "$target_count" != "null" ] && + [ "$total_count" -gt 0 ] && [ "$total_count" -eq "$target_count" ]; then + echo "$target_count" + return 0 + fi + sleep 2 + done + echo "table $table_id still has replicas outside $target_addr" >&2 + return 1 +} + function get_maintainer_addr() { local api_addr=$1 local changefeed_id=$2 @@ -125,6 +224,20 @@ function wait_for_add_operator_inflight_in_logs() { return 1 } +function wait_for_restored_merge_operator_in_logs() { + local work_dir=$1 + local retry=$2 + + for ((i = 0; i < retry; i++)); do + if grep -qs "restore merge operator" "$work_dir"/cdc*.log 2>/dev/null; then + return 0 + fi + sleep 2 + done + echo "restored merge operator not observed in logs" >&2 + return 1 +} + function wait_for_maintainer_move() { local api_addr=$1 local changefeed_id=$2 @@ -223,8 +336,13 @@ function create_diff_config() { local work_dir=$1 local target_config_path=$2 - # update output-dir to point to current work directory to avoid collision between subcases. - sed "s|output-dir = \".*\"|output-dir = \"$work_dir/sync_diff/output\"|" "$CUR/conf/diff_config.toml" >"$target_config_path" + # Keep sync-diff aligned with the TiDB endpoints selected for this run, so isolated local reruns do not + # accidentally compare against another default-port cluster on the machine. + sed \ + -e "s|output-dir = \".*\"|output-dir = \"$work_dir/sync_diff/output\"|" \ + -e "/\\[data-sources.mysql1\\]/,/^$/{s/host = \".*\"/host = \"$UP_TIDB_HOST\"/; s/port = [0-9][0-9]*/port = $UP_TIDB_PORT/;}" \ + -e "/\\[data-sources.tidb0\\]/,/^$/{s/host = \".*\"/host = \"$DOWN_TIDB_HOST\"/; s/port = [0-9][0-9]*/port = $DOWN_TIDB_PORT/;}" \ + "$CUR/conf/diff_config.toml" >"$target_config_path" } function run_impl() { @@ -239,9 +357,11 @@ function run_impl() { # Disable balance scheduler to avoid unexpected auto split/move interfering with this test. export GO_FAILPOINTS='github.com/pingcap/ticdc/maintainer/scheduler/StopBalanceScheduler=return(true)' - run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 1 --addr "127.0.0.1:8300" - run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 2 --addr "127.0.0.1:8301" - run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 3 --addr "127.0.0.1:8302" + # Always pass the freshly started upstream PD explicitly so every capture joins the test cluster + # instead of silently falling back to the default 2379 endpoint during isolated local reruns. + run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 1 --addr "${CDC_ADDRS[0]}" --pd "$pd_addr" + run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 2 --addr "${CDC_ADDRS[1]}" --pd "$pd_addr" + run_cdc_server --workdir "$work_dir" --binary $CDC_BINARY --logsuffix 3 --addr "${CDC_ADDRS[2]}" --pd "$pd_addr" export GO_FAILPOINTS='' TOPIC_NAME="ticdc-move-table-maintainer-failover-$RANDOM" @@ -252,7 +372,7 @@ function run_impl() { run_pulsar_cluster "$work_dir" normal SINK_URI="pulsar://127.0.0.1:6650/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" ;; - *) SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1" ;; + *) SINK_URI="mysql://normal:123456@127.0.0.1:${DOWN_TIDB_PORT}/?max-txn-row=1" ;; esac changefeed_config="$work_dir/changefeed.toml" create_changefeed_config "$mode" "$work_dir" "$changefeed_config" @@ -267,17 +387,22 @@ function run_impl() { run_sql "CREATE TABLE maintainer_failover_when_operator.t1(id INT PRIMARY KEY, val VARCHAR(20));" ${UP_TIDB_HOST} ${UP_TIDB_PORT} # move run_sql "CREATE TABLE maintainer_failover_when_operator.t2(id INT PRIMARY KEY, val VARCHAR(20));" ${UP_TIDB_HOST} ${UP_TIDB_PORT} # split run_sql "CREATE TABLE maintainer_failover_when_operator.t3(id INT PRIMARY KEY, val VARCHAR(20));" ${UP_TIDB_HOST} ${UP_TIDB_PORT} # remove + run_sql "CREATE TABLE maintainer_failover_when_operator.t6(id INT PRIMARY KEY, val VARCHAR(20));" ${UP_TIDB_HOST} ${UP_TIDB_PORT} # merge run_sql "split table maintainer_failover_when_operator.t2 between (1) and (100000) regions 20;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} + run_sql "split table maintainer_failover_when_operator.t6 between (1) and (100000) regions 20;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} run_sql "INSERT INTO maintainer_failover_when_operator.t1 VALUES (1, 'a'), (2, 'b');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} run_sql "INSERT INTO maintainer_failover_when_operator.t2 VALUES (1, 'a'), (2, 'b');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} run_sql "INSERT INTO maintainer_failover_when_operator.t3 VALUES (1, 'a'), (2, 'b');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} + run_sql "INSERT INTO maintainer_failover_when_operator.t6 VALUES (1, 'a'), (2, 'b');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} check_table_exists "maintainer_failover_when_operator.t1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 check_table_exists "maintainer_failover_when_operator.t2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 check_table_exists "maintainer_failover_when_operator.t3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 + check_table_exists "maintainer_failover_when_operator.t6" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 table_id_1=$(get_table_id "maintainer_failover_when_operator" "t1") table_id_2=$(get_table_id "maintainer_failover_when_operator" "t2") table_id_3=$(get_table_id "maintainer_failover_when_operator" "t3") + table_id_6=$(get_table_id "maintainer_failover_when_operator" "t6") api_addr=${CDC_ADDRS[0]} maintainer_addr=$(get_maintainer_addr "$api_addr" "$changefeed_id") @@ -297,9 +422,28 @@ function run_impl() { ensure_table_single_replication "$api_addr" "$changefeed_id" "$table_id_1" "$mode" ensure_table_single_replication "$api_addr" "$changefeed_id" "$table_id_2" "$mode" ensure_table_single_replication "$api_addr" "$changefeed_id" "$table_id_3" "$mode" + ensure_table_single_replication "$api_addr" "$changefeed_id" "$table_id_6" "$mode" ensure_table_on_addr "$api_addr" "$changefeed_id" "$table_id_1" "$origin_addr" "$mode" ensure_table_on_addr "$api_addr" "$changefeed_id" "$table_id_2" "$origin_addr" "$mode" ensure_table_on_addr "$api_addr" "$changefeed_id" "$table_id_3" "$origin_addr" "$mode" + ensure_table_on_addr "$api_addr" "$changefeed_id" "$table_id_6" "$origin_addr" "$mode" + + # Prepare a dedicated split table for the merge failover scenario. + # Steps: + # 1) Split the table into multiple replications. + # 2) Move all split dispatchers onto the surviving origin capture, so the merge request is persisted on a + # node that stays alive after the maintainer moves. + # 3) Record the replication count before issuing merge; a blocked merge should temporarily add one more + # merged dispatcher, and a successful restored merge should later reduce the count by one. + split_table_with_retry "$table_id_6" "$changefeed_id" 10 "$mode" + wait_for_table_replication_count "$api_addr" "$changefeed_id" "$table_id_6" 2 ge "$mode" 60 + move_split_table_with_retry "$origin_addr" "$table_id_6" "$changefeed_id" 10 "$mode" + wait_for_all_table_replications_on_addr "$api_addr" "$changefeed_id" "$table_id_6" "$origin_addr" "$mode" 60 + merge_replication_count_before=$(get_table_replication_count "$api_addr" "$changefeed_id" "$table_id_6" "$mode") + if [ -z "$merge_replication_count_before" ] || [ "$merge_replication_count_before" == "null" ] || [ "$merge_replication_count_before" -lt 2 ]; then + echo "table $table_id_6 does not have enough replications for merge, count=$merge_replication_count_before" >&2 + exit 1 + fi enable_failpoint --addr "$origin_addr" --name "$FAILPOINT_NOT_READY_TO_CLOSE_DISPATCHER" --expr "return(true)" enable_failpoint_on_all_addrs "$FAILPOINT_BLOCK_CREATE_DISPATCHER" "pause" @@ -337,6 +481,15 @@ function run_impl() { # failpoint is enabled on origin, so the table should not move to target wait_for_table_on_addr "$api_addr" "$changefeed_id" "$table_id_1" "$origin_addr" "$mode" + # Merge operator: issue merge against the dedicated split table while source dispatcher close is blocked. + # Once the merged dispatcher appears, the maintainer can be killed safely because the merge request has + # already reached dispatcher manager state and must be restored from bootstrap on failover. + set +e + merge_table_with_retry "$table_id_6" "$changefeed_id" 1 "$mode" & + merge_pid=$! + set -e + wait_for_table_replication_count "$api_addr" "$changefeed_id" "$table_id_6" "$((merge_replication_count_before + 1))" ge "$mode" 60 + # Remove operator: drop one table while dispatcher close is blocked. run_sql "DROP TABLE maintainer_failover_when_operator.t3;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} @@ -353,8 +506,12 @@ function run_impl() { disable_failpoint --addr "$origin_addr" --name "$FAILPOINT_NOT_READY_TO_CLOSE_DISPATCHER" disable_failpoint_on_all_addrs_best_effort "$FAILPOINT_BLOCK_CREATE_DISPATCHER" + wait_for_restored_merge_operator_in_logs "$work_dir" 60 + wait_for_table_replication_count "$api_addr" "$changefeed_id" "$table_id_6" "$((merge_replication_count_before - 1))" eq "$mode" 60 + set +e wait "$split_pid" + wait "$merge_pid" set -e # After removing failpoints, the table should be scheduled eventually. @@ -364,6 +521,7 @@ function run_impl() { check_table_exists "maintainer_failover_when_operator.t4" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 check_table_exists "maintainer_failover_when_operator.t5" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 + check_table_exists "maintainer_failover_when_operator.t6" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 check_table_not_exists "maintainer_failover_when_operator.t3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 300 run_sql "ALTER TABLE maintainer_failover_when_operator.t1 ADD COLUMN c2 INT DEFAULT 0;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} @@ -372,6 +530,7 @@ function run_impl() { run_sql "INSERT INTO maintainer_failover_when_operator.t2 VALUES (3, 'c');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} run_sql "INSERT INTO maintainer_failover_when_operator.t4 VALUES (3, 'c');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} run_sql "INSERT INTO maintainer_failover_when_operator.t5 VALUES (3, 'c');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} + run_sql "INSERT INTO maintainer_failover_when_operator.t6 VALUES (3, 'c');" ${UP_TIDB_HOST} ${UP_TIDB_PORT} diff_config="$work_dir/diff_config.toml" create_diff_config "$work_dir" "$diff_config"