Skip to content

Commit

Permalink
fix: do not use gtid if gtid is disabled (#1781)
Browse files Browse the repository at this point in the history
Fixed an issue where the input_canal plugin used GTID as the sync method even when gtid_enabled was set to false. This led to syncing from the beginning due to receiving an empty GTID set. Syncing from the beginning is usually undesirable as it consumes significant CPU resources on the server side and deviates from the default plugin behavior. This commit ensures that the plugin respects the gtid_enabled switch and the gtid_mode query result.
  • Loading branch information
yyuuttaaoo committed Sep 25, 2024
1 parent aaa462f commit 7c5f15c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/input/canal/input_canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,13 @@ func (sc *ServiceCanal) Start(c pipeline.Collector) error {
startPos.Pos = sc.checkpoint.Offset
}
if nil == gtid && 0 == len(startPos.Name) && !sc.StartFromBegining {
gtid, err = sc.getLatestGTID()
if err != nil {
logger.Warning(sc.context.GetRuntimeContext(), "CANAL_START_ALARM", "Call getLatestGTID failed, error", err)
if sc.isGTIDEnabled {
gtid, err = sc.getLatestGTID()
if err != nil {
logger.Warning(sc.context.GetRuntimeContext(), "CANAL_START_ALARM", "Call getLatestGTID failed, error", err)
}
}
if gtid == nil {
startPos = sc.GetBinlogLatestPos()
}
logger.Infof(sc.context.GetRuntimeContext(), "Get latest checkpoint GTID: %v Position: %v", gtid, startPos)
Expand Down

0 comments on commit 7c5f15c

Please sign in to comment.