[hadoop] 46/50: HDFS-14279. [SBN read] Fix race condition in ObserverReadProxyProvider. Contributed by Erik Krogen.
This is an automated email from the ASF dual-hosted git repository. cliang pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/hadoop.git commit 2598282293f0b857c94157a3f0b38a8f30525317 Author: Erik Krogen AuthorDate: Thu Feb 14 08:59:56 2019 -0800 HDFS-14279. [SBN read] Fix race condition in ObserverReadProxyProvider. Contributed by Erik Krogen. --- .../namenode/ha/ObserverReadProxyProvider.java | 23 +- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java index 7540508..356600f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java @@ -92,13 +92,12 @@ public class ObserverReadProxyProvider * be accessed in synchronized methods. */ private int currentIndex = -1; + /** - * The proxy being used currently; this will match with currentIndex above. - * This field is volatile to allow reads without synchronization; updates - * should still be performed synchronously to maintain consistency between - * currentIndex and this field. + * The proxy being used currently. Should only be accessed in synchronized + * methods. */ - private volatile NNProxyInfo currentProxy; + private NNProxyInfo currentProxy; /** The last proxy that has been used. Only used for testing. */ private volatile ProxyInfo lastProxy = null; @@ -191,10 +190,7 @@ public class ObserverReadProxyProvider * {@link #changeProxy(NNProxyInfo)} to initialize one. */ private NNProxyInfo getCurrentProxy() { -if (currentProxy == null) { - changeProxy(null); -} -return currentProxy; +return changeProxy(null); } /** @@ -205,15 +201,13 @@ public class ObserverReadProxyProvider * returning. * * @param initial The expected current proxy + * @return The new proxy that should be used. */ - private synchronized void changeProxy(NNProxyInfo initial) { + private synchronized NNProxyInfo changeProxy(NNProxyInfo initial) { if (currentProxy != initial) { // Must have been a concurrent modification; ignore the move request - return; + return currentProxy; } -// Attempt to force concurrent callers of getCurrentProxy to wait for the -// new proxy; best-effort by setting currentProxy to null -currentProxy = null; currentIndex = (currentIndex + 1) % nameNodeProxies.size(); currentProxy = createProxyIfNeeded(nameNodeProxies.get(currentIndex)); try { @@ -227,6 +221,7 @@ public class ObserverReadProxyProvider LOG.debug("Changed current proxy from {} to {}", initial == null ? "none" : initial.proxyInfo, currentProxy.proxyInfo); +return currentProxy; } /** - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org
[hadoop] 46/50: HDFS-14279. [SBN read] Fix race condition in ObserverReadProxyProvider. Contributed by Erik Krogen.
This is an automated email from the ASF dual-hosted git repository. cliang pushed a commit to branch branch-3.2 in repository https://gitbox.apache.org/repos/asf/hadoop.git commit 98434bed5c1d686e17cfcb3e461aab4f7c576055 Author: Erik Krogen AuthorDate: Thu Feb 14 08:59:56 2019 -0800 HDFS-14279. [SBN read] Fix race condition in ObserverReadProxyProvider. Contributed by Erik Krogen. --- .../namenode/ha/ObserverReadProxyProvider.java | 23 +- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java index 7540508..356600f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProvider.java @@ -92,13 +92,12 @@ public class ObserverReadProxyProvider * be accessed in synchronized methods. */ private int currentIndex = -1; + /** - * The proxy being used currently; this will match with currentIndex above. - * This field is volatile to allow reads without synchronization; updates - * should still be performed synchronously to maintain consistency between - * currentIndex and this field. + * The proxy being used currently. Should only be accessed in synchronized + * methods. */ - private volatile NNProxyInfo currentProxy; + private NNProxyInfo currentProxy; /** The last proxy that has been used. Only used for testing. */ private volatile ProxyInfo lastProxy = null; @@ -191,10 +190,7 @@ public class ObserverReadProxyProvider * {@link #changeProxy(NNProxyInfo)} to initialize one. */ private NNProxyInfo getCurrentProxy() { -if (currentProxy == null) { - changeProxy(null); -} -return currentProxy; +return changeProxy(null); } /** @@ -205,15 +201,13 @@ public class ObserverReadProxyProvider * returning. * * @param initial The expected current proxy + * @return The new proxy that should be used. */ - private synchronized void changeProxy(NNProxyInfo initial) { + private synchronized NNProxyInfo changeProxy(NNProxyInfo initial) { if (currentProxy != initial) { // Must have been a concurrent modification; ignore the move request - return; + return currentProxy; } -// Attempt to force concurrent callers of getCurrentProxy to wait for the -// new proxy; best-effort by setting currentProxy to null -currentProxy = null; currentIndex = (currentIndex + 1) % nameNodeProxies.size(); currentProxy = createProxyIfNeeded(nameNodeProxies.get(currentIndex)); try { @@ -227,6 +221,7 @@ public class ObserverReadProxyProvider LOG.debug("Changed current proxy from {} to {}", initial == null ? "none" : initial.proxyInfo, currentProxy.proxyInfo); +return currentProxy; } /** - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org