[ 
https://issues.apache.org/jira/browse/HDDS-8129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17698680#comment-17698680
 ] 

Tsz-wo Sze commented on HDDS-8129:
----------------------------------

The following is the code:
{code}
//ContainerStateMachine
  private CompletableFuture<ContainerCommandResponseProto> submitTask(
      ContainerCommandRequestProto request, DispatcherContext.Builder context,
      Consumer<Exception> exceptionHandler) {
    final long containerId = request.getContainerID();
    final TaskQueue queue = containerTaskQueues.computeIfAbsent(
        containerId, id -> new TaskQueue("container" + id));
    final CheckedSupplier<ContainerCommandResponseProto, Exception> task
        = () -> {
          try {
            return runCommand(request, context.build());
          } catch (Exception e) {
            exceptionHandler.accept(e);
            throw e;
          }
        };
    final CompletableFuture<ContainerCommandResponseProto> f
        = queue.submit(task, executor);
    // after the task is completed, remove the queue if the queue is empty.
    f.thenAccept(dummy -> containerTaskQueues.computeIfPresent(containerId,
        (id, q) -> q.isEmpty() ? null : q));
    return f;
  }
{code}


> ContainerStateMachine allows two different tasks with the same container id 
> running in parallel
> -----------------------------------------------------------------------------------------------
>
>                 Key: HDDS-8129
>                 URL: https://issues.apache.org/jira/browse/HDDS-8129
>             Project: Apache Ozone
>          Issue Type: Bug
>          Components: Ozone Datanode
>            Reporter: Tsz-wo Sze
>            Assignee: Tsz-wo Sze
>            Priority: Blocker
>
> In the ContainerStateMachine.submitTask(..) method, we can have the following 
> case
>  # The applyTransaction thread enters submitTask(..). It gets a queue Q for a 
> container C from containerTaskQueues, where Q is empty at that time.
>  # Right before applyTransaction submits a task T1, the executor has 
> completed running a previous task T2 for container C. Since Q is empty, so 
> the executor removes Q from containerTaskQueues.
>  # The applyTransaction thread submits task T1 to Q.  It does not aware Q is 
> not in containerTaskQueues anymore.
>  # Now, the applyTransaction thread submits a new task T3 for container C. 
> Since there is no queue for container C in containerTaskQueues, it creates a 
> new queue Q2. Then, it submits T3 to Q2.
> As a result, T1 and T3 for container C can run in parallel since there are 
> two queues.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to