Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change synchronized on FileSystemContext...; Port [#16219] to branch-2.8 #18711

Open
wants to merge 1 commit into
base: branch-2.8
Choose a base branch
from
Open
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 @@ -60,6 +60,7 @@
import java.util.List;
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 @@ -156,11 +157,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;

/**
Expand Down Expand Up @@ -632,11 +633,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()) {
mWorkerInfoList.set(getAllWorkers());
}
return mWorkerInfoList.get();
}
return mWorkerInfoList;
}

/**
Expand Down
Loading