Skip to content

Commit

Permalink
Pass
Browse files Browse the repository at this point in the history
  • Loading branch information
uber-qlam committed Jul 31, 2018
1 parent 04ae7b9 commit 14cb2c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,8 @@ func (s *matchingPersistenceSuite) TestContinueAsNew() {
RunId: common.StringPtr("64c7e15a-3fd7-4182-9c6f-6f25a4fa2614"),
}
err2 := s.ContinueAsNewExecution(continueAsNewInfo, info0.NextEventID, newWorkflowExecution, int64(3), int64(2))

//panic(3)
s.Nil(err2, "No error expected.")

prevExecutionState, err3 := s.GetWorkflowExecutionInfo(domainID, workflowExecution)
Expand All @@ -1710,6 +1712,7 @@ func (s *matchingPersistenceSuite) TestContinueAsNew() {
s.Equal(common.EmptyEventID, newExecutionInfo.LastProcessedEvent)
s.Equal(int64(2), newExecutionInfo.DecisionScheduleID)

//panic(3)
newRunID, err5 := s.GetCurrentWorkflowRunID(domainID, *workflowExecution.WorkflowId)
s.Nil(err5)
s.Equal(*newWorkflowExecution.RunId, newRunID)
Expand Down
51 changes: 5 additions & 46 deletions common/persistence/sql/sqlMatchingPersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,6 @@ domain_id = ? AND
workflow_id = ?
FOR UPDATE`

continueAsNewUpdateExecutionsSQLQuery = `UPDATE executions SET
run_id = :run_id,
create_request_id = :create_request_id,
state = :state,
close_status = :close_status,
start_version = :start_version
WHERE
shard_id = :shard_id AND
domain_id = :domain_id AND
workflow_id = :workflow_id AND
run_id = :previous_run_id
`

continueAsNewUpdateCurrentExecutionsSQLQuery = `UPDATE current_executions SET
run_id = :run_id,
create_request_id = :create_request_id,
Expand Down Expand Up @@ -774,6 +761,10 @@ func (m *sqlMatchingManager) UpdateWorkflowExecution(request *persistence.Update
}

if request.ContinueAsNew != nil {
if err := createCurrentExecution(tx, request.ContinueAsNew, m.shardID); err != nil {
return err
}

if err := createExecution(tx, request.ContinueAsNew, m.shardID, time.Now()); err != nil {
return err
}
Expand Down Expand Up @@ -1308,6 +1299,7 @@ func createTimerTasks(tx *sqlx.Tx, timerTasks []persistence.Task, deleteTimerTas

func continueAsNew(tx *sqlx.Tx, shardID int, domainID, workflowID, runID, previousRunID string,
createRequestID string, state int64, closeStatus int64, startVersion int64) error {

var currentRunID string
if err := tx.Get(&currentRunID, continueAsNewLockRunIDSQLQuery, int64(shardID), domainID, workflowID); err != nil {
return &workflow.InternalServiceError{
Expand All @@ -1321,39 +1313,6 @@ func continueAsNew(tx *sqlx.Tx, shardID int, domainID, workflowID, runID, previo
}

// The current_executions row is locked, and the run ID has been verified. We can do the updates.
if result, err := tx.NamedExec(continueAsNewUpdateExecutionsSQLQuery, &struct {
currentExecutionRow
PreviousRunID string `db:"previous_run_id"`
}{
currentExecutionRow{
ShardID: int64(shardID),
DomainID: domainID,
WorkflowID: workflowID,
RunID: runID,
CreateRequestID: createRequestID,
State: state,
CloseStatus: closeStatus,
StartVersion: &startVersion,
},
previousRunID,
}); err != nil {
return &workflow.InternalServiceError{
Message: fmt.Sprintf("ContinueAsNew failed. Failed to update executions table. Error: %v", err),
}
} else {
rowsAffected, err := result.RowsAffected()
if err != nil {
return &workflow.InternalServiceError{
Message: fmt.Sprintf("ContinueAsNew failed. Failed to check number of rows updated in executions table. Error: %v", err),
}
}
if rowsAffected != 1 {
return &workflow.InternalServiceError{
Message: fmt.Sprintf("ContinueAsNew failed. %v rows of executions affected instead of 1.", rowsAffected),
}
}
}

if result, err := tx.NamedExec(continueAsNewUpdateCurrentExecutionsSQLQuery, &currentExecutionRow{
ShardID: int64(shardID),
DomainID: domainID,
Expand Down

0 comments on commit 14cb2c3

Please sign in to comment.