@@ -188,27 +188,27 @@ StartWorkflowExecutionResponse startWorkflowExecutionImpl(
188
188
lock .lock ();
189
189
try {
190
190
existing = executionsByWorkflowId .get (workflowId );
191
+ if (existing != null ) {
192
+ Optional <WorkflowExecutionCloseStatus > statusOptional = existing .getCloseStatus ();
193
+ WorkflowIdReusePolicy policy =
194
+ startRequest .isSetWorkflowIdReusePolicy ()
195
+ ? startRequest .getWorkflowIdReusePolicy ()
196
+ : WorkflowIdReusePolicy .AllowDuplicateFailedOnly ;
197
+ if (!statusOptional .isPresent () || policy == WorkflowIdReusePolicy .RejectDuplicate ) {
198
+ return throwDuplicatedWorkflow (startRequest , existing );
199
+ }
200
+ WorkflowExecutionCloseStatus status = statusOptional .get ();
201
+ if (policy == WorkflowIdReusePolicy .AllowDuplicateFailedOnly
202
+ && (status == WorkflowExecutionCloseStatus .COMPLETED
203
+ || status == WorkflowExecutionCloseStatus .CONTINUED_AS_NEW )) {
204
+ return throwDuplicatedWorkflow (startRequest , existing );
205
+ }
206
+ }
207
+ return startWorkflowExecutionNoRunningCheckLocked (
208
+ startRequest , parent , parentChildInitiatedEventId , workflowId );
191
209
} finally {
192
210
lock .unlock ();
193
211
}
194
- if (existing != null ) {
195
- Optional <WorkflowExecutionCloseStatus > statusOptional = existing .getCloseStatus ();
196
- WorkflowIdReusePolicy policy =
197
- startRequest .isSetWorkflowIdReusePolicy ()
198
- ? startRequest .getWorkflowIdReusePolicy ()
199
- : WorkflowIdReusePolicy .AllowDuplicateFailedOnly ;
200
- if (!statusOptional .isPresent () || policy == WorkflowIdReusePolicy .RejectDuplicate ) {
201
- return throwDuplicatedWorkflow (startRequest , existing );
202
- }
203
- WorkflowExecutionCloseStatus status = statusOptional .get ();
204
- if (policy == WorkflowIdReusePolicy .AllowDuplicateFailedOnly
205
- && (status == WorkflowExecutionCloseStatus .COMPLETED
206
- || status == WorkflowExecutionCloseStatus .CONTINUED_AS_NEW )) {
207
- return throwDuplicatedWorkflow (startRequest , existing );
208
- }
209
- }
210
- return startWorkflowExecutionNoRunningCheck (
211
- startRequest , parent , parentChildInitiatedEventId , workflowId );
212
212
}
213
213
214
214
private StartWorkflowExecutionResponse throwDuplicatedWorkflow (
@@ -224,7 +224,7 @@ private StartWorkflowExecutionResponse throwDuplicatedWorkflow(
224
224
throw error ;
225
225
}
226
226
227
- private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheck (
227
+ private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheckLocked (
228
228
StartWorkflowExecutionRequest startRequest ,
229
229
Optional <TestWorkflowMutableState > parent ,
230
230
OptionalLong parentChildInitiatedEventId ,
@@ -236,13 +236,8 @@ private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheck(
236
236
startRequest , parent , parentChildInitiatedEventId , this , store );
237
237
WorkflowExecution execution = result .getExecutionId ().getExecution ();
238
238
ExecutionId executionId = new ExecutionId (domain , execution );
239
- lock .lock ();
240
- try {
241
- executionsByWorkflowId .put (workflowId , result );
242
- executions .put (executionId , result );
243
- } finally {
244
- lock .unlock ();
245
- }
239
+ executionsByWorkflowId .put (workflowId , result );
240
+ executions .put (executionId , result );
246
241
result .startWorkflow ();
247
242
return new StartWorkflowExecutionResponse ().setRunId (execution .getRunId ());
248
243
}
@@ -464,10 +459,15 @@ public String continueAsNew(
464
459
.setWorkflowId (executionId .getWorkflowId ().getWorkflowId ())
465
460
.setWorkflowIdReusePolicy (previousRunStartRequest .getWorkflowIdReusePolicy ())
466
461
.setIdentity (identity );
467
- StartWorkflowExecutionResponse response =
468
- startWorkflowExecutionNoRunningCheck (
469
- startRequest , parent , parentChildInitiatedEventId , executionId .getWorkflowId ());
470
- return response .getRunId ();
462
+ lock .lock ();
463
+ try {
464
+ StartWorkflowExecutionResponse response =
465
+ startWorkflowExecutionNoRunningCheckLocked (
466
+ startRequest , parent , parentChildInitiatedEventId , executionId .getWorkflowId ());
467
+ return response .getRunId ();
468
+ } finally {
469
+ lock .unlock ();
470
+ }
471
471
}
472
472
473
473
@ Override
0 commit comments