Return-Path: X-Original-To: apmail-accumulo-dev-archive@www.apache.org Delivered-To: apmail-accumulo-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC11019CDC for ; Tue, 12 Apr 2016 14:08:45 +0000 (UTC) Received: (qmail 72423 invoked by uid 500); 12 Apr 2016 14:08:45 -0000 Delivered-To: apmail-accumulo-dev-archive@accumulo.apache.org Received: (qmail 72384 invoked by uid 500); 12 Apr 2016 14:08:45 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 72373 invoked by uid 99); 12 Apr 2016 14:08:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Apr 2016 14:08:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1EF5BDFBA0; Tue, 12 Apr 2016 14:08:45 +0000 (UTC) From: joshelser To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request: ACCUMULO-4173: Host Regex Table Load Balanc... Content-Type: text/plain Message-Id: <20160412140845.1EF5BDFBA0@git1-us-west.apache.org> Date: Tue, 12 Apr 2016 14:08:45 +0000 (UTC) Github user joshelser commented on a diff in the pull request: https://github.com/apache/accumulo/pull/83#discussion_r59382019 --- Diff: server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java --- @@ -0,0 +1,334 @@ +/* + * 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.accumulo.server.master.balancer; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.regex.Pattern; + +import org.apache.accumulo.core.client.admin.TableOperations; +import org.apache.accumulo.core.conf.AccumuloConfiguration; +import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.data.impl.KeyExtent; +import org.apache.accumulo.core.master.thrift.TabletServerStatus; +import org.apache.accumulo.core.tabletserver.thrift.TabletStats; +import org.apache.accumulo.server.conf.ServerConfiguration; +import org.apache.accumulo.server.master.state.TServerInstance; +import org.apache.accumulo.server.master.state.TabletMigration; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This balancer will create pools of tablet servers by grouping tablet servers that match a regex into the same pool and calling the balancer set on the table + * to balance within the set of matching tablet servers. All tablet servers that do not match a regex are grouped into a default pool.
+ * Regex properties for this balancer are specified as:
+ * table.custom.balancer.host.regex.<tablename>=<regex>
+ * Periodically (default 5m) this balancer will check to see if a tablet server is hosting tablets that it should not be according to the regex configuration. + * If this occurs then the offending tablets will be reassigned. This would cover the case where the configuration is changed and the master is restarted while + * the tablet servers are up. To change the out of bounds check time period, set the following property:
+ * table.custom.balancer.host.regex.oob.period=5m
+ * Periodically (default 5m) this balancer will regroup the set of current tablet servers into pools based on regexes applied to the tserver host names. This + * would cover the case of tservers dying or coming online. To change the host pool check time period, set the following property:
+ * table.custom.balancer.host.regex.pool.check=5m
+ * Regex matching can be based on either the host name (default) or host ip address. To set this balancer to match the regular expressions to the tablet server + * IP address, then set the following property:
+ * table.custom.balancer.host.regex.is.ip=true + * + */ +public class HostRegexTableLoadBalancer extends TableLoadBalancer { + + private static final Logger LOG = LoggerFactory.getLogger(HostRegexTableLoadBalancer.class); + public static final String HOST_BALANCER_PREFIX = Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "balancer.host.regex."; + public static final String HOST_BALANCER_OOB_CHECK = Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "balancer.host.regex.oob.period"; + private static final String HOST_BALANCER_OOB_DEFAULT = "5m"; + public static final String HOST_BALANCER_POOL_RECHECK_KEY = Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "balancer.host.regex.pool.check"; + private static final String HOST_BALANCER_POOL_RECHECK_DEFAULT = "5m"; + public static final String HOST_BALANCER_REGEX_USING_IPS = Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "balancer.host.regex.is.ip"; + protected static final String DEFAULT_POOL = "HostTableLoadBalancer.ALL"; + + protected long oobCheckMillis = AccumuloConfiguration.getTimeInMillis(HOST_BALANCER_OOB_DEFAULT); + protected long poolRecheckMillis = AccumuloConfiguration.getTimeInMillis(HOST_BALANCER_POOL_RECHECK_DEFAULT); + + private Map tableIdToTableName = null; + private Map poolNameToRegexPattern = null; + private volatile long lastOOBCheck = System.currentTimeMillis(); + private volatile long lastPoolRecheck = 0; + private boolean isIpBasedRegex = false; + private Map> pools = new HashMap>(); + + /** + * Group the set of current tservers by pool name. Tservers that don't match a regex are put into a default pool. + * + * @param current + * map of current tservers + * @return current servers grouped by pool name, if not a match it is put into a default pool. + */ + protected synchronized Map> splitCurrentByRegex(SortedMap current) { + if ((System.currentTimeMillis() - lastPoolRecheck) > poolRecheckMillis) { --- End diff -- This is probably fine when the defaults are on the order of minutes, but could be problematic if someone reduces the period. Maybe worthy of a comment to state the expectation that `poolRecheckMillis` is commonly order-minutes. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---