-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtask.go
More file actions
545 lines (485 loc) · 19.7 KB
/
task.go
File metadata and controls
545 lines (485 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
// Copyright 2024 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 (
"math"
"sync"
"time"
"github.com/pingcap/log"
"github.com/pingcap/ticdc/downstreamadapter/dispatcher"
"github.com/pingcap/ticdc/downstreamadapter/eventcollector"
"github.com/pingcap/ticdc/downstreamadapter/sink/mysql"
"github.com/pingcap/ticdc/heartbeatpb"
"github.com/pingcap/ticdc/pkg/common"
appcontext "github.com/pingcap/ticdc/pkg/common/context"
"github.com/pingcap/ticdc/utils/threadpool"
"go.uber.org/zap"
)
const (
heartbeatTaskExecuteInterval = 200 * time.Millisecond
defaultCompleteStatusInterval = 10 * time.Second
// syncPointCompleteStatusInterval is shorter so eventBroker can receive dispatcher-level
// checkpointTs progress faster when two-phase syncpoint commit is enabled.
syncPointCompleteStatusInterval = 1 * time.Second
)
// HeartbeatTask is a perioic task to collect the heartbeat status from event dispatcher manager and push to heartbeatRequestQueue
type HeartBeatTask struct {
taskHandle *threadpool.TaskHandle
manager *DispatcherManager
// Used to determine when to collect complete status
statusTick int
}
func newHeartBeatTask(manager *DispatcherManager) *HeartBeatTask {
taskScheduler := GetHeartBeatTaskScheduler()
t := &HeartBeatTask{
manager: manager,
statusTick: 0,
}
t.taskHandle = taskScheduler.Submit(t, time.Now().Add(time.Second*1))
return t
}
func getCompleteStatusInterval(enableSyncPoint bool) time.Duration {
if enableSyncPoint {
return syncPointCompleteStatusInterval
}
return defaultCompleteStatusInterval
}
func getIntervalTicks(interval, executeInterval time.Duration) int {
ticks := int(interval / executeInterval)
if ticks <= 0 {
return 1
}
return ticks
}
func (t *HeartBeatTask) Execute() time.Time {
if t.manager.closed.Load() {
return time.Time{}
}
executeInterval := heartbeatTaskExecuteInterval
enableSyncPoint := t.manager.config != nil && t.manager.config.EnableSyncPoint
completeStatusInterval := getIntervalTicks(getCompleteStatusInterval(enableSyncPoint), executeInterval)
t.statusTick++
needCompleteStatus := t.statusTick%completeStatusInterval == 0
message := t.manager.aggregateDispatcherHeartbeats(needCompleteStatus)
t.manager.heartbeatRequestQueue.Enqueue(&HeartBeatRequestWithTargetID{TargetID: t.manager.GetMaintainerID(), Request: message})
return time.Now().Add(executeInterval)
}
func (t *HeartBeatTask) Cancel() {
t.taskHandle.Cancel()
}
var (
heartBeatTaskSchedulerOnce sync.Once
heartBeatTaskScheduler threadpool.ThreadPool
)
func GetHeartBeatTaskScheduler() threadpool.ThreadPool {
heartBeatTaskSchedulerOnce.Do(func() {
heartBeatTaskScheduler = threadpool.NewThreadPoolDefault()
})
return heartBeatTaskScheduler
}
func SetHeartBeatTaskScheduler(taskScheduler threadpool.ThreadPool) {
heartBeatTaskScheduler = taskScheduler
}
var (
mergeCheckTaskSchedulerOnce sync.Once
mergeCheckTaskScheduler threadpool.ThreadPool
)
func GetMergeCheckTaskScheduler() threadpool.ThreadPool {
mergeCheckTaskSchedulerOnce.Do(func() {
mergeCheckTaskScheduler = threadpool.NewThreadPoolDefault()
})
return mergeCheckTaskScheduler
}
func SetMergeCheckTaskScheduler(taskScheduler threadpool.ThreadPool) {
mergeCheckTaskScheduler = taskScheduler
}
// MergeCheckTask is a task to check the status of the merged dispatcher.
type MergeCheckTask struct {
taskHandle *threadpool.TaskHandle
manager *DispatcherManager
mergedDispatcher dispatcher.Dispatcher
dispatcherIDs []common.DispatcherID // the ids of dispatchers to be merged
}
func newMergeCheckTask(manager *DispatcherManager, mergedDispatcher dispatcher.Dispatcher, dispatcherIDs []common.DispatcherID) *MergeCheckTask {
taskScheduler := GetMergeCheckTaskScheduler()
t := &MergeCheckTask{
manager: manager,
mergedDispatcher: mergedDispatcher,
dispatcherIDs: dispatcherIDs,
}
t.taskHandle = taskScheduler.Submit(t, time.Now().Add(time.Second*1))
return t
}
func (t *MergeCheckTask) Execute() time.Time {
if t.manager.closed.Load() {
return time.Time{}
}
sinkType := getSinkType(t.mergedDispatcher, t.manager)
if common.IsRedoMode(t.mergedDispatcher.GetMode()) {
if needAbort, abortReason := shouldAbortMerge(t, t.manager.redoDispatcherMap); needAbort {
abortMerge(t, t.manager.redoDispatcherMap, sinkType, abortReason)
return time.Time{}
}
} else {
if needAbort, abortReason := shouldAbortMerge(t, t.manager.dispatcherMap); needAbort {
abortMerge(t, t.manager.dispatcherMap, sinkType, abortReason)
return time.Time{}
}
}
if t.mergedDispatcher.GetComponentStatus() != heartbeatpb.ComponentState_MergeReady {
return time.Now().Add(time.Second * 1)
}
if common.IsRedoMode(t.mergedDispatcher.GetMode()) {
doMerge(t, t.manager.redoDispatcherMap)
} else {
doMerge(t, t.manager.dispatcherMap)
}
return time.Now().Add(time.Second * 1)
}
func (t *MergeCheckTask) Cancel() {
t.taskHandle.Cancel()
}
func shouldAbortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T]) (bool, string) {
mergedID := t.mergedDispatcher.GetId()
mergedDispatcher, ok := dispatcherMap.Get(mergedID)
if !ok {
return true, "merged_dispatcher_missing"
}
if mergedDispatcher.GetTryRemoving() || mergedDispatcher.GetRemovingStatus() {
return true, "merged_dispatcher_removing"
}
for _, id := range t.dispatcherIDs {
dispatcherItem, ok := dispatcherMap.Get(id)
if !ok {
return true, "source_dispatcher_missing"
}
if dispatcherItem.GetTryRemoving() || dispatcherItem.GetRemovingStatus() {
return true, "source_dispatcher_removing"
}
}
return false, ""
}
func abortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T], sinkType common.SinkType, reason string) {
log.Info("abort merge",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.String("reason", reason),
zap.Int64("mode", t.mergedDispatcher.GetMode()),
zap.Any("dispatcherIDs", t.dispatcherIDs),
zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()),
)
// Stop retrying and cleanup best-effort.
t.Cancel()
eventCollector := appcontext.GetService[*eventcollector.EventCollector](appcontext.EventCollector)
memoryQuota := t.manager.sinkQuota
if common.IsRedoMode(t.mergedDispatcher.GetMode()) {
memoryQuota = t.manager.redoQuota
}
for _, id := range t.dispatcherIDs {
dispatcherItem, ok := dispatcherMap.Get(id)
if !ok {
continue
}
if dispatcherItem.GetTryRemoving() || dispatcherItem.GetRemovingStatus() {
continue
}
if dispatcherItem.GetComponentStatus() == heartbeatpb.ComponentState_WaitingMerge {
dispatcherItem.SetComponentStatus(heartbeatpb.ComponentState_Working)
}
// Merge closes and detaches source dispatchers from event collector. If merge aborts,
// re-register the dispatchers so they can resume receiving events.
if !eventCollector.HasDispatcher(id) {
eventCollector.AddDispatcher(dispatcherItem, memoryQuota)
}
}
removeDispatcher(t.manager, t.mergedDispatcher.GetId(), dispatcherMap, sinkType)
t.manager.RemoveMergeOperator(t.mergedDispatcher.GetId())
}
func doMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T]) {
log.Info("do merge",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Int64("mode", t.mergedDispatcher.GetMode()),
zap.Any("dispatcherIDs", t.dispatcherIDs),
zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()),
)
sinkType := getSinkType(t.mergedDispatcher, t.manager)
// Step1: close all dispatchers to be merged, calculate the min checkpointTs of the merged dispatcher
minCheckpointTs := uint64(math.MaxUint64)
closedList := make([]bool, len(t.dispatcherIDs)) // record whether the dispatcher is closed successfully
pendingStates := make([]*heartbeatpb.State, len(t.dispatcherIDs))
closedCount := 0
count := 0
for closedCount < len(t.dispatcherIDs) {
if needAbort, abortReason := shouldAbortMerge(t, dispatcherMap); needAbort {
abortMerge(t, dispatcherMap, sinkType, abortReason)
return
}
for idx, id := range t.dispatcherIDs {
if closedList[idx] {
continue
}
dispatcher, ok := dispatcherMap.Get(id)
if !ok {
break
}
if count == 0 {
appcontext.GetService[*eventcollector.EventCollector](appcontext.EventCollector).RemoveDispatcher(dispatcher)
}
watermark, ok := dispatcher.TryClose()
if ok {
if watermark.CheckpointTs < minCheckpointTs {
minCheckpointTs = watermark.CheckpointTs
}
// Record pending block event status when the source dispatcher is closed successfully.
// This is used to derive a safe startTs for merged dispatcher when all source dispatchers
// are waiting for the same block event (DDL or syncpoint).
pendingStates[idx] = dispatcher.GetBlockEventStatus()
closedList[idx] = true
closedCount++
} else {
log.Info("dispatcher is still not closed", zap.Stringer("dispatcherID", id))
}
}
time.Sleep(10 * time.Millisecond)
count += 1
log.Info("event dispatcher manager is doing merge, waiting for dispatchers to be closed",
zap.Int("closedCount", closedCount),
zap.Int("total", len(t.dispatcherIDs)),
zap.Int("count", count),
zap.Int64("mode", t.mergedDispatcher.GetMode()),
zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()),
)
}
// Step2: resolve startTs and skip flags for the merged dispatcher,
// set the pd clock currentTs as the currentPDTs of the merged dispatcher,
// change the component status of the merged dispatcher to Initializing
// set dispatcher into dispatcherMap and related field
// notify eventCollector to update the merged dispatcher startTs
startTs, skipSyncpointAtStartTs, skipDMLAsStartTs := resolveMergedDispatcherStartTs(t, minCheckpointTs, pendingStates)
t.mergedDispatcher.SetStartTs(startTs)
t.mergedDispatcher.SetSkipSyncpointAtStartTs(skipSyncpointAtStartTs)
t.mergedDispatcher.SetSkipDMLAsStartTs(skipDMLAsStartTs)
t.mergedDispatcher.SetCurrentPDTs(t.manager.pdClock.CurrentTS())
t.mergedDispatcher.SetComponentStatus(heartbeatpb.ComponentState_Initializing)
appcontext.GetService[*eventcollector.EventCollector](appcontext.EventCollector).CommitAddDispatcher(t.mergedDispatcher, startTs)
log.Info("merge dispatcher commit",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Stringer("dispatcherID", t.mergedDispatcher.GetId()),
zap.Int64("mode", t.mergedDispatcher.GetMode()),
zap.Any("tableSpan", common.FormatTableSpan(t.mergedDispatcher.GetTableSpan())),
zap.Uint64("startTs", startTs),
)
// Step3: cancel the merge task
t.Cancel()
// Step4: remove all the dispatchers to be merged
// we set dispatcher removing status to true after we set the merged dispatcher into dispatcherMap and change its status to Initializing.
// so that we can ensure the calculate of checkpointTs of the event dispatcher manager will include the merged dispatcher of the dispatchers to be merged
// to avoid the fallback of the checkpointTs
for _, id := range t.dispatcherIDs {
dispatcher, ok := dispatcherMap.Get(id)
if !ok {
log.Warn("dispatcher not found when do merge, skip remove",
zap.Stringer("dispatcherID", id),
zap.Stringer("changefeedID", t.manager.changefeedID))
continue
}
dispatcher.Remove()
}
t.manager.RemoveMergeOperator(t.mergedDispatcher.GetId())
}
type mergedStartTsCandidate struct {
startTs uint64
skipSyncpointAtStartTs bool
skipDMLAsStartTs bool
allSamePending bool
pendingCommitTs uint64
pendingIsSyncPoint bool
}
func buildMergedStartTsCandidate(minCheckpointTs uint64, pendingStates []*heartbeatpb.State) mergedStartTsCandidate {
candidate := mergedStartTsCandidate{
startTs: minCheckpointTs,
skipSyncpointAtStartTs: false,
skipDMLAsStartTs: false,
allSamePending: true,
}
if len(pendingStates) == 0 {
// Defensive: without per-dispatcher pending barrier states, we can only fall back to the
// conservative choice (min checkpointTs) and avoid inferring anything about barriers.
candidate.allSamePending = false
return candidate
}
var pendingCommitTs uint64
var pendingIsSyncPoint bool
for idx, state := range pendingStates {
if state == nil {
// If any source dispatcher is not waiting on a barrier, we can't derive a barrier-aligned startTs.
candidate.allSamePending = false
break
}
if idx == 0 {
pendingCommitTs = state.BlockTs
pendingIsSyncPoint = state.IsSyncPoint
continue
}
if state.BlockTs != pendingCommitTs || state.IsSyncPoint != pendingIsSyncPoint {
// Mixed barrier states imply the merged dispatcher should start from minCheckpointTs.
candidate.allSamePending = false
break
}
}
candidate.pendingCommitTs = pendingCommitTs
candidate.pendingIsSyncPoint = pendingIsSyncPoint
if candidate.allSamePending {
// When all source dispatchers are blocked by the same barrier, pick a startTs that can replay it safely:
// - Syncpoint: start from commitTs.
// - DDL: start from (commitTs-1) to replay the DDL at commitTs and skip duplicate DML at commitTs.
if pendingIsSyncPoint {
candidate.startTs = pendingCommitTs
} else if pendingCommitTs > 0 {
candidate.startTs = pendingCommitTs - 1
candidate.skipDMLAsStartTs = true
}
}
return candidate
}
func mergeMergedStartTsCandidateWithMySQLRecovery(t *MergeCheckTask, candidate mergedStartTsCandidate) (uint64, bool, bool) {
finalStartTs := candidate.startTs
finalSkipSyncpointAtStartTs := candidate.skipSyncpointAtStartTs
finalSkipDMLAsStartTs := candidate.skipDMLAsStartTs
if !common.IsDefaultMode(t.mergedDispatcher.GetMode()) || t.manager.sink.SinkType() != common.MysqlSinkType {
// Only default-mode MySQL needs ddl_ts-based crash recovery; other sinks/modes keep the candidate decision.
return finalStartTs, finalSkipSyncpointAtStartTs, finalSkipDMLAsStartTs
}
newStartTsList, skipSyncpointAtStartTsList, skipDMLAsStartTsList, err := t.manager.sink.(*mysql.Sink).GetTableRecoveryInfo(
[]int64{t.mergedDispatcher.GetTableSpan().TableID},
[]int64{int64(candidate.startTs)},
false,
)
if err != nil {
log.Error("get table recovery info for merge dispatcher failed",
zap.Stringer("dispatcherID", t.mergedDispatcher.GetId()),
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Error(err),
)
t.mergedDispatcher.HandleError(err)
return finalStartTs, finalSkipSyncpointAtStartTs, finalSkipDMLAsStartTs
}
recoveryStartTs := uint64(newStartTsList[0])
recoverySkipSyncpointAtStartTs := skipSyncpointAtStartTsList[0]
recoverySkipDMLAsStartTs := skipDMLAsStartTsList[0]
if recoveryStartTs > candidate.startTs {
finalStartTs = recoveryStartTs
finalSkipSyncpointAtStartTs = recoverySkipSyncpointAtStartTs
finalSkipDMLAsStartTs = recoverySkipDMLAsStartTs
} else if recoveryStartTs == candidate.startTs {
finalSkipSyncpointAtStartTs = candidate.skipSyncpointAtStartTs || recoverySkipSyncpointAtStartTs
finalSkipDMLAsStartTs = candidate.skipDMLAsStartTs || recoverySkipDMLAsStartTs
}
log.Info("get table recovery info for merge dispatcher",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Uint64("mergeStartTsCandidate", candidate.startTs),
zap.Any("recoveryStartTs", newStartTsList),
zap.Any("recoverySkipSyncpointAtStartTsList", skipSyncpointAtStartTsList),
zap.Any("recoverySkipDMLAsStartTsList", skipDMLAsStartTsList),
zap.Uint64("finalStartTs", finalStartTs),
zap.Bool("finalSkipSyncpointAtStartTs", finalSkipSyncpointAtStartTs),
zap.Bool("finalSkipDMLAsStartTs", finalSkipDMLAsStartTs),
)
return finalStartTs, finalSkipSyncpointAtStartTs, finalSkipDMLAsStartTs
}
// resolveMergedDispatcherStartTs returns the effective startTs and skip flags for the merged dispatcher.
//
// Inputs:
// - minCheckpointTs: min checkpointTs among all source dispatchers, collected after they are closed.
// - pendingStates: per-source block state from GetBlockEventStatus() captured at close time.
//
// Algorithm:
// 1. Build a merge candidate from minCheckpointTs.
// If all source dispatchers have a non-nil pending block state and they refer to the same (commitTs, isSyncPoint),
// adjust the merge candidate so the merged dispatcher can replay that block event safely:
// - DDL: startTs = commitTs - 1, skipDMLAsStartTs = true.
// - SyncPoint: startTs = commitTs.
// The merge candidate always uses skipSyncpointAtStartTs = false.
// 2. If the sink is MySQL, query downstream ddl_ts recovery info using the merge candidate startTs and merge the results:
// - If recoveryStartTs > mergeStartTsCandidate: use recoveryStartTs and its skip flags.
// - If recoveryStartTs == mergeStartTsCandidate: OR the skip flags.
// - If recoveryStartTs < mergeStartTsCandidate: keep the merge candidate.
// If the query fails, the error is reported via mergedDispatcher.HandleError and the merge candidate is returned.
//
// For non-MySQL and redo, the merge candidate is the final result.
func resolveMergedDispatcherStartTs(t *MergeCheckTask, minCheckpointTs uint64, pendingStates []*heartbeatpb.State) (uint64, bool, bool) {
candidate := buildMergedStartTsCandidate(minCheckpointTs, pendingStates)
if candidate.allSamePending {
if !candidate.pendingIsSyncPoint && candidate.pendingCommitTs == 0 {
log.Warn("pending ddl has zero commit ts, fallback to min checkpoint ts",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Uint64("minCheckpointTs", minCheckpointTs),
zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()))
}
log.Info("merge dispatcher uses pending block event to calculate start ts",
zap.Stringer("changefeedID", t.manager.changefeedID),
zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()),
zap.Uint64("pendingCommitTs", candidate.pendingCommitTs),
zap.Bool("pendingIsSyncPoint", candidate.pendingIsSyncPoint),
zap.Uint64("startTs", candidate.startTs),
zap.Bool("skipSyncpointAtStartTs", candidate.skipSyncpointAtStartTs),
zap.Bool("skipDMLAsStartTs", candidate.skipDMLAsStartTs),
)
}
return mergeMergedStartTsCandidateWithMySQLRecovery(t, candidate)
}
var (
removeDispatcherTaskSchedulerOnce sync.Once
removeDispatcherTaskScheduler threadpool.ThreadPool
)
func GetRemoveDispatcherTaskScheduler() threadpool.ThreadPool {
removeDispatcherTaskSchedulerOnce.Do(func() {
removeDispatcherTaskScheduler = threadpool.NewThreadPoolDefault()
})
return removeDispatcherTaskScheduler
}
// RemoveDispatcherTask is a task to asynchronously remove a dispatcher until the dispatcher can be closed
type RemoveDispatcherTask struct {
manager *DispatcherManager
dispatcherItem dispatcher.Dispatcher
retryCount int
}
func (t *RemoveDispatcherTask) Execute() time.Time {
// Check if manager is closed
if t.manager.closed.Load() {
return time.Time{}
}
// If the dispatcher is removing, we don't need to remove it again
if t.dispatcherItem.GetRemovingStatus() {
return time.Time{}
}
// Try to close the dispatcher
_, ok := t.dispatcherItem.TryClose()
if ok {
// Successfully closed, execute Remove
t.dispatcherItem.Remove()
log.Info("dispatcher removed successfully",
zap.Stringer("dispatcherID", t.dispatcherItem.GetId()),
zap.Int("retryCount", t.retryCount))
return time.Time{} // Task completed
}
// Not successfully closed, retry
t.retryCount++
// Log periodically
if t.retryCount%50 == 0 {
log.Info("still retrying dispatcher close",
zap.Stringer("dispatcherID", t.dispatcherItem.GetId()),
zap.Int("retryCount", t.retryCount))
}
// Retry after 10ms, never give up
return time.Now().Add(10 * time.Millisecond)
}