infraio commented on a change in pull request #2579: URL: https://github.com/apache/hbase/pull/2579#discussion_r511738528
########## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/ReplicationServerManager.java ########## @@ -0,0 +1,204 @@ +/* + * 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.hadoop.hbase.master; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.ScheduledChore; +import org.apache.hadoop.hbase.ServerMetrics; +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The ServerManager class manages info about replication servers. + * <p> + * Maintains lists of online and dead servers. + * <p> + * Servers are distinguished in two different ways. A given server has a + * location, specified by hostname and port, and of which there can only be one + * online at any given time. A server instance is specified by the location + * (hostname and port) as well as the startcode (timestamp from when the server + * was started). This is used to differentiate a restarted instance of a given + * server from the original instance. + */ +@InterfaceAudience.Private +public class ReplicationServerManager { + + private static final Logger LOG = LoggerFactory.getLogger(ReplicationServerManager.class); + + public static final String ONLINE_SERVER_REFRESH_INTERVAL = + "hbase.master.replication.server.refresh.interval"; + public static final int ONLINE_SERVER_REFRESH_INTERVAL_DEFAULT = 60 * 1000; // 1 mins + + private final MasterServices master; + + /** Map of registered servers to their current load */ + private final ConcurrentNavigableMap<ServerName, ServerMetrics> onlineServers = + new ConcurrentSkipListMap<>(); + + private OnlineServerRefresher onlineServerRefresher; + private int refreshPeriod; + + /** + * Constructor. + */ + public ReplicationServerManager(final MasterServices master) { + this.master = master; + } + + /** + * start chore in ServerManager + */ + public void startChore() { + Configuration conf = master.getConfiguration(); + refreshPeriod = conf.getInt(ONLINE_SERVER_REFRESH_INTERVAL, + ONLINE_SERVER_REFRESH_INTERVAL_DEFAULT); + onlineServerRefresher = new OnlineServerRefresher("ReplicationServerRefresher", refreshPeriod); + master.getChoreService().scheduleChore(onlineServerRefresher); + } + + /** + * Stop the ServerManager. + */ + public void stop() { + if (onlineServerRefresher != null) { + onlineServerRefresher.cancel(); + } + } + + public void serverReport(ServerName sn, ServerMetrics sl) { + if (null == this.onlineServers.replace(sn, sl)) { + if (!checkAndRecordNewServer(sn, sl)) { + LOG.info("ReplicationServerReport ignored, could not record the server: {}", sn); + } + } + } + + /** + * Check is a server of same host and port already exists, + * if not, or the existed one got a smaller start code, record it. + * + * @param serverName the server to check and record + * @param sl the server load on the server + * @return true if the server is recorded, otherwise, false + */ + boolean checkAndRecordNewServer(final ServerName serverName, final ServerMetrics sl) { Review comment: private method? ---------------------------------------------------------------- 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: us...@infra.apache.org