Skip to content

Commit 21b33f0

Browse files
committed
update more code
1 parent b6d799f commit 21b33f0

6 files changed

Lines changed: 11 additions & 97 deletions

File tree

‎coordinator/changefeed/backoff.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (m *Backoff) HandleError(errs []*heartbeatpb.RunningError) (bool, *heartbea
207207

208208
// check if we exceed the maxElapsedTime
209209
if m.shouldFailWhenRetry() {
210-
log.Error("the changefeed won't be restarted as it has been experiencing failures for "+
210+
log.Error("The changefeed won't be restarted as it has been experiencing failures for "+
211211
"an extended duration",
212212
zap.Duration("maxElapsedTime", m.errBackoff.MaxElapsedTime),
213213
zap.Stringer("changefeed", m.id),

‎coordinator/changefeed/changefeed.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (c *Changefeed) UpdateStatus(newStatus *heartbeatpb.MaintainerStatus) (bool
155155
if newStatus != nil && newStatus.CheckpointTs >= old.CheckpointTs {
156156
c.status.Store(newStatus)
157157
if old.BootstrapDone != newStatus.BootstrapDone {
158-
log.Info("received changefeed status with bootstrapDone",
158+
log.Info("Received changefeed status with bootstrapDone",
159159
zap.Stringer("changefeed", c.ID),
160160
zap.Bool("bootstrapDone", newStatus.BootstrapDone))
161161
return true, config.StateNormal, nil

‎downstreamadapter/eventcollector/dispatcher_stat.go‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ func (d *dispatcherStat) handleSingleDataEvents(events []dispatcher.DispatcherEv
537537
return false
538538
}
539539
if events[0].GetType() == commonEvent.TypeDDLEvent {
540-
originalDDL := events[0].Event.(*commonEvent.DDLEvent)
541-
ddl, err := d.applyRoutingToDDLEvent(originalDDL)
540+
ddl := events[0].Event.(*commonEvent.DDLEvent)
541+
ddl, err := d.target.GetRouter().ApplyToDDLEvent(ddl)
542542
if err != nil {
543543
log.Error("failed to apply routing to DDL event",
544544
zap.Stringer("changefeedID", d.target.GetChangefeedID()),
@@ -551,23 +551,8 @@ func (d *dispatcherStat) handleSingleDataEvents(events []dispatcher.DispatcherEv
551551
}
552552
events[0].Event = ddl
553553
if ddl.TableInfo != nil {
554-
// Check if this DDL's TableInfo is for a different table.
555-
// This can happen with CREATE TABLE LIKE, where the DDL is added to the
556-
// reference table's history for blocking purposes, but the TableInfo is
557-
// for the new table. In this case, we should NOT update the stored tableInfo.
558-
dispatcherTableID := d.target.GetTableSpan().TableID
559-
ddlTableID := ddl.TableInfo.TableName.TableID
560-
if ddlTableID != dispatcherTableID {
561-
log.Debug("DDL TableInfo is for a different table, skipping tableInfo update",
562-
zap.Stringer("changefeedID", d.target.GetChangefeedID()),
563-
zap.Stringer("dispatcher", d.getDispatcherID()),
564-
zap.Int64("dispatcherTableID", dispatcherTableID),
565-
zap.Int64("ddlTableID", ddlTableID),
566-
zap.String("ddlTableName", ddl.TableInfo.TableName.Table))
567-
} else {
568-
d.tableInfoVersion.Store(ddl.FinishedTs)
569-
d.tableInfo.Store(ddl.TableInfo)
570-
}
554+
d.tableInfoVersion.Store(ddl.FinishedTs)
555+
d.tableInfo.Store(ddl.TableInfo)
571556
}
572557
}
573558
d.updateCommitTsStateByEvents(state, events)
@@ -720,7 +705,8 @@ func (d *dispatcherStat) handleHandshakeEvent(event dispatcher.DispatcherEvent)
720705
}
721706
tableInfo := handshakeEvent.TableInfo
722707
if tableInfo != nil {
723-
d.tableInfo.Store(d.applyRoutingToTableInfo(tableInfo))
708+
tableInfo := d.target.GetRouter().ApplyToTableInfo(tableInfo)
709+
d.tableInfo.Store(tableInfo)
724710
}
725711
state.lastEventSeq.Store(handshakeEvent.Seq)
726712
d.observeCurrentEpochMaxEventTs(state, handshakeEvent.GetCommitTs())
@@ -820,17 +806,3 @@ func (d *dispatcherStat) newDispatcherRemoveRequest(serverId string) *messaging.
820806
},
821807
}
822808
}
823-
824-
// applyRoutingToTableInfo applies routing rules to the TableInfo and returns a new TableInfo
825-
// with TargetSchema/TargetTable set. If no routing is needed (no router configured, or routing
826-
// results in same schema/table), returns the original tableInfo unchanged.
827-
// This avoids mutating shared TableInfo objects that may be used by multiple changefeeds.
828-
func (d *dispatcherStat) applyRoutingToTableInfo(tableInfo *common.TableInfo) *common.TableInfo {
829-
router := d.target.GetRouter()
830-
return router.ApplyToTableInfo(tableInfo)
831-
}
832-
833-
func (d *dispatcherStat) applyRoutingToDDLEvent(ddl *commonEvent.DDLEvent) (*commonEvent.DDLEvent, error) {
834-
router := d.target.GetRouter()
835-
return router.ApplyToDDLEvent(ddl)
836-
}

‎downstreamadapter/eventcollector/dispatcher_stat_test.go‎

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ func TestHandleDDLEventTableInfoUpdate(t *testing.T) {
15121512
localServerID := node.ID("local")
15131513
remoteServerID := node.ID("remote")
15141514

1515-
t.Run("stores table info when ddl table matches dispatcher", func(t *testing.T) {
1515+
t.Run("stores ddl table info", func(t *testing.T) {
15161516
var capturedEvent *commonEvent.DDLEvent
15171517
mockDisp := newMockDispatcher(common.NewDispatcherID(), 0)
15181518
mockDisp.handleEvents = func(events []dispatcher.DispatcherEvent, wakeCallback func()) bool {
@@ -1560,58 +1560,4 @@ func TestHandleDDLEventTableInfoUpdate(t *testing.T) {
15601560
require.NotNil(t, capturedEvent)
15611561
require.Same(t, ddlEvent, capturedEvent)
15621562
})
1563-
1564-
t.Run("keeps current table info when ddl table belongs to another table", func(t *testing.T) {
1565-
mockDisp := newMockDispatcher(common.NewDispatcherID(), 0)
1566-
mockDisp.handleEvents = func(events []dispatcher.DispatcherEvent, wakeCallback func()) bool {
1567-
return false
1568-
}
1569-
1570-
stat := newDispatcherStat(mockDisp, newTestEventCollector(localServerID), nil)
1571-
stat.connState.setEventServiceID(remoteServerID)
1572-
stat.currentEpoch.Store(newDispatcherEpochState(10, 1, stat.target.GetStartTs()))
1573-
stat.lastEventCommitTs.Store(50)
1574-
1575-
originalTableInfo := &common.TableInfo{
1576-
TableName: common.TableName{
1577-
Schema: "test",
1578-
Table: "t",
1579-
TableID: 1,
1580-
},
1581-
}
1582-
stat.tableInfo.Store(originalTableInfo)
1583-
1584-
newTableInfo := &common.TableInfo{
1585-
TableName: common.TableName{
1586-
Schema: "test",
1587-
Table: "t_like",
1588-
TableID: 999,
1589-
},
1590-
}
1591-
1592-
ddlEvent := &commonEvent.DDLEvent{
1593-
Version: commonEvent.DDLEventVersion1,
1594-
Query: "CREATE TABLE `test`.`t_like` LIKE `test`.`t`",
1595-
FinishedTs: 100,
1596-
Epoch: 10,
1597-
Seq: 2,
1598-
TableInfo: newTableInfo,
1599-
}
1600-
1601-
events := []dispatcher.DispatcherEvent{
1602-
{From: &remoteServerID, Event: ddlEvent},
1603-
}
1604-
1605-
stat.handleDataEvents(events...)
1606-
1607-
storedTableInfo := stat.tableInfo.Load().(*common.TableInfo)
1608-
require.NotNil(t, storedTableInfo)
1609-
require.Same(t, originalTableInfo, storedTableInfo)
1610-
require.Equal(t, "t", storedTableInfo.TableName.Table)
1611-
require.Equal(t, int64(1), storedTableInfo.TableName.TableID)
1612-
require.NotEqual(t, "t_like", storedTableInfo.TableName.Table)
1613-
require.NotEqual(t, int64(999), storedTableInfo.TableName.TableID)
1614-
require.Equal(t, uint64(0), stat.tableInfoVersion.Load())
1615-
})
1616-
16171563
}

‎downstreamadapter/eventcollector/event_collector_test.go‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ func TestProcessMessage(t *testing.T) {
192192
dml.Seq = seq.Add(1)
193193
dml.Epoch = 1
194194
dml.CommitTs = ddl.FinishedTs + uint64(i)
195-
// eventcollector sets TableInfoVersion from the latest DDL version when
196-
// expanding BatchDMLEvent into individual DMLEvents.
197-
dml.TableInfoVersion = ddl.FinishedTs
198195
events[dml.Seq] = dml
199196
}
200197

‎pkg/common/table_info.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ func (ti *TableInfo) InitPrivateFields() {
142142

143143
// CloneWithRouting creates a shallow copy of TableInfo with routing applied.
144144
// The new TableInfo shares the same columnSchema, View, Sequence pointers
145-
// but has its own TableName and precomputed SQLs using the routed target name
146-
// when columnSchema is available.
145+
// but has its own TableName (with TargetSchema/TargetTable set) and uninitialized preSQLs.
147146
// This is safe because:
148147
// - columnSchema, View, Sequence are read-only after creation
148+
// - preSQLs will be initialized later via InitPrivateFields() using the new TableName
149149
// - TableName is a value type that gets copied
150150
func (ti *TableInfo) CloneWithRouting(targetSchema, targetTable string) *TableInfo {
151151
if ti == nil {
@@ -176,7 +176,6 @@ func (ti *TableInfo) CloneWithRouting(targetSchema, targetTable string) *TableIn
176176
runtime.SetFinalizer(cloned, func(ti *TableInfo) {
177177
GetSharedColumnSchemaStorage().tryReleaseColumnSchema(ti.columnSchema)
178178
})
179-
cloned.InitPrivateFields()
180179
}
181180

182181
return cloned

0 commit comments

Comments
 (0)