You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/08/24 12:45:58 UTC

[GitHub] [iotdb] SzyWilliam opened a new pull request, #7115: [IOTDB-4185] Prevent RatisConsensus Start Race

SzyWilliam opened a new pull request, #7115:
URL: https://github.com/apache/iotdb/pull/7115

   Race condition detected as follows:
   1. PartitionRegionStateMachine is initialized.
   2. ConsensusManager constructor is called, but not returned.
   3. Inside ConsensusManager ctor, RaftServer is initialized in ConsensusManager and start election.
   4. Inside ConsensusManager ctor, RaftServer is elected and notifies PartitionRegionStateMachine.
   5. PartitionRegionStateMachine starts heartbeat service, which uses ConsensusManager.
   6. However, in Step5, ConsensusManager Constructor is not returned, which means the ref is null. It can cause NPE


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] SzyWilliam commented on a diff in pull request #7115: [IOTDB-4185] Prevent RatisConsensus Start Race

Posted by GitBox <gi...@apache.org>.
SzyWilliam commented on code in PR #7115:
URL: https://github.com/apache/iotdb/pull/7115#discussion_r954800627


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/NodeManager.java:
##########
@@ -432,14 +433,18 @@ public void startHeartbeatService() {
 
   /** loop body of the heartbeat thread */
   private void heartbeatLoopBody() {
-    if (getConsensusManager().isLeader()) {
-      // Generate HeartbeatReq
-      THeartbeatReq heartbeatReq = genHeartbeatReq();
-      // Send heartbeat requests to all the registered DataNodes
-      pingRegisteredDataNodes(heartbeatReq, getRegisteredDataNodes());
-      // Send heartbeat requests to all the registered ConfigNodes
-      pingRegisteredConfigNodes(heartbeatReq, getRegisteredConfigNodes());
-    }
+    Optional.ofNullable(getConsensusManager())
+        .ifPresent(

Review Comment:
   Done



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java:
##########
@@ -496,19 +497,23 @@ public String getRegionStorageGroup(TConsensusGroupId regionId) {
 
   /** Called by {@link PartitionManager#regionCleaner} Delete RegionGroups periodically. */
   public void clearDeletedRegions() {
-    if (getConsensusManager().isLeader()) {
-      final Set<TRegionReplicaSet> deletedRegionSet = partitionInfo.getDeletedRegionSet();
-      if (!deletedRegionSet.isEmpty()) {
-        LOGGER.info(
-            "DELETE REGIONS {} START",
-            deletedRegionSet.stream()
-                .map(TRegionReplicaSet::getRegionId)
-                .collect(Collectors.toList()));
-        deletedRegionSet.forEach(
-            regionReplicaSet -> removeRegionGroupCache(regionReplicaSet.regionId));
-        SyncDataNodeClientPool.getInstance().deleteRegions(deletedRegionSet);
-      }
-    }
+    Optional.ofNullable(getConsensusManager())
+        .ifPresent(

Review Comment:
   Done



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 merged pull request #7115: [IOTDB-4185] Prevent RatisConsensus Start Race

Posted by GitBox <gi...@apache.org>.
JackieTien97 merged PR #7115:
URL: https://github.com/apache/iotdb/pull/7115


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #7115: [IOTDB-4185] Prevent RatisConsensus Start Race

Posted by GitBox <gi...@apache.org>.
CRZbulabula commented on code in PR #7115:
URL: https://github.com/apache/iotdb/pull/7115#discussion_r954427284


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java:
##########
@@ -496,19 +497,23 @@ public String getRegionStorageGroup(TConsensusGroupId regionId) {
 
   /** Called by {@link PartitionManager#regionCleaner} Delete RegionGroups periodically. */
   public void clearDeletedRegions() {
-    if (getConsensusManager().isLeader()) {
-      final Set<TRegionReplicaSet> deletedRegionSet = partitionInfo.getDeletedRegionSet();
-      if (!deletedRegionSet.isEmpty()) {
-        LOGGER.info(
-            "DELETE REGIONS {} START",
-            deletedRegionSet.stream()
-                .map(TRegionReplicaSet::getRegionId)
-                .collect(Collectors.toList()));
-        deletedRegionSet.forEach(
-            regionReplicaSet -> removeRegionGroupCache(regionReplicaSet.regionId));
-        SyncDataNodeClientPool.getInstance().deleteRegions(deletedRegionSet);
-      }
-    }
+    Optional.ofNullable(getConsensusManager())
+        .ifPresent(

Review Comment:
   We'd better add annotation about why should we must use Optional.ofNullable.ifPresent here.



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/NodeManager.java:
##########
@@ -432,14 +433,18 @@ public void startHeartbeatService() {
 
   /** loop body of the heartbeat thread */
   private void heartbeatLoopBody() {
-    if (getConsensusManager().isLeader()) {
-      // Generate HeartbeatReq
-      THeartbeatReq heartbeatReq = genHeartbeatReq();
-      // Send heartbeat requests to all the registered DataNodes
-      pingRegisteredDataNodes(heartbeatReq, getRegisteredDataNodes());
-      // Send heartbeat requests to all the registered ConfigNodes
-      pingRegisteredConfigNodes(heartbeatReq, getRegisteredConfigNodes());
-    }
+    Optional.ofNullable(getConsensusManager())
+        .ifPresent(

Review Comment:
   We'd better add annotation about why should we must use Optional.ofNullable.ifPresent here.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org