Merge branch '1.6' Conflicts: core/src/main/java/org/apache/accumulo/core/conf/Property.java server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c9eaa7ff Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c9eaa7ff Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c9eaa7ff Branch: refs/heads/master Commit: c9eaa7ff13aa0f560c254145b67a89e8f0538b40 Parents: 29ca177 9c4967e Author: Keith Turner <ktur...@apache.org> Authored: Fri Oct 3 15:00:02 2014 -0400 Committer: Keith Turner <ktur...@apache.org> Committed: Fri Oct 3 15:00:02 2014 -0400 ---------------------------------------------------------------------- .../org/apache/accumulo/core/conf/Property.java | 68 +++++++++++---- .../tserver/TabletServerResourceManager.java | 2 +- .../tserver/compaction/CompactionPlan.java | 32 +++++++ .../tserver/compaction/WriteParameters.java | 6 ++ .../apache/accumulo/tserver/tablet/Tablet.java | 12 +-- .../tserver/compaction/CompactionPlanTest.java | 87 +++++++++++++++++++ .../functional/ConfigurableCompactionIT.java | 34 ++++++++ test/src/test/resources/TestCompactionStrat.jar | Bin 0 -> 1681 bytes 8 files changed, 218 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9eaa7ff/core/src/main/java/org/apache/accumulo/core/conf/Property.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/conf/Property.java index 19f1961,ad83454..58a6a32 --- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java @@@ -771,48 -629,45 +771,82 @@@ public enum Property // This is not a cache for loaded classes, just a way to avoid spamming the debug log static Map<String,Class<?>> loaded = Collections.synchronizedMap(new HashMap<String,Class<?>>()); + private static <T> T createInstance(String context, String clazzName, Class<T> base, T defaultInstance) { + T instance = null; + + try { + + Class<? extends T> clazz; + if (context != null && !context.equals("")) { + clazz = AccumuloVFSClassLoader.getContextManager().loadClass(context, clazzName, base); + } else { + clazz = AccumuloVFSClassLoader.loadClass(clazzName, base); + } + + instance = clazz.newInstance(); + if (loaded.put(clazzName, clazz) != clazz) + log.debug("Loaded class : " + clazzName); + } catch (Exception e) { + log.warn("Failed to load class ", e); + } + + if (instance == null) { + log.info("Using default class " + defaultInstance.getClass().getName()); + instance = defaultInstance; + } + return instance; + } + ++ ++ /** ++ * Creates a new instance of a class specified in a configuration property. The table classpath context is used if set. ++ * ++ * @param conf ++ * configuration containing property ++ * @param property ++ * property specifying class name ++ * @param base ++ * base class of type ++ * @param defaultInstance ++ * instance to use if creation fails ++ * @return new class instance, or default instance if creation failed ++ * @see AccumuloVFSClassLoader ++ */ + public static <T> T createTableInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) { + String clazzName = conf.get(property); + String context = conf.get(TABLE_CLASSPATH); + + return createInstance(context, clazzName, base, defaultInstance); + } + + /** + * Creates a new instance of a class specified in a configuration property. - * ++ * + * @param conf + * configuration containing property + * @param property + * property specifying class name + * @param base + * base class of type + * @param defaultInstance + * instance to use if creation fails + * @return new class instance, or default instance if creation failed + * @see AccumuloVFSClassLoader + */ public static <T> T createInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) { String clazzName = conf.get(property); - T instance = null; - - try { - Class<? extends T> clazz = AccumuloVFSClassLoader.loadClass(clazzName, base); - instance = clazz.newInstance(); - if (loaded.put(clazzName, clazz) != clazz) - log.debug("Loaded class : " + clazzName); - } catch (Exception e) { - log.warn("Failed to load class ", e); - } - if (instance == null) { - log.info("Using default class " + defaultInstance.getClass().getName()); - instance = defaultInstance; - } - return instance; + return createInstance(null, clazzName, base, defaultInstance); } + /** + * Collects together properties from the given configuration pertaining to compaction strategies. The relevant properties all begin with the prefix in + * {@link #TABLE_COMPACTION_STRATEGY_PREFIX}. In the returned map, the prefix is removed from each property's key. - * ++ * + * @param tableConf + * configuration + * @return map of compaction strategy property keys and values, with the detection prefix removed from each key + */ public static Map<String,String> getCompactionStrategyOptions(AccumuloConfiguration tableConf) { Map<String,String> longNames = tableConf.getAllPropertiesWithPrefix(Property.TABLE_COMPACTION_STRATEGY_PREFIX); Map<String,String> result = new HashMap<String,String>(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9eaa7ff/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java ---------------------------------------------------------------------- diff --cc server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java index 25c0ee8,935ffeb..4855a4f --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java @@@ -568,10 -565,10 +568,10 @@@ public class TabletServerResourceManage return false; } } - CompactionStrategy strategy = Property.createInstanceFromPropertyName(tableConf, Property.TABLE_COMPACTION_STRATEGY, CompactionStrategy.class, + CompactionStrategy strategy = Property.createTableInstanceFromPropertyName(tableConf, Property.TABLE_COMPACTION_STRATEGY, CompactionStrategy.class, new DefaultCompactionStrategy()); strategy.init(Property.getCompactionStrategyOptions(tableConf)); - MajorCompactionRequest request = new MajorCompactionRequest(tablet.getExtent(), reason, TabletServerResourceManager.this.fs, tableConf); + MajorCompactionRequest request = new MajorCompactionRequest(extent, reason, TabletServerResourceManager.this.fs, tableConf); request.setFiles(tabletFiles); try { return strategy.shouldCompact(request);