[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14247429#comment-14247429
 ] 

Hongchao Deng commented on ZOOKEEPER-2069:
------------------------------------------

I think you are concerned about not clearing up packets in outgoingQueue.
Let me summarize my understanding of cleanup() here.
cleanup() are for two purposes:

1. 
[Disconnection|https://github.com/apache/zookeeper/blob/b0a29d4a957a846a045e11ab158d53ef284e5a6b/src/java/main/org/apache/zookeeper/ClientCnxn.java#L1221]:
 the cleanup here is to notify *some* of packets that connection was lost. In 
here, we need to guarantee that the *previous* packets in outgoingQueue is 
cleared and notified. If there are new packets being queued, not a problem 
because they will be sent in next connection. I have three deep thoughts here: 
(1) it's the reason that I think blocking queue is a much better solution than 
the semaphore one. Because semaphore won't be wakeup up in next connection; (2) 
the later queued packet doesn't matter in next connection because priming 
packet is always *addFront*; (3) we can't simply try to eliminate later queued 
packet here because cleanup() here doesn't guarantee *closing* or 
*!state.isAlive()*.
{code}
            if (!state.isAlive() || closing) {
                conLossPacket(packet);
            } else {
                ...
                outgoingQueue.add(packet);
            }
{code}
2. [Session 
Expire/Close|https://github.com/apache/zookeeper/blob/b0a29d4a957a846a045e11ab158d53ef284e5a6b/src/java/main/org/apache/zookeeper/ClientCnxn.java#L1233]:
 the cleanup here is to clear everything. When it jumps to this point, it's 
guaranteed *closing* or *!state.isAlive()*. We can assume that no other packets 
will be added to outgoingQueue because they will be *notified* of death. After 
it's cleared, guaranteed cleared.

Now let's jump back to your suggestion. The looping check isn't needed in the 
first condition and guaranteed in the second. -v- Hope you don't mind long talk.

> Netty Support for ClientCnxnSocket
> ----------------------------------
>
>                 Key: ZOOKEEPER-2069
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2069
>             Project: ZooKeeper
>          Issue Type: Sub-task
>            Reporter: Hongchao Deng
>            Assignee: Hongchao Deng
>         Attachments: QA-run-nettyclient-for-test.patch, 
> ZOOKEEPER-2069-v10-channel.patch, ZOOKEEPER-2069-v11.patch, 
> ZOOKEEPER-2069-v12.patch, ZOOKEEPER-2069-v14.patch, 
> ZOOKEEPER-2069-v15-jdk6.patch, ZOOKEEPER-2069-v15-jdk6.patch, 
> ZOOKEEPER-2069-v16.patch, ZOOKEEPER-2069-v2.patch, ZOOKEEPER-2069-v3.patch, 
> ZOOKEEPER-2069-v4.patch, ZOOKEEPER-2069-v5.patch, ZOOKEEPER-2069-v6.patch, 
> ZOOKEEPER-2069-v7.patch, ZOOKEEPER-2069-v8.patch, ZOOKEEPER-2069-v9.1.patch, 
> ZOOKEEPER-2069-v9.2.patch, ZOOKEEPER-2069-v9.patch, ZOOKEEPER-2069.patch, 
> draft.patch
>
>
> Review Board: https://reviews.apache.org/r/27244/diff/#



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to