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

szetszwo pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/ratis.git

commit f8ca0a8f41f4495df2c97b3a850741493b67badd
Author: Sammi Chen <[email protected]>
AuthorDate: Thu Jun 30 16:51:45 2022 +0800

    RATIS-1608. Improve RaftStorageDirectoryImpl#tryLock performance on ios 
system (#665)
---
 .../org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java
index 86471798..7d27f7a0 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java
@@ -39,6 +39,7 @@ class RaftStorageDirectoryImpl implements 
RaftStorageDirectory {
   private static final String IN_USE_LOCK_NAME = "in_use.lock";
   private static final String META_FILE_NAME = "raft-meta";
   private static final String CONF_EXTENSION = ".conf";
+  private static final String JVM_NAME = 
ManagementFactory.getRuntimeMXBean().getName();
 
   enum StorageState {
     NON_EXISTENT,
@@ -218,7 +219,6 @@ class RaftStorageDirectoryImpl implements 
RaftStorageDirectory {
       deletionHookAdded = true;
     }
     RandomAccessFile file = new RandomAccessFile(lockF, "rws");
-    String jvmName = ManagementFactory.getRuntimeMXBean().getName();
     FileLock res;
     try {
       res = file.getChannel().tryLock();
@@ -226,8 +226,8 @@ class RaftStorageDirectoryImpl implements 
RaftStorageDirectory {
         LOG.error("Unable to acquire file lock on path " + lockF.toString());
         throw new OverlappingFileLockException();
       }
-      file.write(jvmName.getBytes(StandardCharsets.UTF_8));
-      LOG.info("Lock on " + lockF + " acquired by nodename " + jvmName);
+      file.write(JVM_NAME.getBytes(StandardCharsets.UTF_8));
+      LOG.info("Lock on " + lockF + " acquired by nodename " + JVM_NAME);
     } catch (OverlappingFileLockException oe) {
       // Cannot read from the locked file on Windows.
       LOG.error("It appears that another process "

Reply via email to