ctubbsii commented on a change in pull request #524: Tiered Volume Chooser, 
including Regex and Default strategies.
URL: https://github.com/apache/accumulo/pull/524#discussion_r193887375
 
 

 ##########
 File path: 
server/base/src/main/java/org/apache/accumulo/server/fs/TieredStorageVolumeChooser.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.accumulo.server.fs;
+
+import java.util.Arrays;
+
+import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.volume.Volume;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
+import org.apache.accumulo.server.conf.TableConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link PreferredVolumeChooser} that bases its choices on the extent of 
the tablet and the
+ * configured tiered storage volume chooser strategy. Defaults to selecting 
from the volumes set as
+ * preferred in table.custom.preferred.volumes, which should contain a comma 
separated list of
+ * {@link Volume} URIs, the table.tiered.special.volumes which is a comma 
seperated list of special
+ * volumes, and table.tiered.strategy which should be a class that implements 
TieredStorageStrategy.
+ * Note that both the property name and the format of its value are specific 
to this particular
+ * implementation.
+ */
+public class TieredStorageVolumeChooser extends PreferredVolumeChooser {
+  private static final Logger log = 
LoggerFactory.getLogger(TieredStorageVolumeChooser.class);
+
+  public static final String TABLE_TIERING_STRATEGY = 
Property.TABLE_ARBITRARY_PROP_PREFIX
+      + "tiering.strategy";
+
+  @Override
+  protected String[] getPreferredVolumesForTable(VolumeChooserEnvironment env,
+      ServerConfigurationFactory confFactory, String[] options) {
+
+    log.trace("choosing using tiered storage volume chooser");
+
+    TieredStorageStrategy strategy = getTieringStrategy(env, confFactory);
+    String preferredVolumes = strategy.getVolumeList(env, confFactory, 
options);
+
+    // fall back to global default scope, so setting only one default is 
necessary, rather than a
+    // separate default for TABLE scope than other scopes
+    if (null == preferredVolumes || preferredVolumes.isEmpty()) {
+      preferredVolumes = 
confFactory.getSystemConfiguration().get(DEFAULT_SCOPED_PREFERRED_VOLUMES);
+    }
+
+    // throw an error if volumes not specified or empty
+    if (null == preferredVolumes || preferredVolumes.isEmpty()) {
+      String msg = "Property " + TABLE_PREFERRED_VOLUMES + " or " + 
DEFAULT_SCOPED_PREFERRED_VOLUMES
+          + " must be a subset of " + Arrays.toString(options) + " to use the "
+          + getClass().getSimpleName();
+      throw new VolumeChooserException(msg);
+    }
+
+    return parsePreferred(TABLE_PREFERRED_VOLUMES, preferredVolumes, options);
+  }
+
+  private TieredStorageStrategy getTieringStrategy(VolumeChooserEnvironment 
env,
+      ServerConfigurationFactory confFactory) {
+    log.trace("Looking up property {} + for Table id: {}", 
TABLE_TIERING_STRATEGY,
+        env.getTableId());
+
+    final TableConfiguration tableConf = 
confFactory.getTableConfiguration(env.getTableId());
+    String strategyClass = tableConf.get(TABLE_TIERING_STRATEGY);
+
+    return 
ConfigurationTypeHelper.getClassInstance(tableConf.get(Property.TABLE_CLASSPATH),
+        strategyClass, TieredStorageStrategy.class, new 
DefaultTieredStorageStrategy());
 
 Review comment:
   Automatic fallback to an implementation that was not the implementation the 
user specified in the configuration is generally a bad idea. Also, the default 
strategy appears to just turn this "tiered" strategy into a regular preferred 
volumes chooser... so it's probably not needed at all. If the user wanted to 
use that, they could have just used the `PreferredVolumesChooser` instead.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to