imbajin commented on code in PR #2906:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2906#discussion_r2531932249


##########
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java:
##########
@@ -370,50 +372,6 @@ private boolean peerEquals(PeerId p1, PeerId p2) {
     }
 
     private Replicator.State getReplicatorState(PeerId peerId) {
-        var replicateGroup = getReplicatorGroup();
-        if (replicateGroup == null) {
-            return null;
-        }
-
-        ThreadId threadId = replicateGroup.getReplicator(peerId);
-        if (threadId == null) {
-            return null;
-        } else {
-            Replicator r = (Replicator) threadId.lock();
-            if (r == null) {
-                return Replicator.State.Probe;
-            }
-            Replicator.State result = getState(r);
-            threadId.unlock();
-            return result;
-        }
-    }
-
-    private ReplicatorGroup getReplicatorGroup() {
-        var clz = this.raftNode.getClass();
-        try {
-            var f = clz.getDeclaredField("replicatorGroup");
-            f.setAccessible(true);
-            var group = (ReplicatorGroup) f.get(this.raftNode);
-            f.setAccessible(false);
-            return group;
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            log.info("getReplicatorGroup: error {}", e.getMessage());
-            return null;
-        }
-    }
-
-    private Replicator.State getState(Replicator r) {
-        var clz = r.getClass();
-        try {
-            var f = clz.getDeclaredField("state");
-            f.setAccessible(true);
-            var state = (Replicator.State) f.get(this.raftNode);
-            f.setAccessible(false);
-            return state;
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            log.info("getReplicatorGroup: error {}", e.getMessage());
-            return null;
-        }
+        return RaftReflectionUtil.getReplicatorState(this.raftNode, peerId);

Review Comment:
   🧹 **原始 bug 回顾**
   
   Issue #2867 指出的核心问题在原代码第 413 行:
   
   ```java
   var state = (Replicator.State) f.get(this.raftNode);
   ```
   
   应该是:
   ```java
   var state = (Replicator.State) f.get(r);
   ```
   
   这个 bug 会导致反射获取到错误的对象字段值。当前 PR 的新实现已经修复了这个问题 
(RaftReflectionUtil.java:73),但引入依赖的代价过高。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to