lvfangmin commented on a change in pull request #1007: ZOOKEEPER-3448: Introduce MessageTracker to assist debug leader and leaner connectivity issues. URL: https://github.com/apache/zookeeper/pull/1007#discussion_r309531768
########## File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/util/MessageTracker.java ########## @@ -0,0 +1,157 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.zookeeper.server.quorum.Leader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class provides a way of buffering sentBuffer and receivedBuffer messages in order. + * It uses EvictingQueue of size BUFFERED_MESSAGE_SIZE to store the messages. + * When the queue is full it overrides the oldest in a circular manner. + * This class does doe not provide thread safety. + */ +public class MessageTracker { + + private static final Logger LOG = LoggerFactory.getLogger(MessageTracker.class); + + private final CircularBuffer<BufferedMessage> sentBuffer; + private final CircularBuffer<BufferedMessage> receivedBuffer; + + public static final String MESSAGE_TRACKER_BUFFER_SIZE = "zookeeper.messageTracker.BufferSize"; + public static final String MESSAGE_TRACKER_ENABLED = "zookeeper.messageTracker.Enabled"; + public static final int BUFFERED_MESSAGE_SIZE; + private static final boolean enabled; + static { + BUFFERED_MESSAGE_SIZE = Integer.getInteger(MESSAGE_TRACKER_BUFFER_SIZE, 10); + enabled = Boolean.getBoolean(MESSAGE_TRACKER_ENABLED); + } + + public MessageTracker(int buffer_size) { + this.sentBuffer = new CircularBuffer<>(BufferedMessage.class, buffer_size); + this.receivedBuffer = new CircularBuffer<>(BufferedMessage.class, buffer_size); + } + + public void trackSent(long timestamp) { + if (enabled) sentBuffer.write(new BufferedMessage(timestamp)); Review comment: Should we keep the same coding format and change it to: if (enabled) { ... } ---------------------------------------------------------------- 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
