Skip to content

Commit

Permalink
Fix regression with GetWorkflow (need to check if execution row exist…
Browse files Browse the repository at this point in the history
…s before locking it; otherwise return EntityNotExists in order to pass DeleteWorkflow test)
  • Loading branch information
uber-qlam committed Aug 3, 2018
1 parent fd485d9 commit ef41d12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ func (s *matchingPersistenceSuite) TestWorkflowMutableState_Timers() {
s.Equal(1, len(state.TimerInfos))
s.Equal(int64(3345), state.TimerInfos[timerID].Version)
s.Equal(timerID, state.TimerInfos[timerID].TimerID)
s.Equal(currentTime.Unix(), state.TimerInfos[timerID].ExpiryTime.Unix())
s.Equal(currentTime.Unix(), state.TimerInfos[timerID].ExpiryTime.Unix()) // flakey
s.Equal(int64(2), state.TimerInfos[timerID].TaskID)
s.Equal(int64(5), state.TimerInfos[timerID].StartedID)

Expand Down
16 changes: 14 additions & 2 deletions common/persistence/sql/sqlMatchingPersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,15 @@ func (m *sqlMatchingManager) GetWorkflowExecution(request *persistence.GetWorkfl

if _, err := lockNextEventID(tx, m.shardID, request.DomainID, *request.Execution.WorkflowId, *request.Execution.RunId);
err != nil {
return nil, &workflow.InternalServiceError{
Message: fmt.Sprintf("GetWorkflowExecution operation failed. Failed to write-lock executions row. Error: %v", err),
switch err.(type) {
case *workflow.EntityNotExistsError:
return nil, &workflow.EntityNotExistsError{
Message: fmt.Sprintf("GetWorkflowExecution operation failed. Error: %v", err),
}
default:
return nil, &workflow.InternalServiceError{
Message: fmt.Sprintf("GetWorkflowExecution operation failed. Failed to write-lock executions row. Error: %v", err),
}
}
}

Expand Down Expand Up @@ -1188,6 +1195,11 @@ func lockAndCheckNextEventID(tx *sqlx.Tx, shardID int, domainID, workflowID, run
func lockNextEventID(tx *sqlx.Tx, shardID int, domainID, workflowID, runID string) (*int64, error) {
var nextEventID int64
if err := tx.Get(&nextEventID, lockAndCheckNextEventIdSQLQuery, shardID, domainID, workflowID, runID); err != nil {
if err == sql.ErrNoRows {
return nil, &workflow.EntityNotExistsError{
Message: fmt.Sprintf("Failed to lock executions row with (shard, domain, workflow, run) = (%v,%v,%v,%v) which does not exist.", shardID, domainID, workflowID, runID),
}
}
return nil, &workflow.InternalServiceError{
Message: fmt.Sprintf("Failed to lock executions row. Error: %v", err),
}
Expand Down
3 changes: 2 additions & 1 deletion common/persistence/sql/workflowStateNonMaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ func getSignalsRequested(tx *sqlx.Tx,
ret[s] = struct{}{}
}
return ret, nil
}
}

0 comments on commit ef41d12

Please sign in to comment.