@@ -35,6 +35,21 @@ import (
3535 "go.uber.org/zap"
3636)
3737
38+ const dispatcherOrchestratorWarnLogInterval = 10 * time .Second
39+
40+ func shouldLogDispatcherOrchestratorWarning (lastLogTime * atomic.Int64 , interval time.Duration ) bool {
41+ now := time .Now ().UnixNano ()
42+ for {
43+ last := lastLogTime .Load ()
44+ if last != 0 && now - last < interval .Nanoseconds () {
45+ return false
46+ }
47+ if lastLogTime .CompareAndSwap (last , now ) {
48+ return true
49+ }
50+ }
51+ }
52+
3853// DispatcherOrchestrator coordinates the creation, deletion, and management of event dispatcher managers
3954// for different change feeds based on maintainer bootstrap messages.
4055type DispatcherOrchestrator struct {
@@ -50,6 +65,11 @@ type DispatcherOrchestrator struct {
5065 closed atomic.Bool
5166 // msgGuardWaitGroup waits for in-flight RecvMaintainerRequest handlers before shutdown.
5267 msgGuardWaitGroup util.GuardedWaitGroup
68+
69+ lastUnknownMessageLogTime atomic.Int64
70+ lastHandleMessageErrLogTime atomic.Int64
71+ lastSendResponseErrLogTime atomic.Int64
72+ lastCreateManagerErrLogTime atomic.Int64
5373}
5474
5575func New () * DispatcherOrchestrator {
@@ -87,9 +107,11 @@ func (m *DispatcherOrchestrator) RecvMaintainerRequest(
87107
88108 key , ok := getPendingMessageKey (msg )
89109 if ! ok {
90- log .Warn ("unknown message type, drop message" ,
91- zap .String ("type" , msg .Type .String ()),
92- zap .Any ("message" , msg .Message ))
110+ if shouldLogDispatcherOrchestratorWarning (& m .lastUnknownMessageLogTime , dispatcherOrchestratorWarnLogInterval ) {
111+ log .Warn ("unknown message type, drop message" ,
112+ zap .String ("type" , msg .Type .String ()),
113+ zap .Any ("message" , msg .Message ))
114+ }
93115 return nil
94116 }
95117
@@ -130,21 +152,29 @@ func (m *DispatcherOrchestrator) handleMessages() {
130152 switch req := msg .Message [0 ].(type ) {
131153 case * heartbeatpb.MaintainerBootstrapRequest :
132154 if err := m .handleBootstrapRequest (msg .From , req ); err != nil {
133- log .Error ("failed to handle bootstrap request" , zap .Error (err ))
155+ if shouldLogDispatcherOrchestratorWarning (& m .lastHandleMessageErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
156+ log .Error ("failed to handle bootstrap request" , zap .Error (err ))
157+ }
134158 }
135159 case * heartbeatpb.MaintainerPostBootstrapRequest :
136160 // Only the event dispatcher manager with table trigger event dispatcher will receive the post bootstrap request
137161 if err := m .handlePostBootstrapRequest (msg .From , req ); err != nil {
138- log .Error ("failed to handle post bootstrap request" , zap .Error (err ))
162+ if shouldLogDispatcherOrchestratorWarning (& m .lastHandleMessageErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
163+ log .Error ("failed to handle post bootstrap request" , zap .Error (err ))
164+ }
139165 }
140166 case * heartbeatpb.MaintainerCloseRequest :
141167 if err := m .handleCloseRequest (msg .From , req ); err != nil {
142- log .Error ("failed to handle close request" , zap .Error (err ))
168+ if shouldLogDispatcherOrchestratorWarning (& m .lastHandleMessageErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
169+ log .Error ("failed to handle close request" , zap .Error (err ))
170+ }
143171 }
144172 default :
145- log .Warn ("unknown message type, ignore it" ,
146- zap .String ("type" , msg .Type .String ()),
147- zap .Any ("message" , msg .Message ))
173+ if shouldLogDispatcherOrchestratorWarning (& m .lastUnknownMessageLogTime , dispatcherOrchestratorWarnLogInterval ) {
174+ log .Warn ("unknown message type, ignore it" ,
175+ zap .String ("type" , msg .Type .String ()),
176+ zap .Any ("message" , msg .Message ))
177+ }
148178 }
149179
150180 m .msgQueue .Done (key )
@@ -182,8 +212,10 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest(
182212 )
183213 // Fast return the error to maintainer.
184214 if err != nil {
185- log .Error ("failed to create new dispatcher manager" ,
186- zap .Any ("changefeedID" , cfId .Name ()), zap .Duration ("duration" , time .Since (start )), zap .Error (err ))
215+ if shouldLogDispatcherOrchestratorWarning (& m .lastCreateManagerErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
216+ log .Error ("failed to create new dispatcher manager" ,
217+ zap .Any ("changefeedID" , cfId .Name ()), zap .Duration ("duration" , time .Since (start )), zap .Error (err ))
218+ }
187219
188220 appcontext.GetService [* dispatchermanager.HeartBeatCollector ](appcontext .HeartbeatCollector ).RemoveDispatcherManager (cfId )
189221
@@ -196,8 +228,10 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest(
196228 Message : err .Error (),
197229 },
198230 }
199- log .Error ("create new dispatcher manager failed" ,
200- zap .Any ("changefeedID" , cfId .Name ()), zap .Duration ("duration" , time .Since (start )), zap .Error (err ))
231+ if shouldLogDispatcherOrchestratorWarning (& m .lastCreateManagerErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
232+ log .Error ("create new dispatcher manager failed" ,
233+ zap .Any ("changefeedID" , cfId .Name ()), zap .Duration ("duration" , time .Since (start )), zap .Error (err ))
234+ }
201235
202236 return m .sendResponse (from , messaging .MaintainerManagerTopic , response )
203237 }
@@ -396,7 +430,9 @@ func createBootstrapResponse(
396430func (m * DispatcherOrchestrator ) sendResponse (to node.ID , topic string , msg messaging.IOTypeT ) error {
397431 message := messaging .NewSingleTargetMessage (to , topic , msg )
398432 if err := m .mc .SendCommand (message ); err != nil {
399- log .Error ("failed to send response" , zap .Error (err ))
433+ if shouldLogDispatcherOrchestratorWarning (& m .lastSendResponseErrLogTime , dispatcherOrchestratorWarnLogInterval ) {
434+ log .Error ("failed to send response" , zap .Error (err ))
435+ }
400436 return err
401437 }
402438 return nil
0 commit comments