eolivelli commented on a change in pull request #1116: ZOOKEEPER-3575: Moving sending packets in Learner to a separate thread URL: https://github.com/apache/zookeeper/pull/1116#discussion_r353631390
########## File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerSender.java ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LearnerSender extends ZooKeeperCriticalThread { + private static final Logger LOG = LoggerFactory.getLogger(LearnerSender.class); + + private final LinkedBlockingQueue<QuorumPacket> queuedPackets = new LinkedBlockingQueue<>(); + private final QuorumPacket proposalOfDeath = new QuorumPacket(); + + Learner learner; + + public LearnerSender(Learner learner) { + super("LearnerSender:" + learner.zk.getServerId(), learner.zk.getZooKeeperServerListener()); + this.learner = learner; + } + + @Override + public void run() { + while (true) { + try { + QuorumPacket p = queuedPackets.poll(); + if (p == null) { + learner.bufferedOutput.flush(); + p = queuedPackets.take(); + } + + if (p == proposalOfDeath) { + // Packet of death! + break; + } + + learner.messageTracker.trackSent(p.getType()); Review comment: here https://github.com/apache/zookeeper/pull/1116/files#diff-c8b414c1ca2084ecb9fe32a0a3832d44R170 we accessing learner internal variables inside a synchronized block. it looks like an inconsistent synchronization maybe it depends on the fact that this feature is enabled or not, but I am not sure we are 100% safe can you please motivate or at least leave some comment for future inspection and understanding of the flow ? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
