This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new f01d6bb1b91 HDDS-15565. Remove unnecessary lock in S3GatewayMetrics 
(#10521)
f01d6bb1b91 is described below

commit f01d6bb1b914c7f9250842a447f1b639a8ff07ba
Author: fmorg-git <[email protected]>
AuthorDate: Wed Jun 17 11:40:56 2026 -0700

    HDDS-15565. Remove unnecessary lock in S3GatewayMetrics (#10521)
---
 .../hadoop/ozone/s3/metrics/S3GatewayMetrics.java  | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java
index 5bb2c2952a3..7f2b2f67863 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java
@@ -49,7 +49,7 @@ public final class S3GatewayMetrics implements Closeable, 
MetricsSource {
   // TODO: https://issues.apache.org/jira/browse/HDDS-13555
   @SuppressWarnings("PMD.SingularField")
   private MetricsRegistry registry;
-  private static S3GatewayMetrics instance;
+  private static volatile S3GatewayMetrics instance;
 
   // BucketEndpoint
   private @Metric MutableCounterLong getBucketSuccess;
@@ -303,14 +303,20 @@ public void close() {
    *
    * @return S3GatewayMetrics
    */
-  public static synchronized S3GatewayMetrics create(OzoneConfiguration conf) {
-    if (instance != null) {
-      return instance;
+  public static S3GatewayMetrics create(OzoneConfiguration conf) {
+    S3GatewayMetrics local = instance;
+    if (local == null) {
+      synchronized (S3GatewayMetrics.class) {
+        local = instance;
+        if (local == null) {
+          MetricsSystem ms = DefaultMetricsSystem.instance();
+          local = ms.register(SOURCE_NAME, "S3 Gateway Metrics",
+              new S3GatewayMetrics(conf));
+          instance = local;
+        }
+      }
     }
-    MetricsSystem ms = DefaultMetricsSystem.instance();
-    instance = ms.register(SOURCE_NAME, "S3 Gateway Metrics",
-        new S3GatewayMetrics(conf));
-    return instance;
+    return local;
   }
 
   /**
@@ -857,7 +863,7 @@ private long updateAndGetStats(PerformanceMetrics metric, 
long startNanos) {
     return value;
   }
 
-  public static synchronized S3GatewayMetrics getMetrics() {
+  public static S3GatewayMetrics getMetrics() {
     return instance;
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to