You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2014/10/03 21:02:51 UTC

[1/2] git commit: ACCUMULO-3183 support loading compaction strategy from per table classpath

Repository: accumulo
Updated Branches:
  refs/heads/1.6 a65f1234e -> 9c4967e8f


ACCUMULO-3183 support loading compaction strategy from per table classpath


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/43f787d6
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/43f787d6
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/43f787d6

Branch: refs/heads/1.6
Commit: 43f787d68012badd4c980be2d36195a8ce56bf40
Parents: a65f123
Author: Keith Turner <kt...@apache.org>
Authored: Fri Oct 3 14:28:33 2014 -0400
Committer: Keith Turner <kt...@apache.org>
Committed: Fri Oct 3 14:28:33 2014 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/core/conf/Property.java |  25 ++++++++++++--
 .../org/apache/accumulo/tserver/Tablet.java     |   2 +-
 .../tserver/TabletServerResourceManager.java    |   2 +-
 .../functional/ConfigurableCompactionIT.java    |  34 +++++++++++++++++++
 test/src/test/resources/TestCompactionStrat.jar | Bin 0 -> 1681 bytes
 5 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/43f787d6/core/src/main/java/org/apache/accumulo/core/conf/Property.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
index 6167b25..ad83454 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
@@ -629,12 +629,18 @@ 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<?>>());
 
-  public static <T> T createInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) {
-    String clazzName = conf.get(property);
+  private static <T> T createInstance(String context, String clazzName, Class<T> base, T defaultInstance) {
     T instance = null;
 
     try {
-      Class<? extends T> clazz = AccumuloVFSClassLoader.loadClass(clazzName, base);
+
+      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);
@@ -649,6 +655,19 @@ public enum Property {
     return instance;
   }
 
+  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);
+  }
+
+  public static <T> T createInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) {
+    String clazzName = conf.get(property);
+
+    return createInstance(null, clazzName, base, defaultInstance);
+  }
+
   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/43f787d6/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
index 4e7a77e..226f3d8 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
@@ -3073,7 +3073,7 @@ public class Tablet {
     long t1, t2, t3;
 
     // acquire file info outside of tablet lock
-    CompactionStrategy strategy = Property.createInstanceFromPropertyName(acuTableConf, Property.TABLE_COMPACTION_STRATEGY, CompactionStrategy.class,
+    CompactionStrategy strategy = Property.createTableInstanceFromPropertyName(acuTableConf, Property.TABLE_COMPACTION_STRATEGY, CompactionStrategy.class,
         new DefaultCompactionStrategy());
     strategy.init(Property.getCompactionStrategyOptions(acuTableConf));
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/43f787d6/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java
index d4bc0fd..935ffeb 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java
@@ -565,7 +565,7 @@ public class TabletServerResourceManager {
           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);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/43f787d6/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableCompactionIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableCompactionIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableCompactionIT.java
index 353fdb1..2b90c81 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableCompactionIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableCompactionIT.java
@@ -19,9 +19,11 @@ package org.apache.accumulo.test.functional;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Random;
+import java.util.TreeSet;
 
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
@@ -38,6 +40,7 @@ import org.apache.accumulo.tserver.compaction.CompactionPlan;
 import org.apache.accumulo.tserver.compaction.CompactionStrategy;
 import org.apache.accumulo.tserver.compaction.MajorCompactionRequest;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -85,6 +88,37 @@ public class ConfigurableCompactionIT extends ConfigurableMacIT {
     runTest(c, tableName, 5);
   }
 
+  @Test(timeout = 60000)
+  public void testPerTableClasspath() throws Exception {
+    final Connector c = getConnector();
+    final String tableName = getUniqueNames(1)[0];
+    c.tableOperations().create(tableName);
+    c.instanceOperations().setProperty(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "context1",
+        System.getProperty("user.dir") + "/src/test/resources/TestCompactionStrat.jar");
+    c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "10");
+    c.tableOperations().setProperty(tableName, Property.TABLE_CLASSPATH.getKey(), "context1");
+    // EfgCompactionStrat will only compact a tablet w/ end row of 'efg'. No other tablets are compacted.
+    c.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(), "org.apache.accumulo.test.EfgCompactionStrat");
+
+    c.tableOperations().addSplits(tableName, new TreeSet<Text>(Arrays.asList(new Text("efg"))));
+
+    for (char ch = 'a'; ch < 'l'; ch++)
+      writeFlush(c, tableName, ch + "");
+
+    while (countFiles(c, tableName) != 7) {
+      UtilWaitThread.sleep(200);
+    }
+  }
+
+  private void writeFlush(Connector conn, String tablename, String row) throws Exception {
+    BatchWriter bw = conn.createBatchWriter(tablename, new BatchWriterConfig());
+    Mutation m = new Mutation(row);
+    m.put("", "", "");
+    bw.addMutation(m);
+    bw.close();
+    conn.tableOperations().flush(tablename, null, null, true);
+  }
+
   final static Random r = new Random();
 
   private void makeFile(Connector conn, String tablename) throws Exception {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/43f787d6/test/src/test/resources/TestCompactionStrat.jar
----------------------------------------------------------------------
diff --git a/test/src/test/resources/TestCompactionStrat.jar b/test/src/test/resources/TestCompactionStrat.jar
new file mode 100644
index 0000000..0bc38d4
Binary files /dev/null and b/test/src/test/resources/TestCompactionStrat.jar differ


[2/2] git commit: ACCUMULO-3189 add verification of compaction plan

Posted by kt...@apache.org.
ACCUMULO-3189 add verification of compaction plan


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9c4967e8
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9c4967e8
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9c4967e8

Branch: refs/heads/1.6
Commit: 9c4967e8fd9bb81d69bffd933eaa5a2834196303
Parents: 43f787d
Author: Keith Turner <kt...@apache.org>
Authored: Fri Oct 3 14:29:14 2014 -0400
Committer: Keith Turner <kt...@apache.org>
Committed: Fri Oct 3 14:38:44 2014 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/tserver/Tablet.java     |  4 +-
 .../tserver/compaction/CompactionPlan.java      | 32 +++++++
 .../tserver/compaction/WriteParameters.java     |  6 ++
 .../tserver/compaction/CompactionPlanTest.java  | 87 ++++++++++++++++++++
 4 files changed, 128 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c4967e8/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
index 226f3d8..e345210 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
@@ -3128,8 +3128,10 @@ public class Tablet {
         MajorCompactionRequest request = new MajorCompactionRequest(extent, reason, fs, acuTableConf);
         request.setFiles(allFiles);
         plan = strategy.getCompactionPlan(request);
-        if (plan != null)
+        if (plan != null) {
+          plan.validate(allFiles.keySet());
           inputFiles.addAll(plan.inputFiles);
+        }
       }
 
       if (inputFiles.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c4967e8/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/CompactionPlan.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/CompactionPlan.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/CompactionPlan.java
index 9417624..6f69fb0 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/CompactionPlan.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/CompactionPlan.java
@@ -17,10 +17,15 @@
 package org.apache.accumulo.tserver.compaction;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.accumulo.server.fs.FileRef;
 
+import com.google.common.collect.Sets;
+
 /**
  * A plan for a compaction: the input files, the files that are *not* inputs to a compaction that should simply be deleted, and the optional parameters used to
  * create the resulting output file.
@@ -52,4 +57,31 @@ public class CompactionPlan {
     }
     return b.toString();
   }
+
+  /**
+   * Validate compaction plan.
+   * 
+   * @param allFiles
+   *          All possible files
+   * @throws IllegalStateException
+   *           thrown when validation fails.
+   */
+  public final void validate(Set<FileRef> allFiles) {
+    Set<FileRef> inputSet = new HashSet<FileRef>(inputFiles);
+    Set<FileRef> deleteSet = new HashSet<FileRef>(deleteFiles);
+
+    if (!allFiles.containsAll(inputSet)) {
+      inputSet.removeAll(allFiles);
+      throw new IllegalStateException("plan inputs contains files not in allFiles " + inputSet);
+    }
+
+    if (!allFiles.containsAll(deleteSet)) {
+      deleteSet.removeAll(allFiles);
+      throw new IllegalStateException("plan deletes contains files not in allFiles " + deleteSet);
+    }
+
+    if (!Collections.disjoint(inputSet, deleteSet)) {
+      throw new IllegalStateException("plan contains overlap in inputFiles and deleteFiles " + Sets.intersection(inputSet, deleteSet));
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c4967e8/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/WriteParameters.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/WriteParameters.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/WriteParameters.java
index 42b4e17..edb862e 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/WriteParameters.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/compaction/WriteParameters.java
@@ -16,6 +16,8 @@
  */
 package org.apache.accumulo.tserver.compaction;
 
+import com.google.common.base.Preconditions;
+
 public class WriteParameters {
   private String compressType = null;
   private long hdfsBlockSize = 0;
@@ -36,6 +38,7 @@ public class WriteParameters {
   }
 
   public void setHdfsBlockSize(long hdfsBlockSize) {
+    Preconditions.checkArgument(hdfsBlockSize >= 0);
     this.hdfsBlockSize = hdfsBlockSize;
   }
 
@@ -44,6 +47,7 @@ public class WriteParameters {
   }
 
   public void setBlockSize(long blockSize) {
+    Preconditions.checkArgument(blockSize >= 0);
     this.blockSize = blockSize;
   }
 
@@ -52,6 +56,7 @@ public class WriteParameters {
   }
 
   public void setIndexBlockSize(long indexBlockSize) {
+    Preconditions.checkArgument(indexBlockSize >= 0);
     this.indexBlockSize = indexBlockSize;
   }
 
@@ -60,6 +65,7 @@ public class WriteParameters {
   }
 
   public void setReplication(int replication) {
+    Preconditions.checkArgument(replication >= 0);
     this.replication = replication;
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c4967e8/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java
new file mode 100644
index 0000000..988d87f
--- /dev/null
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.tserver.compaction;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.accumulo.server.fs.FileRef;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class CompactionPlanTest {
+
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
+
+  @Test
+  public void testOverlappingInputAndDelete() {
+    CompactionPlan cp1 = new CompactionPlan();
+
+    FileRef fr1 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/1.rf");
+    FileRef fr2 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/2.rf");
+
+    cp1.inputFiles.add(fr1);
+
+    cp1.deleteFiles.add(fr1);
+    cp1.deleteFiles.add(fr2);
+
+    Set<FileRef> allFiles = ImmutableSet.of(fr1, fr2);
+
+    exception.expect(IllegalStateException.class);
+    cp1.validate(allFiles);
+  }
+
+  @Test
+  public void testInputNotInAllFiles() {
+    CompactionPlan cp1 = new CompactionPlan();
+
+    FileRef fr1 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/1.rf");
+    FileRef fr2 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/2.rf");
+    FileRef fr3 = new FileRef("hdfs://nn1/accumulo/tables/1/t-2/3.rf");
+
+    cp1.inputFiles.add(fr1);
+    cp1.inputFiles.add(fr2);
+    cp1.inputFiles.add(fr3);
+
+    Set<FileRef> allFiles = ImmutableSet.of(fr1, fr2);
+
+    exception.expect(IllegalStateException.class);
+    cp1.validate(allFiles);
+  }
+
+  @Test
+  public void testDeleteNotInAllFiles() {
+    CompactionPlan cp1 = new CompactionPlan();
+
+    FileRef fr1 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/1.rf");
+    FileRef fr2 = new FileRef("hdfs://nn1/accumulo/tables/1/t-1/2.rf");
+    FileRef fr3 = new FileRef("hdfs://nn1/accumulo/tables/1/t-2/3.rf");
+
+    cp1.deleteFiles.add(fr1);
+    cp1.deleteFiles.add(fr2);
+    cp1.deleteFiles.add(fr3);
+
+    Set<FileRef> allFiles = ImmutableSet.of(fr1, fr2);
+
+    exception.expect(IllegalStateException.class);
+    cp1.validate(allFiles);
+  }
+
+}