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 2021/02/08 15:39:57 UTC

[GitHub] [iotdb] yuqi1129 opened a new pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

yuqi1129 opened a new pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662


   …cy problem
   
   ## Description
   see https://github.com/apache/iotdb/issues/2661
   
   ### Content1 ...
   
   ### Content2 ...
   
   ### Content3 ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


----------------------------------------------------------------
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.

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



[GitHub] [iotdb] LebronAl commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
LebronAl commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r582744864



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/async/AsyncClientPool.java
##########
@@ -81,19 +82,19 @@ public AsyncClient getClient(Node node, boolean activatedOnly) throws IOExceptio
 
     AsyncClient client;
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<AsyncClient> clientStack =
+    Deque<AsyncClient> clientDeque =
         clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
-      if (clientStack.isEmpty()) {
+      if (clientDeque.isEmpty()) {
         int nodeClientNum = nodeClientNumMap.getOrDefault(clusterNode, 0);
         if (nodeClientNum >= maxConnectionForEachNode) {
-          client = waitForClient(clientStack, clusterNode, nodeClientNum);
+          client = waitForClient(clientDeque, clusterNode);
         } else {
           nodeClientNumMap.put(clusterNode, nodeClientNum + 1);
           client = asyncClientFactory.getAsyncClient(clusterNode, this);
         }
       } else {
-        client = clientStack.pop();
+        client = clientDeque.getFirst();

Review comment:
       why not use `pop()`? this client must be removed from this deque temporarily as it will be used by the caller




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] yuqi1129 commented on pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
yuqi1129 commented on pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#issuecomment-786671189


   @LebronAl Yes, we can just use `nodeClientNumMap.computeIfPresent(node, (n, oldValue) -> oldValue + 1)` to solve the atomic update problem in map.  nice advice~


----------------------------------------------------------------
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.

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



[GitHub] [iotdb] LebronAl commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
LebronAl commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r582744864



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/async/AsyncClientPool.java
##########
@@ -81,19 +82,19 @@ public AsyncClient getClient(Node node, boolean activatedOnly) throws IOExceptio
 
     AsyncClient client;
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<AsyncClient> clientStack =
+    Deque<AsyncClient> clientDeque =
         clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
-      if (clientStack.isEmpty()) {
+      if (clientDeque.isEmpty()) {
         int nodeClientNum = nodeClientNumMap.getOrDefault(clusterNode, 0);
         if (nodeClientNum >= maxConnectionForEachNode) {
-          client = waitForClient(clientStack, clusterNode, nodeClientNum);
+          client = waitForClient(clientDeque, clusterNode);
         } else {
           nodeClientNumMap.put(clusterNode, nodeClientNum + 1);
           client = asyncClientFactory.getAsyncClient(clusterNode, this);
         }
       } else {
-        client = clientStack.pop();
+        client = clientDeque.getFirst();

Review comment:
       why not use `pop()`? this client must be removed from this deque temporarily as it will be used in the caller

##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/sync/SyncClientPool.java
##########
@@ -125,25 +137,25 @@ private Client waitForClient(Deque<Client> clientStack, ClusterNode node, int no
    * @param node
    * @param client
    */
-  void putClient(Node node, Client client) {
+  public void putClient(Node node, Client client) {
     ClusterNode clusterNode = new ClusterNode(node);
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<Client> clientStack = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
+    Deque<Client> clientDeque = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
       if (client.getInputProtocol() != null && client.getInputProtocol().getTransport().isOpen()) {
-        clientStack.push(client);
+        clientDeque.push(client);
         NodeStatusManager.getINSTANCE().activate(node);
       } else {
         try {
-          clientStack.push(syncClientFactory.getSyncClient(node, this));
+          clientDeque.push(syncClientFactory.getSyncClient(node, this));
           NodeStatusManager.getINSTANCE().activate(node);
+          this.notify();
         } catch (TTransportException e) {
           logger.error("Cannot open transport for client {}", node, e);
           nodeClientNumMap.computeIfPresent(clusterNode, (n, oldValue) -> oldValue - 1);
           NodeStatusManager.getINSTANCE().deactivate(node);
         }
       }
-      this.notifyAll();

Review comment:
       I can understand why you change `notifyAll` to `notify`, but I don't know why remove this line here to above?




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] yuqi1129 commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
yuqi1129 commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r583648855



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/sync/SyncClientPool.java
##########
@@ -125,25 +137,25 @@ private Client waitForClient(Deque<Client> clientStack, ClusterNode node, int no
    * @param node
    * @param client
    */
-  void putClient(Node node, Client client) {
+  public void putClient(Node node, Client client) {
     ClusterNode clusterNode = new ClusterNode(node);
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<Client> clientStack = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
+    Deque<Client> clientDeque = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
       if (client.getInputProtocol() != null && client.getInputProtocol().getTransport().isOpen()) {
-        clientStack.push(client);
+        clientDeque.push(client);
         NodeStatusManager.getINSTANCE().activate(node);
       } else {
         try {
-          clientStack.push(syncClientFactory.getSyncClient(node, this));
+          clientDeque.push(syncClientFactory.getSyncClient(node, this));
           NodeStatusManager.getINSTANCE().activate(node);
+          this.notify();
         } catch (TTransportException e) {
           logger.error("Cannot open transport for client {}", node, e);
           nodeClientNumMap.computeIfPresent(clusterNode, (n, oldValue) -> oldValue - 1);
           NodeStatusManager.getINSTANCE().deactivate(node);
         }
       }
-      this.notifyAll();

Review comment:
       > but I don't know why remove this line here to above
   My intention is just to replace notifyAll() with notify(), it's a mistake to move to the inner try block 




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] yuqi1129 commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
yuqi1129 commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r583643342



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/async/AsyncClientPool.java
##########
@@ -81,19 +82,19 @@ public AsyncClient getClient(Node node, boolean activatedOnly) throws IOExceptio
 
     AsyncClient client;
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<AsyncClient> clientStack =
+    Deque<AsyncClient> clientDeque =
         clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
-      if (clientStack.isEmpty()) {
+      if (clientDeque.isEmpty()) {
         int nodeClientNum = nodeClientNumMap.getOrDefault(clusterNode, 0);
         if (nodeClientNum >= maxConnectionForEachNode) {
-          client = waitForClient(clientStack, clusterNode, nodeClientNum);
+          client = waitForClient(clientDeque, clusterNode);
         } else {
           nodeClientNumMap.put(clusterNode, nodeClientNum + 1);
           client = asyncClientFactory.getAsyncClient(clusterNode, this);
         }
       } else {
-        client = clientStack.pop();
+        client = clientDeque.getFirst();

Review comment:
       Sorry, this is a mistake i make here, `getFirst()` will not remove element from queue




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] LebronAl commented on pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
LebronAl commented on pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#issuecomment-795465515


   Hi, yuqi~
   As [2791](https://github.com/apache/iotdb/pull/2791) has fix this concurrent bug you mentioned in [2661](https://github.com/apache/iotdb/issues/2661), I will close this PR.
   
   Thanks for you careful finding!


----------------------------------------------------------------
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.

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



[GitHub] [iotdb] LebronAl commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
LebronAl commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r584409119



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/async/AsyncClientPool.java
##########
@@ -195,12 +198,12 @@ void recreateClient(Node node) {
           clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
       try {
         AsyncClient asyncClient = asyncClientFactory.getAsyncClient(node, this);
-        clientStack.push(asyncClient);
+        clientStack.addLast(asyncClient);

Review comment:
       what's the benefit of changing stack to queue? 




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] yuqi1129 commented on a change in pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
yuqi1129 commented on a change in pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662#discussion_r583648855



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/sync/SyncClientPool.java
##########
@@ -125,25 +137,25 @@ private Client waitForClient(Deque<Client> clientStack, ClusterNode node, int no
    * @param node
    * @param client
    */
-  void putClient(Node node, Client client) {
+  public void putClient(Node node, Client client) {
     ClusterNode clusterNode = new ClusterNode(node);
     // As clientCaches is ConcurrentHashMap, computeIfAbsent is thread safety.
-    Deque<Client> clientStack = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
+    Deque<Client> clientDeque = clientCaches.computeIfAbsent(clusterNode, n -> new ArrayDeque<>());
     synchronized (this) {
       if (client.getInputProtocol() != null && client.getInputProtocol().getTransport().isOpen()) {
-        clientStack.push(client);
+        clientDeque.push(client);
         NodeStatusManager.getINSTANCE().activate(node);
       } else {
         try {
-          clientStack.push(syncClientFactory.getSyncClient(node, this));
+          clientDeque.push(syncClientFactory.getSyncClient(node, this));
           NodeStatusManager.getINSTANCE().activate(node);
+          this.notify();
         } catch (TTransportException e) {
           logger.error("Cannot open transport for client {}", node, e);
           nodeClientNumMap.computeIfPresent(clusterNode, (n, oldValue) -> oldValue - 1);
           NodeStatusManager.getINSTANCE().deactivate(node);
         }
       }
-      this.notifyAll();

Review comment:
       > but I don't know why remove this line here to above
   
   My intention is just to replace notifyAll() with notify(), it's a mistake to move to the inner try block 




----------------------------------------------------------------
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.

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



[GitHub] [iotdb] LebronAl closed pull request #2662: Fix statistics value in SyncClientPool/AsyncClientPool have concurren…

Posted by GitBox <gi...@apache.org>.
LebronAl closed pull request #2662:
URL: https://github.com/apache/iotdb/pull/2662


   


----------------------------------------------------------------
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.

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