You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2019/12/20 17:28:52 UTC
[GitHub] [zookeeper] lvfangmin commented on a change in pull request #1116:
ZOOKEEPER-3575: Moving sending packets in Learner to a separate thread
lvfangmin 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_r360478864
##########
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:
This looks good to me, it might be better to not visit the internal variable directly, but using things like get to make the code easier to manage and reason about though.
----------------------------------------------------------------
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
With regards,
Apache Git Services