Skip to content

Commit

Permalink
Fix task attempt reset (#4276)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt committed May 3, 2023
1 parent b757d8b commit 6e43d54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions service/history/queues/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ func (e *executableImpl) Execute() (retErr error) {
e.taggedMetricsHandler = e.metricsHandler.WithTags(metricsTags...)

if isActive != e.lastActiveness {
// namespace did a failover, reset task attempt
e.Lock()
e.attempt = 0
e.Unlock()
// namespace did a failover,
// reset task attempt since the execution logic used will change
e.resetAttempt()
}
e.lastActiveness = isActive

Expand Down Expand Up @@ -535,6 +534,13 @@ func (e *executableImpl) updatePriority() {
}
}

func (e *executableImpl) resetAttempt() {
e.Lock()
defer e.Unlock()

e.attempt = 1
}

func (e *executableImpl) estimateTaskMetricTag() []metrics.Tag {
namespaceTag := metrics.NamespaceUnknownTag()
isActive := true
Expand Down
14 changes: 14 additions & 0 deletions service/history/queues/executable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ func (s *executableSuite) TestExecute_CallerInfo() {
s.NoError(executable.Execute())
}

func (s *executableSuite) TestExecuteHandleErr_ResetAttempt() {
executable := s.newTestExecutable()
s.mockExecutor.EXPECT().Execute(gomock.Any(), executable).Return(nil, true, errors.New("some random error"))
err := executable.Execute()
s.Error(err)
s.Error(executable.HandleErr(err))
s.Equal(2, executable.Attempt())

// isActive changed to false, should reset attempt
s.mockExecutor.EXPECT().Execute(gomock.Any(), executable).Return(nil, false, nil)
s.NoError(executable.Execute())
s.Equal(1, executable.Attempt())
}

func (s *executableSuite) TestExecuteHandleErr_Corrupted() {
executable := s.newTestExecutable()

Expand Down

0 comments on commit 6e43d54

Please sign in to comment.