@@ -383,16 +383,16 @@ func (e *historyEngineImpl) StartWorkflowExecution(
383
383
startRequest * h.StartWorkflowExecutionRequest ,
384
384
) (resp * workflow.StartWorkflowExecutionResponse , retError error ) {
385
385
386
- domainEntry , retError := e .getActiveDomainEntry (startRequest .DomainUUID )
387
- if retError != nil {
388
- return
386
+ domainEntry , err := e .getActiveDomainEntry (startRequest .DomainUUID )
387
+ if err != nil {
388
+ return nil , err
389
389
}
390
390
domainID := domainEntry .GetInfo ().ID
391
391
392
392
request := startRequest .StartRequest
393
- retError = validateStartWorkflowExecutionRequest (request , e .config .MaxIDLengthLimit ())
394
- if retError != nil {
395
- return
393
+ err = validateStartWorkflowExecutionRequest (request , e .config .MaxIDLengthLimit ())
394
+ if err != nil {
395
+ return nil , err
396
396
}
397
397
398
398
workflowID := request .GetWorkflowId ()
@@ -424,18 +424,17 @@ func (e *historyEngineImpl) StartWorkflowExecution(
424
424
}
425
425
}
426
426
427
- _ , retError = msBuilder .AddWorkflowExecutionStartedEvent (execution , startRequest )
428
- if retError != nil {
429
- retError = & workflow.InternalServiceError {Message : "Failed to add workflow execution started event." }
430
- return
427
+ _ , err = msBuilder .AddWorkflowExecutionStartedEvent (execution , startRequest )
428
+ if err != nil {
429
+ return nil , & workflow.InternalServiceError {Message : "Failed to add workflow execution started event." }
431
430
}
432
431
433
432
taskList := request .TaskList .GetName ()
434
433
cronBackoffSeconds := startRequest .GetFirstDecisionTaskBackoffSeconds ()
435
434
// Generate first decision task event if not child WF and no first decision task backoff
436
- transferTasks , _ , retError := e .generateFirstDecisionTask (domainID , msBuilder , startRequest .ParentExecutionInfo , taskList , cronBackoffSeconds )
437
- if retError != nil {
438
- return
435
+ transferTasks , _ , err := e .generateFirstDecisionTask (domainID , msBuilder , startRequest .ParentExecutionInfo , taskList , cronBackoffSeconds )
436
+ if err != nil {
437
+ return nil , err
439
438
}
440
439
441
440
// Generate first timer task : WF timeout task
@@ -457,9 +456,9 @@ func (e *historyEngineImpl) StartWorkflowExecution(
457
456
createReplicationTask := domainEntry .CanReplicateEvent ()
458
457
replicationTasks := []persistence.Task {}
459
458
var replicationTask persistence.Task
460
- _ , replicationTask , retError = context .appendFirstBatchEventsForActive (msBuilder , createReplicationTask )
461
- if retError != nil {
462
- return
459
+ _ , replicationTask , err = context .appendFirstBatchEventsForActive (msBuilder , createReplicationTask )
460
+ if err != nil {
461
+ return nil , err
463
462
}
464
463
if replicationTask != nil {
465
464
replicationTasks = append (replicationTasks , replicationTask )
@@ -469,53 +468,54 @@ func (e *historyEngineImpl) StartWorkflowExecution(
469
468
createMode := persistence .CreateWorkflowModeBrandNew
470
469
prevRunID := ""
471
470
prevLastWriteVersion := int64 (0 )
472
- retError = context .createWorkflowExecution (
471
+ err = context .createWorkflowExecution (
473
472
msBuilder , e .currentClusterName , createReplicationTask , e .timeSource .Now (),
474
473
transferTasks , replicationTasks , timerTasks ,
475
474
createMode , prevRunID , prevLastWriteVersion ,
476
475
)
477
- if retError != nil {
478
- t , ok := retError .(* persistence.WorkflowExecutionAlreadyStartedError )
479
- if ok {
476
+ if err != nil {
477
+ if t , ok := err .(* persistence.WorkflowExecutionAlreadyStartedError ); ok {
480
478
if t .StartRequestID == * request .RequestId {
479
+ e .deleteEvents (domainID , execution , eventStoreVersion , msBuilder .GetCurrentBranch ())
481
480
return & workflow.StartWorkflowExecutionResponse {
482
481
RunId : common .StringPtr (t .RunID ),
483
482
}, nil
484
483
// delete history is expected here because duplicate start request will create history with different rid
485
484
}
486
485
487
486
if msBuilder .GetCurrentVersion () < t .LastWriteVersion {
488
- retError = ce .NewDomainNotActiveError (
487
+ e .deleteEvents (domainID , execution , eventStoreVersion , msBuilder .GetCurrentBranch ())
488
+ return nil , ce .NewDomainNotActiveError (
489
489
* request .Domain ,
490
490
clusterMetadata .GetCurrentClusterName (),
491
491
clusterMetadata .ClusterNameForFailoverVersion (t .LastWriteVersion ),
492
492
)
493
- return
494
493
}
495
494
496
495
// create as ID reuse
497
496
createMode = persistence .CreateWorkflowModeWorkflowIDReuse
498
497
prevRunID = t .RunID
499
498
prevLastWriteVersion = t .LastWriteVersion
500
- retError = e .applyWorkflowIDReusePolicyHelper (t .StartRequestID , prevRunID , t .State , t .CloseStatus , domainID , execution , startRequest .StartRequest .GetWorkflowIdReusePolicy ())
501
- if retError != nil {
502
- return
499
+ err = e .applyWorkflowIDReusePolicyHelper (t .StartRequestID , prevRunID , t .State , t .CloseStatus , domainID , execution , startRequest .StartRequest .GetWorkflowIdReusePolicy ())
500
+ if err != nil {
501
+ e .deleteEvents (domainID , execution , eventStoreVersion , msBuilder .GetCurrentBranch ())
502
+ return nil , err
503
503
}
504
- retError = context .createWorkflowExecution (
504
+ err = context .createWorkflowExecution (
505
505
msBuilder , e .currentClusterName , createReplicationTask , e .timeSource .Now (),
506
506
transferTasks , replicationTasks , timerTasks ,
507
507
createMode , prevRunID , prevLastWriteVersion ,
508
508
)
509
509
}
510
510
}
511
511
512
- if retError == nil || persistence .IsTimeoutError (retError ) {
513
- e .timerProcessor .NotifyNewTimers (e .currentClusterName , e .shard .GetCurrentTime (e .currentClusterName ), timerTasks )
514
- return & workflow.StartWorkflowExecutionResponse {
515
- RunId : execution .RunId ,
516
- }, retError
512
+ e .timerProcessor .NotifyNewTimers (e .currentClusterName , e .shard .GetCurrentTime (e .currentClusterName ), timerTasks )
513
+ if err != nil {
514
+ return nil , err
517
515
}
518
- return
516
+ return & workflow.StartWorkflowExecutionResponse {
517
+ RunId : execution .RunId ,
518
+ }, nil
519
519
}
520
520
521
521
// GetMutableState retrieves the mutable state of the workflow execution
@@ -1377,9 +1377,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1377
1377
signalWithStartRequest * h.SignalWithStartWorkflowExecutionRequest ,
1378
1378
) (retResp * workflow.StartWorkflowExecutionResponse , retError error ) {
1379
1379
1380
- domainEntry , retError := e .getActiveDomainEntry (signalWithStartRequest .DomainUUID )
1381
- if retError != nil {
1382
- return
1380
+ domainEntry , err := e .getActiveDomainEntry (signalWithStartRequest .DomainUUID )
1381
+ if err != nil {
1382
+ return nil , err
1383
1383
}
1384
1384
domainID := domainEntry .GetInfo ().ID
1385
1385
@@ -1450,9 +1450,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1450
1450
}
1451
1451
// Generate a transaction ID for appending events to history
1452
1452
var transactionID int64
1453
- transactionID , retError = e .shard .GetNextTransferTaskID ()
1454
- if retError != nil {
1455
- return
1453
+ transactionID , err = e .shard .GetNextTransferTaskID ()
1454
+ if err != nil {
1455
+ return nil , err
1456
1456
}
1457
1457
1458
1458
// We apply the update to execution using optimistic concurrency. If it fails due to a conflict then reload
@@ -1479,9 +1479,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1479
1479
// Start workflow and signal
1480
1480
startRequest := getStartRequest (domainID , sRequest )
1481
1481
request := startRequest .StartRequest
1482
- retError = validateStartWorkflowExecutionRequest (request , e .config .MaxIDLengthLimit ())
1483
- if retError != nil {
1484
- return
1482
+ err = validateStartWorkflowExecutionRequest (request , e .config .MaxIDLengthLimit ())
1483
+ if err != nil {
1484
+ return nil , err
1485
1485
}
1486
1486
1487
1487
workflowID := request .GetWorkflowId ()
@@ -1508,8 +1508,8 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1508
1508
eventStoreVersion = persistence .EventStoreVersionV2
1509
1509
}
1510
1510
if eventStoreVersion == persistence .EventStoreVersionV2 {
1511
- if retError = msBuilder .SetHistoryTree (* execution .RunId ); retError != nil {
1512
- return
1511
+ if err = msBuilder .SetHistoryTree (* execution .RunId ); err != nil {
1512
+ return nil , err
1513
1513
}
1514
1514
}
1515
1515
@@ -1526,9 +1526,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1526
1526
policy = * request .WorkflowIdReusePolicy
1527
1527
}
1528
1528
1529
- retError = e .applyWorkflowIDReusePolicyForSigWithStart (prevMutableState .GetExecutionInfo (), domainID , execution , policy )
1530
- if retError != nil {
1531
- return
1529
+ err = e .applyWorkflowIDReusePolicyForSigWithStart (prevMutableState .GetExecutionInfo (), domainID , execution , policy )
1530
+ if err != nil {
1531
+ return nil , err
1532
1532
}
1533
1533
}
1534
1534
@@ -1548,9 +1548,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1548
1548
}
1549
1549
// first decision task
1550
1550
var transferTasks []persistence.Task
1551
- transferTasks , _ , retError = e .generateFirstDecisionTask (domainID , msBuilder , startRequest .ParentExecutionInfo , taskList , 0 )
1552
- if retError != nil {
1553
- return
1551
+ transferTasks , _ , err = e .generateFirstDecisionTask (domainID , msBuilder , startRequest .ParentExecutionInfo , taskList , 0 )
1552
+ if err != nil {
1553
+ return nil , err
1554
1554
}
1555
1555
1556
1556
// first timer task
@@ -1563,9 +1563,9 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1563
1563
createReplicationTask := domainEntry .CanReplicateEvent ()
1564
1564
replicationTasks := []persistence.Task {}
1565
1565
var replicationTask persistence.Task
1566
- _ , replicationTask , retError = context .appendFirstBatchEventsForActive (msBuilder , createReplicationTask )
1567
- if retError != nil {
1568
- return
1566
+ _ , replicationTask , err = context .appendFirstBatchEventsForActive (msBuilder , createReplicationTask )
1567
+ if err != nil {
1568
+ return nil , err
1569
1569
}
1570
1570
if replicationTask != nil {
1571
1571
replicationTasks = append (replicationTasks , replicationTask )
@@ -1579,30 +1579,30 @@ func (e *historyEngineImpl) SignalWithStartWorkflowExecution(
1579
1579
prevRunID = prevMutableState .GetExecutionInfo ().RunID
1580
1580
prevLastWriteVersion = prevMutableState .GetLastWriteVersion ()
1581
1581
}
1582
- retError = context .createWorkflowExecution (
1582
+ err = context .createWorkflowExecution (
1583
1583
msBuilder , e .currentClusterName , createReplicationTask , e .timeSource .Now (),
1584
1584
transferTasks , replicationTasks , timerTasks ,
1585
1585
createMode , prevRunID , prevLastWriteVersion ,
1586
1586
)
1587
1587
1588
- t , ok := retError .(* persistence.WorkflowExecutionAlreadyStartedError )
1589
- if ok {
1588
+ if t , ok := err .(* persistence.WorkflowExecutionAlreadyStartedError ); ok {
1589
+ e . deleteEvents ( domainID , execution , eventStoreVersion , msBuilder . GetCurrentBranch ())
1590
1590
if t .StartRequestID == * request .RequestId {
1591
1591
return & workflow.StartWorkflowExecutionResponse {
1592
1592
RunId : common .StringPtr (t .RunID ),
1593
1593
}, nil
1594
1594
// delete history is expected here because duplicate start request will create history with different rid
1595
1595
}
1596
+ return nil , err
1596
1597
}
1597
1598
1598
- // Timeout error is not a failure
1599
- if retError == nil || persistence .IsTimeoutError (retError ) {
1600
- e .timerProcessor .NotifyNewTimers (e .currentClusterName , e .shard .GetCurrentTime (e .currentClusterName ), timerTasks )
1601
- return & workflow.StartWorkflowExecutionResponse {
1602
- RunId : execution .RunId ,
1603
- }, retError
1599
+ e .timerProcessor .NotifyNewTimers (e .currentClusterName , e .shard .GetCurrentTime (e .currentClusterName ), timerTasks )
1600
+ if err != nil {
1601
+ return nil , err
1604
1602
}
1605
- return
1603
+ return & workflow.StartWorkflowExecutionResponse {
1604
+ RunId : execution .RunId ,
1605
+ }, nil
1606
1606
}
1607
1607
1608
1608
// RemoveSignalMutableState remove the signal request id in signal_requested for deduplicate
0 commit comments