You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ar...@apache.org on 2022/03/30 18:29:05 UTC

[zookeeper] branch branch-3.6 updated: ZOOKEEPER-3652: Synchronize ClientCnxn outgoing queue flush on a stable internal value

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

arshad pushed a commit to branch branch-3.6
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.6 by this push:
     new 1907d20  ZOOKEEPER-3652: Synchronize ClientCnxn outgoing queue flush on a stable internal value
1907d20 is described below

commit 1907d206870ac6cbdea5261a80ed2aea86d17642
Author: Sylvain Wallez <sy...@bluxte.net>
AuthorDate: Wed Mar 30 23:54:55 2022 +0530

    ZOOKEEPER-3652: Synchronize ClientCnxn outgoing queue flush on a stable internal value
    
    When packets are added to ClientCnxn's outgoing packet queue we ensure there's no conflict with an ongoing flush of that queue because of connection loss.
    
    Synchronization used to be on the state field's value. This value is both not stable (its value changes over time), possibly causing improper synchronization, and global, which can cause contention in applications that run several ZooKeeper clients.
    
    We now synchronize on outgoingQueue which is both local to a ClientCnxn's instance and stable.
    
    Author: Sylvain Wallez <sy...@bluxte.net>
    
    Reviewers: maoling <ma...@apache.org>, Mohammad Arshad <ar...@apache.org>
    
    Closes #1257 from swallez/ZOOKEEPER-3652 and squashes the following commits:
    
    82e2cad2c [Sylvain Wallez] Instruct SpotBugs that we know what we're doing when synchronizing on outgoingQueue
    b0bc03d6f [Sylvain Wallez] ZOOKEEPER-3652: Synchronize ClientCnxn outgoing queue flush on a stable internal value
    
    (cherry picked from commit 91e0520133b82acb87ab60962fce5eae992d87e8)
    Signed-off-by: Mohammad Arshad <ar...@apache.org>
---
 zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
index 7c31a2a..ed95554 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
@@ -1185,6 +1185,7 @@ public class ClientCnxn {
         }
 
         @Override
+        @SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
         public void run() {
             clientCnxnSocket.introduce(this, sessionId, outgoingQueue);
             clientCnxnSocket.updateNow();
@@ -1313,7 +1314,7 @@ public class ClientCnxn {
                 }
             }
 
-            synchronized (state) {
+            synchronized (outgoingQueue) {
                 // When it comes to this point, it guarantees that later queued
                 // packet to outgoingQueue will be notified of death.
                 cleanup();
@@ -1651,6 +1652,7 @@ public class ClientCnxn {
         return queuePacket(h, r, request, response, cb, clientPath, serverPath, ctx, watchRegistration, null);
     }
 
+    @SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER")
     public Packet queuePacket(
         RequestHeader h,
         ReplyHeader r,
@@ -1677,7 +1679,7 @@ public class ClientCnxn {
         // 1. synchronize with the final cleanup() in SendThread.run() to avoid race
         // 2. synchronized against each packet. So if a closeSession packet is added,
         // later packet will be notified.
-        synchronized (state) {
+        synchronized (outgoingQueue) {
             if (!state.isAlive() || closing) {
                 conLossPacket(packet);
             } else {