Skip to content

Commit 67df8a0

Browse files
elegamaobaolong
authored andcommitted
Change synchronized on FileSystemContext to avoid deadlock
### What changes are proposed in this pull request? Please outline the changes and how this PR fixes the issue. ### Why are the changes needed? Please clarify why the changes are needed. For instance, 1. If you propose a new API, clarify the use case for a new API. 2. If you fix a bug, describe the bug. ### Does this PR introduce any user facing changes? Please list the user-facing changes introduced by your change, including 1. change in user-facing APIs 2. addition or removal of property keys 3. webui pr-link: Alluxio#16219 change-id: cid-f6e6af4556026e122b2e672fad6ab87a0a9f507e
1 parent 4b86cf6 commit 67df8a0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

core/client/fs/src/main/java/alluxio/client/file/FileSystemContext.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.util.Optional;
6363
import java.util.concurrent.ConcurrentHashMap;
6464
import java.util.concurrent.atomic.AtomicBoolean;
65+
import java.util.concurrent.atomic.AtomicReference;
6566
import javax.annotation.Nullable;
6667
import javax.annotation.concurrent.GuardedBy;
6768
import javax.annotation.concurrent.ThreadSafe;
@@ -162,11 +163,11 @@ public class FileSystemContext implements Closeable {
162163
private MetadataCache mMetadataCache;
163164

164165
/** Cached map for workers. */
165-
@GuardedBy("this")
166-
private volatile List<BlockWorkerInfo> mWorkerInfoList = null;
166+
@GuardedBy("mWorkerInfoList")
167+
private final AtomicReference<List<BlockWorkerInfo>> mWorkerInfoList = new AtomicReference<>();
167168

168169
/** The policy to refresh workers list. */
169-
@GuardedBy("this")
170+
@GuardedBy("mWorkerInfoList")
170171
private final RefreshPolicy mWorkerRefreshPolicy;
171172

172173
/**
@@ -651,11 +652,14 @@ public synchronized WorkerNetAddress getNodeLocalWorker() throws IOException {
651652
*
652653
* @return the info of all block workers eligible for reads and writes
653654
*/
654-
public synchronized List<BlockWorkerInfo> getCachedWorkers() throws IOException {
655-
if (mWorkerInfoList == null || mWorkerInfoList.isEmpty() || mWorkerRefreshPolicy.attempt()) {
656-
mWorkerInfoList = getAllWorkers();
655+
public List<BlockWorkerInfo> getCachedWorkers() throws IOException {
656+
synchronized (mWorkerInfoList) {
657+
if (mWorkerInfoList.get() == null || mWorkerInfoList.get().isEmpty()
658+
|| mWorkerRefreshPolicy.attempt()) {
659+
mWorkerInfoList.set(getAllWorkers());
660+
}
661+
return mWorkerInfoList.get();
657662
}
658-
return mWorkerInfoList;
659663
}
660664

661665
/**

0 commit comments

Comments
 (0)