HDFS-14279. [SBN read] Fix race condition in ObserverReadProxyProvider. Contributed by Erik Krogen.
This commit is contained in:
parent
c377540704
commit
2fe15053ab
@ -233,10 +233,7 @@ ProxyInfo<T> getLastProxy() {
|
||||
* {@link #changeProxy(NNProxyInfo)} to initialize one.
|
||||
*/
|
||||
private NNProxyInfo<T> getCurrentProxy() {
|
||||
if (currentProxy == null) {
|
||||
changeProxy(null);
|
||||
}
|
||||
return currentProxy;
|
||||
return changeProxy(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,21 +244,20 @@ private NNProxyInfo<T> getCurrentProxy() {
|
||||
* returning.
|
||||
*
|
||||
* @param initial The expected current proxy
|
||||
* @return The new proxy that should be used.
|
||||
*/
|
||||
private synchronized void changeProxy(NNProxyInfo<T> initial) {
|
||||
private synchronized NNProxyInfo<T> changeProxy(NNProxyInfo<T> 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));
|
||||
currentProxy.setCachedState(getHAServiceState(currentProxy));
|
||||
LOG.debug("Changed current proxy from {} to {}",
|
||||
initial == null ? "none" : initial.proxyInfo,
|
||||
currentProxy.proxyInfo);
|
||||
return currentProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user