Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C50A8200C61 for ; Tue, 25 Apr 2017 21:59:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C3BF9160BB3; Tue, 25 Apr 2017 19:59:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1678E160B8E for ; Tue, 25 Apr 2017 21:59:27 +0200 (CEST) Received: (qmail 82823 invoked by uid 500); 25 Apr 2017 19:59:27 -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 82812 invoked by uid 99); 25 Apr 2017 19:59:26 -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, 25 Apr 2017 19:59:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CE135DFA1E; Tue, 25 Apr 2017 19:59:26 +0000 (UTC) From: ctubbsii To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request #253: ACCUMULO-4086 Improve volume chooser fallback Content-Type: text/plain Message-Id: <20170425195926.CE135DFA1E@git1-us-west.apache.org> Date: Tue, 25 Apr 2017 19:59:26 +0000 (UTC) archived-at: Tue, 25 Apr 2017 19:59:29 -0000 Github user ctubbsii commented on a diff in the pull request: https://github.com/apache/accumulo/pull/253#discussion_r113294955 --- Diff: server/base/src/main/java/org/apache/accumulo/server/fs/PreferredVolumeChooser.java --- @@ -21,84 +21,90 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.function.Predicate; +import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.volume.Volume; import org.apache.accumulo.server.client.HdfsZooInstance; import org.apache.accumulo.server.conf.ServerConfigurationFactory; -import org.apache.accumulo.server.conf.TableConfiguration; import org.apache.commons.collections.map.LRUMap; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link RandomVolumeChooser} that limits its choices from a given set of options to the subset of those options preferred for a particular table. Defaults - * to selecting from all of the options presented. Can be customized via the table property {@value #PREFERRED_VOLUMES_CUSTOM_KEY}, which should contain a comma + * to selecting from all of the options presented. Can be customized via the table property table.custom.preferredVolumes, which should contain a comma * separated list of {@link Volume} URIs. Note that both the property name and the format of its value are specific to this particular implementation. */ public class PreferredVolumeChooser extends RandomVolumeChooser { private static final Logger log = LoggerFactory.getLogger(PreferredVolumeChooser.class); - /** - * This should match {@link Property#TABLE_ARBITRARY_PROP_PREFIX} - */ - public static final String PREFERRED_VOLUMES_CUSTOM_KEY = "table.custom.preferredVolumes"; - // TODO ACCUMULO-3417 replace this with the ability to retrieve by String key. - private static final Predicate PREFERRED_VOLUMES_FILTER = key -> PREFERRED_VOLUMES_CUSTOM_KEY.equals(key); + public static final String PREFERRED_VOLUMES_CUSTOM_KEY = Property.TABLE_ARBITRARY_PROP_PREFIX + "preferredVolumes"; @SuppressWarnings("unchecked") private final Map> parsedPreferredVolumes = Collections.synchronizedMap(new LRUMap(1000)); // TODO has to be lazily initialized currently because of the reliance on HdfsZooInstance. see ACCUMULO-3411 private volatile ServerConfigurationFactory serverConfs; @Override - public String choose(VolumeChooserEnvironment env, String[] options) { - if (!env.hasTableId()) + public String choose(VolumeChooserEnvironment env, String[] options) throws AccumuloException { + if (!env.hasTableId() && !env.hasScope()) { + // this should only happen during initialize + log.warn("No table id or scope, so it's not possible to determine preferred volumes. Using all volumes."); return super.choose(env, options); + } + ServerConfigurationFactory localConf = loadConf(); - // Get the current table's properties, and find the preferred volumes property - // This local variable is an intentional component of the single-check idiom. - ServerConfigurationFactory localConf = serverConfs; - if (localConf == null) { - // If we're under contention when first getting here we'll throw away some initializations. - localConf = new ServerConfigurationFactory(HdfsZooInstance.getInstance()); - serverConfs = localConf; + String systemPreferredVolumes = localConf.getConfiguration().get(PREFERRED_VOLUMES_CUSTOM_KEY); + if (null == systemPreferredVolumes || systemPreferredVolumes.isEmpty()) { + String logMessage = "Default preferred volumes are missing."; + log.debug(logMessage); + throw new AccumuloException(logMessage); } - TableConfiguration tableConf = localConf.getTableConfiguration(env.getTableId()); - final Map props = new HashMap<>(); - tableConf.getProperties(props, PREFERRED_VOLUMES_FILTER); - if (props.isEmpty()) { - log.warn("No preferred volumes specified. Defaulting to randomly choosing from instance volumes"); - return super.choose(env, options); + + String volumes = null; + if (env.hasTableId()) { + volumes = localConf.getTableConfiguration(env.getTableId()).get(PREFERRED_VOLUMES_CUSTOM_KEY); + } else if (env.hasScope()) { + volumes = localConf.getConfiguration().get(Property.GENERAL_ARBITRARY_PROP_PREFIX.getKey() + env.getScope() + ".preferredVolumes"); + } + + // if there was an empty or missing property, use the system-wide volumes + if (null == volumes || volumes.isEmpty()) { + if (env.hasTableId()) { + log.warn("Missing property for TableID " + env.getTableId() + " but it should have picked up default volumes."); + } else { + log.debug("Missing preferred volumes for scope " + env.getScope() + ". Using default volumes."); --- End diff -- This should probably be a hard fail also. --- 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. ---