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 8e1f9362a1 HDDS-9379. thread local client ID generator for omRequest 
(#5398)
8e1f9362a1 is described below

commit 8e1f9362a1cd429cfa697de8b17edb5d973cb38c
Author: Slava Tutrinov <[email protected]>
AuthorDate: Tue Oct 10 21:33:20 2023 +0300

    HDDS-9379. thread local client ID generator for omRequest (#5398)
---
 hadoop-hdds/common/pom.xml                         |  4 +++
 .../main/java/org/apache/hadoop/util/UUIDUtil.java | 42 ++++++++++++++++++++++
 hadoop-ozone/dist/src/main/license/bin/LICENSE.txt |  1 +
 hadoop-ozone/dist/src/main/license/jar-report.txt  |  1 +
 .../hadoop/ozone/om/OzoneManagerServiceGrpc.java   | 23 ++++++++----
 pom.xml                                            |  6 ++++
 6 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/hadoop-hdds/common/pom.xml b/hadoop-hdds/common/pom.xml
index 087de5f2aa..f94ddc8cee 100644
--- a/hadoop-hdds/common/pom.xml
+++ b/hadoop-hdds/common/pom.xml
@@ -234,6 +234,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd";>
       <version>${io.grpc.version}</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.uuid</groupId>
+      <artifactId>java-uuid-generator</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/UUIDUtil.java 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/UUIDUtil.java
new file mode 100644
index 0000000000..b8d949fac9
--- /dev/null
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/UUIDUtil.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.util;
+
+import com.fasterxml.uuid.Generators;
+
+import java.security.SecureRandom;
+import java.util.UUID;
+
+/**
+ * Helper methods to deal with random UUIDs.
+ */
+public final class UUIDUtil {
+
+  private UUIDUtil() {
+
+  }
+
+  private static final ThreadLocal<SecureRandom> GENERATOR =
+      ThreadLocal.withInitial(SecureRandom::new);
+
+  public static UUID randomUUID() {
+    return Generators.randomBasedGenerator(GENERATOR.get()).generate();
+  }
+
+}
diff --git a/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt 
b/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
index a361067ae7..4249600d7b 100644
--- a/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
+++ b/hadoop-ozone/dist/src/main/license/bin/LICENSE.txt
@@ -448,6 +448,7 @@ Apache License 2.0
    org.yaml:snakeyaml
    software.amazon.ion:ion-java
    org.awaitility:awaitility
+   com.fasterxml.uuid:java-uuid-generator
 
 MIT
 =====================
diff --git a/hadoop-ozone/dist/src/main/license/jar-report.txt 
b/hadoop-ozone/dist/src/main/license/jar-report.txt
index 6fdc30d2b0..7654680bb3 100644
--- a/hadoop-ozone/dist/src/main/license/jar-report.txt
+++ b/hadoop-ozone/dist/src/main/license/jar-report.txt
@@ -272,3 +272,4 @@ share/ozone/lib/woodstox-core.jar
 share/ozone/lib/zookeeper.jar
 share/ozone/lib/zookeeper-jute.jar
 share/ozone/lib/zstd-jni.jar
+share/ozone/lib/java-uuid-generator.jar
\ No newline at end of file
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerServiceGrpc.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerServiceGrpc.java
index b45f3b8763..9a6bf14279 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerServiceGrpc.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerServiceGrpc.java
@@ -17,24 +17,24 @@
  */
 package org.apache.hadoop.ozone.om;
 
-import io.grpc.Status;
 import com.google.protobuf.RpcController;
+import io.grpc.Status;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.security.SecurityConfig;
-import org.apache.hadoop.ipc.ClientId;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ipc.Server;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
 import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerServiceGrpc.OzoneManagerServiceImplBase;
 import 
org.apache.hadoop.ozone.protocolPB.OzoneManagerProtocolServerSideTranslatorPB;
-import org.apache.hadoop.ozone.protocol.proto
-    .OzoneManagerProtocolProtos.OMRequest;
-import org.apache.hadoop.ozone.protocol.proto
-    .OzoneManagerProtocolProtos.OMResponse;
 import org.apache.hadoop.ozone.security.OzoneDelegationTokenSecretManager;
+import org.apache.hadoop.util.UUIDUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.UUID;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
@@ -74,7 +74,7 @@ public class OzoneManagerServiceGrpc extends 
OzoneManagerServiceImplBase {
         null,
         null,
         RPC.RpcKind.RPC_PROTOCOL_BUFFER,
-        ClientId.getClientId()));
+        getClientId()));
     // TODO: currently require setting the Server class for each request
     // with thread context (Server.Call()) that includes retries
     // and importantly random ClientId.  This is currently necessary for
@@ -96,4 +96,13 @@ public class OzoneManagerServiceGrpc extends 
OzoneManagerServiceImplBase {
     }
     responseObserver.onCompleted();
   }
+
+  private static byte[] getClientId() {
+    UUID uuid = UUIDUtil.randomUUID();
+    ByteBuffer buf = ByteBuffer.wrap(new byte[16]);
+    buf.putLong(uuid.getMostSignificantBits());
+    buf.putLong(uuid.getLeastSignificantBits());
+    return buf.array();
+  }
+
 }
diff --git a/pom.xml b/pom.xml
index 2f2b1d8a6e..ae310f1f93 100644
--- a/pom.xml
+++ b/pom.xml
@@ -309,6 +309,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xs
     <jgrapht.version>1.0.1</jgrapht.version>
 
     <vault.driver.version>5.1.0</vault.driver.version>
+    <java.uuid.generator.version>4.3.0</java.uuid.generator.version>
     <native.lib.tmp.dir></native.lib.tmp.dir>
   </properties>
 
@@ -1577,6 +1578,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xs
         <version>${mockito2.version}</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>com.fasterxml.uuid</groupId>
+        <artifactId>java-uuid-generator</artifactId>
+        <version>${java.uuid.generator.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 


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

Reply via email to