Skip to content

Commit 152b270

Browse files
elegaXenorith
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 5dd3ba8 commit 152b270

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
@@ -60,6 +60,7 @@
6060
import java.util.List;
6161
import java.util.concurrent.ConcurrentHashMap;
6262
import java.util.concurrent.atomic.AtomicBoolean;
63+
import java.util.concurrent.atomic.AtomicReference;
6364
import javax.annotation.Nullable;
6465
import javax.annotation.concurrent.GuardedBy;
6566
import javax.annotation.concurrent.ThreadSafe;
@@ -156,11 +157,11 @@ public class FileSystemContext implements Closeable {
156157
private boolean mUriValidationEnabled = true;
157158

158159
/** Cached map for workers. */
159-
@GuardedBy("this")
160-
private volatile List<BlockWorkerInfo> mWorkerInfoList = null;
160+
@GuardedBy("mWorkerInfoList")
161+
private final AtomicReference<List<BlockWorkerInfo>> mWorkerInfoList = new AtomicReference<>();
161162

162163
/** The policy to refresh workers list. */
163-
@GuardedBy("this")
164+
@GuardedBy("mWorkerInfoList")
164165
private final RefreshPolicy mWorkerRefreshPolicy;
165166

166167
/**
@@ -632,11 +633,14 @@ public synchronized WorkerNetAddress getNodeLocalWorker() throws IOException {
632633
*
633634
* @return the info of all block workers eligible for reads and writes
634635
*/
635-
public synchronized List<BlockWorkerInfo> getCachedWorkers() throws IOException {
636-
if (mWorkerInfoList == null || mWorkerInfoList.isEmpty() || mWorkerRefreshPolicy.attempt()) {
637-
mWorkerInfoList = getAllWorkers();
636+
public List<BlockWorkerInfo> getCachedWorkers() throws IOException {
637+
synchronized (mWorkerInfoList) {
638+
if (mWorkerInfoList.get() == null || mWorkerInfoList.get().isEmpty()
639+
|| mWorkerRefreshPolicy.attempt()) {
640+
mWorkerInfoList.set(getAllWorkers());
641+
}
642+
return mWorkerInfoList.get();
638643
}
639-
return mWorkerInfoList;
640644
}
641645

642646
/**

0 commit comments

Comments
 (0)