wei.song created HADOOP-20101:
---------------------------------

             Summary: ViewFileSystem InnerCache holds the write lock during 
filesystem creation, deadlocking with FileSystem.CACHE
                 Key: HADOOP-20101
                 URL: https://issues.apache.org/jira/browse/HADOOP-20101
             Project: Hadoop Common
          Issue Type: Bug
          Components: fs
    Affects Versions: 3.4.3, 3.4.2, 3.4.1, 3.5.0, 3.3.6, 3.3.4, 3.3.3, 3.3.5, 
3.3.2, 3.4.0
         Environment: Hadoop 3.3.5, Linux, single node.
yarn.nodemanager.container-executor.class: DefaultContainerExecutor, so the 
localizer runs inside the NodeManager JVM.
fs.defaultFS: a viewfs mount.
fs.viewfs.enable.inner.cache: default, not disabled.
            Reporter: wei.song


Problem
A YARN NodeManager localizer thread can hang permanently, after which the node 
stops launching new containers. Restarting the NodeManager is the only 
recovery. Reproduced on 3.3.5.

Why the deadlock window exists
ViewFileSystem InnerCache.get() acquires the InnerCache write lock and then 
calls fsCreator.getNewInstance() while still holding it. That call connects to 
a NameNode and performs authentication, so it can take seconds to tens of 
seconds. The critical section is not microseconds but seconds, which is what 
makes the two lock cycle reachable in practice.

The cycle
While the creation is in progress, the localizer thread reaches its teardown 
path, ContainerLocalizer.closeFileSystems on a localization failure, and calls 
FileSystem.CACHE.closeAll(ugi). That path holds the CACHE monitor and then 
enters ViewFileSystem.close() and waits for the InnerCache write lock in 
clear(). The creating thread, once the slow call returns, tries to publish its 
instance through Cache.getInternal() and waits for the CACHE monitor. Neither 
wait responds to interruption, so the cycle never breaks.

Conditions
The localizer must run inside the NodeManager JVM, which means 
DefaultContainerExecutor. A viewfs mount must be in use, since only viewfs 
paths go through InnerCache. The localization failure path must be reached so 
that the closeAllForUGI() teardown runs. A filesystem instantiation slow enough 
to overlap with the teardown is required.

Fix
Create the filesystem instance outside the lock, then take the lock only to 
re-check and publish. If another thread won the race, close the redundant 
instance after unlocking, so the write lock covers only map.get and map.put.

Evidence
A jstack dump shows the two threads in the cycle, one blocked in 
InnerCache.clear() holding the CACHE monitor, the other blocked in 
Cache.getInternal() holding the InnerCache write lock. A deterministic unit 
test reproduces the same interleaving in a single JVM: the current code times 
out and fails after 25 seconds, the patched code passes in about 200 
milliseconds. On a six container NodeManager, the patched build keeps the 
NodeManager active through a localization failure while all containers end in 
LOCALIZATION_FAILED, whereas the original build deadlocks and needs a restart. 
Reproduction steps will follow in a comment.

Version range
InnerCache was introduced by HADOOP-17028 in 3.3.2, so 3.3.0 and 3.3.1 are not 
affected. The affected range is 3.3.2 through 3.4.x, and also 3.5.0.

Why 3.5.0 is still affected
HADOOP-19346 replaced the ReentrantReadWriteLock with a ConcurrentHashMap, 
which looks like it removes the lock but does not remove the cycle. The new 
get() is map.computeIfAbsent(key, k -> getNewFileSystem(uri, config)). Under 
the ConcurrentHashMap contract the mapping function runs while the bin is 
locked, and the mapping function calls fsCreator.getNewInstance(), which is the 
same slow call as before. ConcurrentHashMap.clear() synchronizes on the bin 
heads, so the teardown path still waits for the lock held by the creation path. 
The cycle is now between the FileSystem.CACHE monitor and the ConcurrentHashMap 
bin lock, and it has the same shape as in 3.3.2 through 3.4.x. This part is 
based on code inspection of HADOOP-19346 and on the ConcurrentHashMap contract, 
not on a run against 3.5.0; I plan to confirm it on trunk with the same test.

Note
Backporting HADOOP-19346 alone does not fix this, because the ConcurrentHashMap 
version keeps the slow creation inside a locked section. Both the minimal 
reorder and the ConcurrentHashMap version need the instance creation moved 
outside the lock, or computeIfAbsent replaced by explicit get and putIfAbsent 
calls.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to