diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java
index af8413cc43a4..152a59d41e25 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java
@@ -29,6 +29,7 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ratis.util.ExitUtils;
import picocli.CommandLine;
import picocli.CommandLine.ExitCode;
import picocli.CommandLine.Option;
@@ -78,7 +79,7 @@ public void run(String[] argv) {
int exitCode = execute(argv);
if (exitCode != ExitCode.OK) {
- System.exit(exitCode);
+ ExitUtils.terminate(exitCode, null, null);
}
}
diff --git a/hadoop-ozone/httpfsgateway/dev-support/findbugsExcludeFile.xml b/hadoop-ozone/httpfsgateway/dev-support/findbugsExcludeFile.xml
index ea725446e42b..40d78d0cd6ce 100644
--- a/hadoop-ozone/httpfsgateway/dev-support/findbugsExcludeFile.xml
+++ b/hadoop-ozone/httpfsgateway/dev-support/findbugsExcludeFile.xml
@@ -15,24 +15,4 @@
limitations under the License.
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServerWebApp.java b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServerWebApp.java
index 8f9d8f3d6e56..b5a1736b0edc 100644
--- a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServerWebApp.java
+++ b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServerWebApp.java
@@ -18,6 +18,7 @@
package org.apache.ozone.fs.http.server;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
@@ -36,7 +37,7 @@
* implementation that is wired in HttpFSServer's WAR
* WEB-INF/web.xml.
*
- * It provides acces to the server context via the singleton {@link #get}.
+ * It provides access to the server context via the singleton {@link #get}.
*
* All the configuration is loaded from configuration properties prefixed
* with httpfs..
@@ -56,8 +57,8 @@ public class HttpFSServerWebApp extends ServerWebApp {
*/
public static final String CONF_ADMIN_GROUP = "admin.group";
- private static HttpFSServerWebApp server;
- private static HttpFSServerMetrics metrics;
+ private static final AtomicReference SERVER = new AtomicReference<>();
+ private static final AtomicReference METRICS = new AtomicReference<>();
private String adminGroup;
@@ -80,13 +81,12 @@ public HttpFSServerWebApp() throws IOException {
*/
@Override
public void init() throws ServerException {
- if (server != null) {
+ if (!SERVER.compareAndSet(null, this)) {
throw new RuntimeException("HttpFSServer server already initialized");
}
- server = this;
super.init();
adminGroup = getConfig().get(getPrefixedName(CONF_ADMIN_GROUP), "admin");
- LOG.info("Connects to Namenode [{}]",
+ LOG.info("Connects to FileSystem [{}]",
get().get(FileSystemAccess.class).getFileSystemConfiguration().
get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY));
setMetrics(getConfig());
@@ -97,7 +97,8 @@ public void init() throws ServerException {
*/
@Override
public void destroy() {
- server = null;
+ SERVER.set(null);
+ HttpFSServerMetrics metrics = METRICS.getAndSet(null);
if (metrics != null) {
metrics.shutdown();
}
@@ -106,11 +107,11 @@ public void destroy() {
private static void setMetrics(Configuration config) {
LOG.info("Initializing HttpFSServerMetrics");
- metrics = HttpFSServerMetrics.create(config, "HttpFSServer");
+ METRICS.updateAndGet(prev -> prev != null ? prev : HttpFSServerMetrics.create(config, "HttpFSServer"));
JvmPauseMonitor pauseMonitor = new JvmPauseMonitor();
pauseMonitor.init(config);
pauseMonitor.start();
- metrics.getJvmMetrics().setPauseMonitor(pauseMonitor);
+ METRICS.get().getJvmMetrics().setPauseMonitor(pauseMonitor);
FSOperations.setBufferSize(config);
DefaultMetricsSystem.initialize("HttpFSServer");
}
@@ -121,7 +122,7 @@ private static void setMetrics(Configuration config) {
* @return the HttpFSServer server singleton.
*/
public static HttpFSServerWebApp get() {
- return server;
+ return SERVER.get();
}
/**
@@ -129,7 +130,7 @@ public static HttpFSServerWebApp get() {
* @return the HttpFSServerMetrics singleton.
*/
public static HttpFSServerMetrics getMetrics() {
- return metrics;
+ return METRICS.get();
}
/**
diff --git a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java
index 8c1d746914d7..69652ef8f9ed 100644
--- a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java
+++ b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java
@@ -129,43 +129,23 @@ private T getToAdd(String group,
Class klass,
Lock lock,
Map> map) {
- boolean locked = false;
+ lock.lock();
try {
- Map groupMap = map.get(group);
- if (groupMap == null) {
- lock.lock();
- locked = true;
- groupMap = map.get(group);
- if (groupMap == null) {
- groupMap = new ConcurrentHashMap();
- map.put(group, groupMap);
- }
- }
- T element = groupMap.get(name);
- if (element == null) {
- if (!locked) {
- lock.lock();
- locked = true;
- }
- element = groupMap.get(name);
- if (element == null) {
- try {
- if (klass == Timer.class) {
- element = (T) new Timer(timersSize);
- } else {
- element = klass.newInstance();
+ return map
+ .computeIfAbsent(group, k -> new ConcurrentHashMap<>())
+ .computeIfAbsent(name, k -> {
+ try {
+ if (klass == Timer.class) {
+ return (T) new Timer(timersSize);
+ } else {
+ return klass.newInstance();
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
}
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- groupMap.put(name, element);
- }
- }
- return element;
+ });
} finally {
- if (locked) {
- lock.unlock();
- }
+ lock.unlock();
}
}
diff --git a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/servlet/ServerWebApp.java b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/servlet/ServerWebApp.java
index 5378ab941684..7d59b42e0b33 100644
--- a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/servlet/ServerWebApp.java
+++ b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/servlet/ServerWebApp.java
@@ -191,7 +191,7 @@ public InetSocketAddress getAuthority() throws ServerException {
if (authority == null) {
authority = resolveAuthority();
}
+ return authority;
}
- return authority;
}
}