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

jermy pushed a commit to branch RocksDBStore-redundant-checkOpened
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 049fddb3e7e61fa1c304656813034a04a964ab89
Author: Jermy Li <je...@apache.org>
AuthorDate: Sun Aug 31 02:08:32 2025 +0800

    perf(rocksdb): RocksDBStore remove redundant checkOpened() call
    
    Change-Id: I4c4ae6368fecb994708ae1da89c256beefda4511
---
 .../backend/store/rocksdb/RocksDBStore.java        | 84 ++++++++++++----------
 1 file changed, 45 insertions(+), 39 deletions(-)

diff --git 
a/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdb/RocksDBStore.java
 
b/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdb/RocksDBStore.java
index c34d9632f..b42dc5d75 100644
--- 
a/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdb/RocksDBStore.java
+++ 
b/hugegraph-server/hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdb/RocksDBStore.java
@@ -425,7 +425,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         Lock readLock = this.storeLock.readLock();
         readLock.lock();
         try {
-            this.checkOpened();
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Store {} mutation: {}", this.store, mutation);
             }
@@ -490,7 +489,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         readLock.lock();
 
         try {
-            this.checkOpened();
             HugeType tableType = RocksDBTable.tableType(query);
             RocksDBTable table;
             RocksDBSessions.Session session;
@@ -525,7 +523,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         Lock readLock = this.storeLock.readLock();
         readLock.lock();
         try {
-            this.checkOpened();
             HugeType tableType = RocksDBTable.tableType(query);
             RocksDBTable table = this.table(tableType);
             return table.queryNumber(this.session(tableType), query);
@@ -648,8 +645,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         Lock readLock = this.storeLock.readLock();
         readLock.lock();
         try {
-            this.checkOpened();
-
             for (RocksDBSessions.Session session : this.session()) {
                 assert !session.hasChanges();
             }
@@ -663,7 +658,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         Lock readLock = this.storeLock.readLock();
         readLock.lock();
         try {
-            this.checkOpened();
             // Unable to guarantee atomicity when committing multi sessions
             for (RocksDBSessions.Session session : this.session()) {
                 Object count = session.commit();
@@ -681,8 +675,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         Lock readLock = this.storeLock.readLock();
         readLock.lock();
         try {
-            this.checkOpened();
-
             for (RocksDBSessions.Session session : this.session()) {
                 session.rollback();
             }
@@ -691,19 +683,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         }
     }
 
-    @Override
-    protected RocksDBSessions.Session session(HugeType tableType) {
-        this.checkOpened();
-
-        // Optimized disk
-        String disk = this.tableDiskMapping.get(tableType);
-        if (disk != null) {
-            return this.db(disk).session();
-        }
-
-        return this.sessions.session();
-    }
-
     @Override
     public Map<String, String> createSnapshot(String snapshotPrefix) {
         Lock readLock = this.storeLock.readLock();
@@ -785,22 +764,6 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         }
     }
 
-    private List<RocksDBSessions.Session> session() {
-        this.checkOpened();
-
-        if (this.tableDiskMapping.isEmpty()) {
-            return Collections.singletonList(this.sessions.session());
-        }
-
-        // Collect session of each table with optimized disk
-        List<RocksDBSessions.Session> list = new 
ArrayList<>(this.tableDiskMapping.size() + 1);
-        list.add(this.sessions.session());
-        for (String disk : this.tableDiskMapping.values()) {
-            list.add(db(disk).session());
-        }
-        return list;
-    }
-
     private void closeSessions() {
         Iterator<Map.Entry<String, RocksDBSessions>> iter = 
this.dbs.entrySet().iterator();
         while (iter.hasNext()) {
@@ -813,10 +776,53 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
         }
     }
 
-    private Collection<RocksDBSessions> sessions() {
+    private final Collection<RocksDBSessions> sessions() {
         return this.dbs.values();
     }
 
+    private final List<RocksDBSessions.Session> session() {
+        this.checkDbOpened();
+
+        RocksDBSessions.Session session = this.sessions.session();
+        if (!session.opened()) {
+            this.checkOpened();
+        }
+
+        if (this.tableDiskMapping.isEmpty()) {
+            return ImmutableList.of(session);
+        }
+
+        // Collect session of each table with optimized disk
+        List<RocksDBSessions.Session> list = new 
ArrayList<>(this.tableDiskMapping.size() + 1);
+        list.add(session);
+        for (String disk : this.tableDiskMapping.values()) {
+            Session optimizedSession = db(disk).session();
+            assert optimizedSession.opened();
+            list.add(optimizedSession);
+        }
+        return list;
+    }
+
+    @Override
+    protected RocksDBSessions.Session session(HugeType tableType) {
+        this.checkDbOpened();
+
+        Session session;
+        String disk = this.tableDiskMapping.get(tableType);
+        if (disk != null) {
+            // Optimized disk
+            session = this.db(disk).session();
+        } else {
+            // Standard disk
+            session = this.sessions.session();
+        }
+
+        if (!session.opened()) {
+            this.checkOpened();
+        }
+        return session;
+    }
+
     private void parseTableDiskMapping(Map<String, String> disks, String 
dataPath) {
 
         this.tableDiskMapping.clear();
@@ -869,7 +875,7 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
     }
 
     protected RocksDBSessions db(HugeType tableType) {
-        this.checkOpened();
+        this.checkDbOpened();
 
         // Optimized disk
         String disk = this.tableDiskMapping.get(tableType);

Reply via email to