@@ -132,7 +132,7 @@ type (
132
132
taskSequenceNumber int64
133
133
maxTaskSequenceNumber int64
134
134
immediateTaskExclusiveMaxReadLevel int64
135
- scheduledTaskMaxReadLevelMap map [ string ]time. Time // cluster -> scheduledTaskMaxReadLevel
135
+ scheduledTaskMaxReadLevel time. Time
136
136
137
137
// exist only in memory
138
138
remoteClusterInfos map [string ]* remoteClusterInfo
@@ -295,50 +295,26 @@ func (s *ContextImpl) getScheduledTaskMaxReadLevel(cluster string) tasks.Key {
295
295
s .rLock ()
296
296
defer s .rUnlock ()
297
297
298
- if _ , ok := s .scheduledTaskMaxReadLevelMap [cluster ]; ! ok {
299
- s .scheduledTaskMaxReadLevelMap [cluster ] = tasks .DefaultFireTime
300
- }
301
-
302
- return tasks .NewKey (s .scheduledTaskMaxReadLevelMap [cluster ], 0 )
298
+ return tasks .NewKey (s .scheduledTaskMaxReadLevel , 0 )
303
299
}
304
300
305
- func (s * ContextImpl ) UpdateScheduledQueueExclusiveHighReadWatermark (
306
- cluster string ,
307
- singleProcessorMode bool ,
308
- ) (tasks.Key , error ) {
301
+ func (s * ContextImpl ) UpdateScheduledQueueExclusiveHighReadWatermark () (tasks.Key , error ) {
309
302
s .wLock ()
310
303
defer s .wUnlock ()
311
304
312
- if _ , ok := s .scheduledTaskMaxReadLevelMap [cluster ]; ! ok {
313
- s .scheduledTaskMaxReadLevelMap [cluster ] = tasks .DefaultFireTime
314
- }
315
-
316
305
if err := s .errorByState (); err != nil {
317
- return tasks .NewKey (s .scheduledTaskMaxReadLevelMap [ cluster ] , 0 ), err
306
+ return tasks .NewKey (s .scheduledTaskMaxReadLevel , 0 ), err
318
307
}
319
308
320
309
currentTime := s .timeSource .Now ()
321
- if cluster != "" && cluster != s .GetClusterMetadata ().GetCurrentClusterName () {
322
- currentTime = s .getOrUpdateRemoteClusterInfoLocked (cluster ).CurrentTime
323
- }
324
310
325
311
// Truncation here is just to make sure max read level has the same precision as the old logic
326
312
// in case existing code can't work correctly with precision higher than 1ms.
327
313
// Once we validate the rest of the code can worker correctly with higher precision, the truncation should be removed.
328
314
newMaxReadLevel := currentTime .Add (s .config .TimerProcessorMaxTimeShift ()).Truncate (persistence .ScheduledTaskMinPrecision )
329
- if singleProcessorMode {
330
- // When generating scheduled tasks, the task's timestamp will be compared to the namespace's active cluster's
331
- // maxReadLevel to avoid generatnig a task before maxReadLevel.
332
- // But when there's a single procssor, the queue is only using current cluster maxReadLevel.
333
- // So update the maxReadLevel map for all clusters to ensure scheduled task won't be lost.
334
- for key := range s .scheduledTaskMaxReadLevelMap {
335
- s .scheduledTaskMaxReadLevelMap [key ] = util .MaxTime (s .scheduledTaskMaxReadLevelMap [key ], newMaxReadLevel )
336
- }
337
- } else {
338
- s .scheduledTaskMaxReadLevelMap [cluster ] = util .MaxTime (s .scheduledTaskMaxReadLevelMap [cluster ], newMaxReadLevel )
339
- }
315
+ s .scheduledTaskMaxReadLevel = util .MaxTime (s .scheduledTaskMaxReadLevel , newMaxReadLevel )
340
316
341
- return tasks .NewKey (s .scheduledTaskMaxReadLevelMap [ cluster ] , 0 ), nil
317
+ return tasks .NewKey (s .scheduledTaskMaxReadLevel , 0 ), nil
342
318
}
343
319
344
320
// NOTE: the ack level returned is inclusive for immediate task category (acked),
@@ -1388,7 +1364,6 @@ func (s *ContextImpl) allocateTaskIDAndTimestampLocked(
1388
1364
transferExclusiveMaxReadLevel * int64 ,
1389
1365
) error {
1390
1366
now := s .timeSource .Now ()
1391
- currentCluster := s .GetClusterMetadata ().GetCurrentClusterName ()
1392
1367
for category , tasksByCategory := range newTasks {
1393
1368
for _ , task := range tasksByCategory {
1394
1369
// set taskID
@@ -1409,13 +1384,7 @@ func (s *ContextImpl) allocateTaskIDAndTimestampLocked(
1409
1384
// if scheduled task, check if fire time is in the past
1410
1385
if category .Type () == tasks .CategoryTypeScheduled {
1411
1386
ts := task .GetVisibilityTime ()
1412
- if task .GetVersion () != common .EmptyVersion && category .ID () == tasks .CategoryIDTimer {
1413
- // cannot use version to determine the corresponding cluster for timer task
1414
- // this is because during failover, timer task should be created as active
1415
- // or otherwise, failover + active processing logic may not pick up the task.
1416
- currentCluster = namespaceEntry .ActiveClusterName ()
1417
- }
1418
- readCursorTS := s .scheduledTaskMaxReadLevelMap [currentCluster ]
1387
+ readCursorTS := s .scheduledTaskMaxReadLevel
1419
1388
if ts .Truncate (persistence .ScheduledTaskMinPrecision ).Before (readCursorTS ) {
1420
1389
// make sure scheduled task timestamp is higher than max read level after truncation
1421
1390
// as persistence layer may lose precision when persisting the task.
@@ -1427,12 +1396,14 @@ func (s *ContextImpl) allocateTaskIDAndTimestampLocked(
1427
1396
tag .Timestamp (ts ),
1428
1397
tag .CursorTimestamp (readCursorTS ),
1429
1398
tag .ValueShardAllocateTimerBeforeRead )
1430
- task .SetVisibilityTime (s .scheduledTaskMaxReadLevelMap [ currentCluster ] .Add (persistence .ScheduledTaskMinPrecision ))
1399
+ task .SetVisibilityTime (s .scheduledTaskMaxReadLevel .Add (persistence .ScheduledTaskMinPrecision ))
1431
1400
}
1432
1401
1433
- visibilityTs := task .GetVisibilityTime ()
1434
1402
s .contextTaggedLogger .Debug ("Assigning new timer" ,
1435
- tag .Timestamp (visibilityTs ), tag .TaskID (task .GetTaskID ()), tag .MaxQueryLevel (readCursorTS ))
1403
+ tag .Timestamp (task .GetVisibilityTime ()),
1404
+ tag .TaskID (task .GetTaskID ()),
1405
+ tag .MaxQueryLevel (readCursorTS ),
1406
+ )
1436
1407
}
1437
1408
}
1438
1409
}
@@ -1849,7 +1820,7 @@ func (s *ContextImpl) loadShardMetadata(ownershipChanged *bool) error {
1849
1820
1850
1821
// initialize the cluster current time to be the same as ack level
1851
1822
remoteClusterInfos := make (map [string ]* remoteClusterInfo )
1852
- scheduledTaskMaxReadLevelMap := make ( map [ string ] time.Time )
1823
+ var scheduledTaskMaxReadLevel time.Time
1853
1824
currentClusterName := s .GetClusterMetadata ().GetCurrentClusterName ()
1854
1825
taskCategories := tasks .GetCategories ()
1855
1826
for clusterName , info := range s .GetClusterMetadata ().GetAllClusterInfo () {
@@ -1890,8 +1861,11 @@ func (s *ContextImpl) loadShardMetadata(ownershipChanged *bool) error {
1890
1861
// Add().Truncate() here is just to make sure max read level has the same precision as the old logic
1891
1862
// in case existing code can't work correctly with precision higher than 1ms.
1892
1863
// Once we validate the rest of the code can worker correctly with higher precision, the code should simply be
1893
- // scheduledTaskMaxReadLevelMap[clusterName] = maxReadTime
1894
- scheduledTaskMaxReadLevelMap [clusterName ] = maxReadTime .Add (persistence .ScheduledTaskMinPrecision ).Truncate (persistence .ScheduledTaskMinPrecision )
1864
+ // scheduledTaskMaxReadLevel = util.MaxTime(scheduledTaskMaxReadLevel, maxReadTime)
1865
+ scheduledTaskMaxReadLevel = util .MaxTime (
1866
+ scheduledTaskMaxReadLevel ,
1867
+ maxReadTime .Add (persistence .ScheduledTaskMinPrecision ).Truncate (persistence .ScheduledTaskMinPrecision ),
1868
+ )
1895
1869
1896
1870
if clusterName != currentClusterName {
1897
1871
remoteClusterInfos [clusterName ] = & remoteClusterInfo {CurrentTime : maxReadTime }
@@ -1903,7 +1877,7 @@ func (s *ContextImpl) loadShardMetadata(ownershipChanged *bool) error {
1903
1877
1904
1878
s .shardInfo = updatedShardInfo
1905
1879
s .remoteClusterInfos = remoteClusterInfos
1906
- s .scheduledTaskMaxReadLevelMap = scheduledTaskMaxReadLevelMap
1880
+ s .scheduledTaskMaxReadLevel = scheduledTaskMaxReadLevel
1907
1881
1908
1882
return nil
1909
1883
}
0 commit comments