Skip to content

Commit 5225f13

Browse files
yycpttrodrigozhou
authored andcommitted
Fix task attempt reset (#4276)
1 parent 9448a6f commit 5225f13

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

service/history/queues/executable.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ func (e *executableImpl) Execute() (retErr error) {
212212
e.taggedMetricsHandler = e.metricsHandler.WithTags(metricsTags...)
213213

214214
if isActive != e.lastActiveness {
215-
// namespace did a failover, reset task attempt
216-
e.Lock()
217-
e.attempt = 0
218-
e.Unlock()
215+
// namespace did a failover,
216+
// reset task attempt since the execution logic used will change
217+
e.resetAttempt()
219218
}
220219
e.lastActiveness = isActive
221220

@@ -524,6 +523,13 @@ func (e *executableImpl) updatePriority() {
524523
}
525524
}
526525

526+
func (e *executableImpl) resetAttempt() {
527+
e.Lock()
528+
defer e.Unlock()
529+
530+
e.attempt = 1
531+
}
532+
527533
func (e *executableImpl) estimateTaskMetricTag() []metrics.Tag {
528534
namespaceTag := metrics.NamespaceUnknownTag()
529535
isActive := true

service/history/queues/executable_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ func (s *executableSuite) TestExecute_CallerInfo() {
149149
s.NoError(executable.Execute())
150150
}
151151

152+
func (s *executableSuite) TestExecuteHandleErr_ResetAttempt() {
153+
executable := s.newTestExecutable()
154+
s.mockExecutor.EXPECT().Execute(gomock.Any(), executable).Return(nil, true, errors.New("some random error"))
155+
err := executable.Execute()
156+
s.Error(err)
157+
s.Error(executable.HandleErr(err))
158+
s.Equal(2, executable.Attempt())
159+
160+
// isActive changed to false, should reset attempt
161+
s.mockExecutor.EXPECT().Execute(gomock.Any(), executable).Return(nil, false, nil)
162+
s.NoError(executable.Execute())
163+
s.Equal(1, executable.Attempt())
164+
}
165+
152166
func (s *executableSuite) TestExecuteHandleErr_Corrupted() {
153167
executable := s.newTestExecutable()
154168

0 commit comments

Comments
 (0)