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

ASF GitHub Bot commented on YARN-11843:
---------------------------------------

TaoYang526 commented on code in PR #7855:
URL: https://github.com/apache/hadoop/pull/7855#discussion_r2265516745


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java:
##########
@@ -722,11 +722,10 @@ protected void 
autoCorrectContainerAllocation(List<ResourceRequest> resourceRequ
       if (allocatedContainers != null) {
         for (RMContainer rmContainer : allocatedContainers) {
           if (extraContainers > 0) {
-            // Change the state of the container from ALLOCATED to EXPIRED 
since it is not required.
+            // Change the state of the container from ALLOCATED to RELEASED
+            // since it is not required.
             LOG.debug("Removing extra container:{}", 
rmContainer.getContainer());
-            completedContainer(rmContainer, 
SchedulerUtils.createAbnormalContainerStatus(
-                rmContainer.getContainerId(), 
SchedulerUtils.EXPIRED_CONTAINER),
-                RMContainerEventType.EXPIRE);
+            asyncContainerRelease(rmContainer);

Review Comment:
   Yes, the message will be updated from  "Container expired since it was 
unused" to "Container released by application", which I believe is more 
appropriate.





> Fix potential deadlock when auto-correction of container allocation is enabled
> ------------------------------------------------------------------------------
>
>                 Key: YARN-11843
>                 URL: https://issues.apache.org/jira/browse/YARN-11843
>             Project: Hadoop YARN
>          Issue Type: Bug
>          Components: scheduler
>    Affects Versions: 3.5.0
>            Reporter: Tao Yang
>            Assignee: Tao Yang
>            Priority: Major
>              Labels: pull-request-available
>
> The feature introduced in YARN-11702 has a potential deadlock issue. When 
> enabled, it can cause deadlock when holding application-level write locks 
> while trying to acquire queue-level write locks.
>  
> Root Cause:
>  - autoCorrectContainerAllocation is called while holding application-level 
> write locks
>  - It directly calls completedContainer() which requires queue-level write 
> locks
> {code:java}
> CapacityScheduler#allocate
>    --> ...
>        application.getWriteLock().lock();   //1. requires app writeLock!!!
>        try{
>            ...
>            AbstractYarnScheduler#autoCorrectContainerAllocation
>               --> AbstractYarnScheduler#completedContainer 
>                   --> AbstractYarnScheduler#completedContainerInternal
>                       --> AbstractLeafQueue#completedContainer
>                            writeLock.lock()  //2. requires queue writeLock!!!
>                            try{
>                                ...
>                                FiCaSchedulerApp#containerCompleted
>                                    //3. requires app writeLock!!!
>                            }finally{
>                                writeLock.unlock();
>                            }
>        }finally{
>            application.getWriteLock().unlock();
>        }{code}
>  - This violates lock hierarchy and creates deadlock scenarios, since 
> AbstractYarnScheduler#completedContainer could be called from another thread 
> during normal container completion operations.
>  
> Solution:
> Replace direct completedContainer() calls with asyncContainerRelease() in 
> autoCorrectContainerAllocation method.
> Before:
> {code:java}
> completedContainer(rmContainer, ...); // Direct call causes deadlock {code}
> After:
> {code:java}
> asyncContainerRelease(rmContainer); // Async call avoids deadlock {code}



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

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

Reply via email to