tomicooler opened a new pull request, #6732:
URL: https://github.com/apache/hadoop/pull/6732
Change-Id: I4ca3998748494c1148b1ef79b33500eecae02a97
<!--
Thanks for sending a pull request!
1. If this is your first time, please read our contributor guidelines:
https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute
2. Make sure your PR title starts with JIRA issue id, e.g.,
'HADOOP-17799. Your PR title ...'.
-->
### Description of PR
Jira: [YARN-11191](https://issues.apache.org/jira/browse/YARN-11191)
Original PR: https://github.com/apache/hadoop/pull/4726
The investigation and the fix was done by @yb12138, see the Original PR for
further details.
I fixed the leftover review comments and I slightly modified the new test
code to actually test
the `refreshQueues`. The new test fails without the fix.
### How was this patch tested?
I created a sample application for demonstration:
```java
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class Main {
static final long start = System.currentTimeMillis();
public static void main(String[] args) {
ReentrantReadWriteLock queue = new ReentrantReadWriteLock();
ReentrantReadWriteLock preemption = new ReentrantReadWriteLock();
Thread schedulerThread = new Thread(() -> {
log("queue.readLock().lock()");
queue.readLock().lock();
try {
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log("preemption.readLock().lock()");
preemption.readLock().lock();
log("preemption.readLock().unlock()");
preemption.readLock().unlock();
log("queue.readLock().unlock()");
queue.readLock().unlock();
}, "SCHEDULE");
Thread completeThread = new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log("queue.writeLock().lock()");
queue.writeLock().lock();
log("queue.writeLock().unlock()");
queue.writeLock().unlock();
}, "COMPLETE");
Thread refreshThread = new Thread(() -> {
try {
Thread.sleep(2 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log("preemption.writeLock().lock()");
preemption.writeLock().lock();
log("queue.readLock().lock()");
// OUTPUT_A
queue.readLock().lock();
// OUTPUT_B
//while (!queue.readLock().tryLock()) {
// LockSupport.parkNanos(10000);
//}
log("queue.readLock().unlock()");
queue.readLock().unlock();
log("preemption.writeLock().unlock()");
preemption.writeLock().unlock();
}, "REFRESH ");
schedulerThread.start();
completeThread.start();
refreshThread.start();
try {
schedulerThread.join();
completeThread.join();
refreshThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
static void log(String what) {
System.out.printf("%04d %s %s%n", System.currentTimeMillis() - start,
Thread.currentThread().getName(), what);
}
}
```
`OUTPUT_A` deadlock happens.
```
0005 SCHEDULE queue.readLock().lock()
1007 COMPLETE queue.writeLock().lock()
2006 REFRESH preemption.writeLock().lock()
2006 REFRESH queue.readLock().lock()
5042 SCHEDULE preemption.readLock().lock()
```

`OUTPUT_B` deadlock does not happen. (tryLock)
```
0003 SCHEDULE queue.readLock().lock()
1003 COMPLETE queue.writeLock().lock()
2003 REFRESH preemption.writeLock().lock()
2004 REFRESH queue.readLock().lock()
2005 REFRESH queue.readLock().unlock()
2005 REFRESH preemption.writeLock().unlock()
5026 SCHEDULE preemption.readLock().lock()
5027 SCHEDULE preemption.readLock().unlock()
5027 SCHEDULE queue.readLock().unlock()
5027 COMPLETE queue.writeLock().unlock()
```
### For code changes:
- [x] Does the title or this PR starts with the corresponding JIRA issue id
(e.g. 'YARN-11191. Your PR title ...')?
- [ ] Object storage: have the integration tests been executed and the
endpoint declared according to the connector-specific documentation?
- [ ] If adding new dependencies to the code, are these dependencies
licensed in a way that is compatible for inclusion under [ASF
2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`,
`NOTICE-binary` files?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]