Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -159,11 +160,11 @@ public class FileSystemContext implements Closeable {
private boolean mUriValidationEnabled = true;

/** Cached map for workers. */
@GuardedBy("this")
private volatile List<BlockWorkerInfo> mWorkerInfoList = null;
@GuardedBy("mWorkerInfoList")
private final AtomicReference<List<BlockWorkerInfo>> mWorkerInfoList = new AtomicReference<>();

/** The policy to refresh workers list. */
@GuardedBy("this")
@GuardedBy("mWorkerInfoList")
private final RefreshPolicy mWorkerRefreshPolicy;

private final Map<Class, BlockLocationPolicy> mBlockLocationPolicyMap;
Expand Down Expand Up @@ -636,11 +637,14 @@ public synchronized WorkerNetAddress getNodeLocalWorker() throws IOException {
*
* @return the info of all block workers eligible for reads and writes
*/
public synchronized List<BlockWorkerInfo> getCachedWorkers() throws IOException {
if (mWorkerInfoList == null || mWorkerInfoList.isEmpty() || mWorkerRefreshPolicy.attempt()) {
mWorkerInfoList = getAllWorkers();
public List<BlockWorkerInfo> getCachedWorkers() throws IOException {
synchronized (mWorkerInfoList) {
if (mWorkerInfoList.get() == null || mWorkerInfoList.get().isEmpty()
|| mWorkerRefreshPolicy.attempt()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to worry about the thread safety of this mWorkerRefreshPolicy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated guarded by

mWorkerInfoList.set(getAllWorkers());
}
return mWorkerInfoList.get();
}
return mWorkerInfoList;
}

/**
Expand Down