1.背景
hdfs短路读利用UNIX域套接字,可以让客户端和DataNode通信(客户端与dn是同一台机器)。需要在datanode和客户端的配置中都配置一个套接字路径,并且开启短路读特性。官方链接
hdfs在短路读时, 2.7版本的代码中DomainSocketWatcher(linux机器进程的socket通信的监听)类中有个bug需要修复。分析如下:
//DomainSocketWatcher#add相关代码
public void add(DomainSocket sock, Handler handler) {
lock.lock();
try {
Entry entry = new Entry(sock, handler);
toAdd.add(entry);
while (true) {
try {
processedCond.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (!toAdd.contains(entry)) {
break;
}
}
} finally {
lock.unlock();
}
}
//DomainSocketWatcher#remove相关代码
public void remove(DomainSocket sock) {
lock.lock();
try {
toRemove.put(sock.fd, sock);
while (true) {
try {
processedCond.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (!toRemove.containsKey(sock.fd)) {
break;
}
}
} finally {
lock.unlock();
}
}
final Thread watcherThread = new Thread(new Runnable() {
@Override
public void run() {
final TreeMap<Integer, Entry> entries = new TreeMap<Integer, Entry>();
try {
while (true) {
lock.lock();
try {
// Handle pending removals
while (true) {

本文深入解析HDFS 2.7版本中短路读功能存在的DomainSocketWatcher类Bug,涉及线程通信代码中await与interrupt处理不当导致的死循环问题,并通过实测对比await与awaitUninterruptibly方法的区别。
最低0.47元/天 解锁文章
746

被折叠的 条评论
为什么被折叠?



