drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/5] drill git commit: DRILL-3598: use a factory to create the root allocator. - made the constructor for TopLevelAllocator package private to enforce this
Date Wed, 02 Sep 2015 21:52:52 GMT
Repository: drill
Updated Branches:
  refs/heads/master e39fa835d -> 4b8e85ad6


http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
index 1cb72ff..44f18af 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
@@ -28,7 +28,7 @@ import org.apache.drill.exec.ExecTest;
 import org.apache.drill.exec.cache.VectorAccessibleSerializable;
 import org.apache.drill.exec.compile.CodeCompiler;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.ops.FragmentContext;
 import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.physical.base.FragmentRoot;
@@ -68,75 +68,68 @@ import com.google.common.io.Files;
  * known value.
  */
 public class TestTraceOutputDump extends ExecTest {
-    static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class);
-    DrillConfig c = DrillConfig.create();
-
-
-    @Test
-    public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection
connection) throws Throwable
-    {
-
-        new NonStrictExpectations(){{
-            bitContext.getMetrics(); result = new MetricRegistry();
-            bitContext.getAllocator(); result = new TopLevelAllocator();
-            bitContext.getConfig(); result = c;
-            bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
-            bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c);
-        }};
-
-        PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
-        PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/simple_trace.json"),
Charsets.UTF_8));
-        FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
-        FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(),
connection, registry);
-        SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot)
plan.getSortedOperators(false).iterator().next()));
-
-        while(exec.next()){
-        }
-
-        exec.close();
-
-        if(context.getFailureCause() != null){
-            throw context.getFailureCause();
-        }
-        assertTrue(!context.isFailed());
-
-        FragmentHandle handle = context.getHandle();
-
-        /* Form the file name to which the trace output will dump the record batches */
-        String qid = QueryIdHelper.getQueryId(handle.getQueryId());
+  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class);
+  private final DrillConfig c = DrillConfig.create();
+
+  @Test
+  public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection
connection) throws Throwable {
+    new NonStrictExpectations() {{
+      bitContext.getMetrics(); result = new MetricRegistry();
+      bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c);
+      bitContext.getConfig(); result = c;
+      bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
+      bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c);
+    }};
+
+    final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
+    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/simple_trace.json"),
Charsets.UTF_8));
+    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
+    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(),
connection, registry);
+    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot)
plan.getSortedOperators(false).iterator().next()));
+
+    while(exec.next()) {
+    }
 
-        int majorFragmentId = handle.getMajorFragmentId();
-        int minorFragmentId = handle.getMinorFragmentId();
+    exec.close();
 
-        String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY);
+    if(context.getFailureCause() != null) {
+      throw context.getFailureCause();
+    }
+    assertTrue(!context.isFailed());
 
-        System.out.println("Found log location: " + logLocation);
+    final FragmentHandle handle = context.getHandle();
 
-      String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId,
minorFragmentId);
+    /* Form the file name to which the trace output will dump the record batches */
+    final String qid = QueryIdHelper.getQueryId(handle.getQueryId());
+    final int majorFragmentId = handle.getMajorFragmentId();
+    final int minorFragmentId = handle.getMinorFragmentId();
 
-      System.out.println("File Name: " + filename);
+    final String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY);
+    System.out.println("Found log location: " + logLocation);
 
-        Configuration conf = new Configuration();
-      conf.set(FileSystem.FS_DEFAULT_NAME_KEY, c.getString(ExecConstants.TRACE_DUMP_FILESYSTEM));
+    final String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId,
minorFragmentId);
+    System.out.println("File Name: " + filename);
 
-        FileSystem fs = FileSystem.get(conf);
-      Path path = new Path(filename);
-      assertTrue("Trace file does not exist", fs.exists(path));
-      FSDataInputStream in = fs.open(path);
+    final Configuration conf = new Configuration();
+    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, c.getString(ExecConstants.TRACE_DUMP_FILESYSTEM));
 
-      VectorAccessibleSerializable wrap = new VectorAccessibleSerializable(context.getAllocator());
-      wrap.readFromStream(in);
-      VectorAccessible container = wrap.get();
+    final FileSystem fs = FileSystem.get(conf);
+    final Path path = new Path(filename);
+    assertTrue("Trace file does not exist", fs.exists(path));
+    final FSDataInputStream in = fs.open(path);
 
-        /* Assert there are no selection vectors */
-      assertTrue(wrap.getSv2() == null);
+    final VectorAccessibleSerializable wrap = new VectorAccessibleSerializable(context.getAllocator());
+    wrap.readFromStream(in);
+    final VectorAccessible container = wrap.get();
 
-        /* Assert there is only one record */
-        assertTrue(container.getRecordCount() == 1);
+    /* Assert there are no selection vectors */
+    assertTrue(wrap.getSv2() == null);
 
-        /* Read the Integer value and ASSERT its Integer.MIN_VALUE */
-        int value = (int) container.iterator().next().getValueVector().getAccessor().getObject(0);
-        assertTrue(value == Integer.MIN_VALUE);
-    }
+    /* Assert there is only one record */
+    assertTrue(container.getRecordCount() == 1);
 
+    /* Read the Integer value and ASSERT its Integer.MIN_VALUE */
+    final int value = (int) container.iterator().next().getValueVector().getAccessor().getObject(0);
+    assertTrue(value == Integer.MIN_VALUE);
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
index 07de27f..7b0f137 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
@@ -27,7 +27,7 @@ import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.ExecTest;
 import org.apache.drill.exec.compile.CodeCompiler;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.ops.FragmentContext;
 import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.physical.base.FragmentRoot;
@@ -46,41 +46,35 @@ import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 
 public class TestSimpleUnion extends ExecTest {
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleUnion.class);
-  DrillConfig c = DrillConfig.create();
-
+  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleUnion.class);
+  private final DrillConfig c = DrillConfig.create();
 
   @Test
-  public void testUnion(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection
connection) throws Throwable{
-
-
-    new NonStrictExpectations(){{
+  public void testUnion(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection
connection) throws Throwable {
+    new NonStrictExpectations() {{
       bitContext.getMetrics(); result = new MetricRegistry();
-      bitContext.getAllocator(); result = new TopLevelAllocator();
+      bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c);
       bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
       bitContext.getConfig(); result = c;
       bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c);
     }};
 
+    final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
+    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/union/test1.json"),
Charsets.UTF_8));
+    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
+    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(),
connection, registry);
+    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot)
plan.getSortedOperators(false).iterator().next()));
 
-    PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
-    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/union/test1.json"),
Charsets.UTF_8));
-    FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
-    FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(),
connection, registry);
-    SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot)
plan.getSortedOperators(false).iterator().next()));
-
-    int[] counts = new int[]{100,50};
-    int i=0;
-    while(exec.next()){
+    final int[] counts = new int[]{100,50};
+    int i = 0;
+    while(exec.next()) {
       System.out.println("iteration count:" + exec.getRecordCount());
       assertEquals(counts[i++], exec.getRecordCount());
     }
 
-    if(context.getFailureCause() != null){
+    if(context.getFailureCause() != null) {
       throw context.getFailureCause();
     }
     assertTrue(!context.isFailed());
-
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
index f57e765..c3af451 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
@@ -23,6 +23,7 @@ import io.netty.buffer.DrillBuf;
 
 import java.util.List;
 
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.types.TypeProtos;
@@ -30,7 +31,7 @@ import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.ExecTest;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.RecordBatchLoader;
 import org.apache.drill.exec.record.VectorWrapper;
@@ -45,31 +46,32 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 
 public class TestLoad extends ExecTest {
+  private final DrillConfig drillConfig = DrillConfig.create();
 
   @Test
   public void testLoadValueVector() throws Exception {
-    BufferAllocator allocator = new TopLevelAllocator();
-    ValueVector fixedV = new IntVector(MaterializedField.create(new SchemaPath("ints", ExpressionPosition.UNKNOWN),
+    final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
+    final ValueVector fixedV = new IntVector(MaterializedField.create(new SchemaPath("ints",
ExpressionPosition.UNKNOWN),
         Types.required(MinorType.INT)), allocator);
-    ValueVector varlenV = new VarCharVector(MaterializedField.create(
+    final ValueVector varlenV = new VarCharVector(MaterializedField.create(
         new SchemaPath("chars", ExpressionPosition.UNKNOWN), Types.required(MinorType.VARCHAR)),
allocator);
-    ValueVector nullableVarlenV = new NullableVarCharVector(MaterializedField.create(new
SchemaPath("chars",
+    final ValueVector nullableVarlenV = new NullableVarCharVector(MaterializedField.create(new
SchemaPath("chars",
         ExpressionPosition.UNKNOWN), Types.optional(MinorType.VARCHAR)), allocator);
 
-    List<ValueVector> vectors = Lists.newArrayList(fixedV, varlenV, nullableVarlenV);
-    for (ValueVector v : vectors) {
+    final List<ValueVector> vectors = Lists.newArrayList(fixedV, varlenV, nullableVarlenV);
+    for (final ValueVector v : vectors) {
       AllocationHelper.allocate(v, 100, 50);
       v.getMutator().generateTestData(100);
     }
 
-    WritableBatch writableBatch = WritableBatch.getBatchNoHV(100, vectors, false);
-    RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
-    ByteBuf[] byteBufs = writableBatch.getBuffers();
+    final WritableBatch writableBatch = WritableBatch.getBatchNoHV(100, vectors, false);
+    final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
+    final ByteBuf[] byteBufs = writableBatch.getBuffers();
     int bytes = 0;
     for (int i = 0; i < byteBufs.length; i++) {
       bytes += byteBufs[i].writerIndex();
     }
-    DrillBuf byteBuf = allocator.buffer(bytes);
+    final DrillBuf byteBuf = allocator.buffer(bytes);
     int index = 0;
     for (int i = 0; i < byteBufs.length; i++) {
       byteBufs[i].readBytes(byteBuf, index, byteBufs[i].writerIndex());
@@ -80,7 +82,7 @@ public class TestLoad extends ExecTest {
     batchLoader.load(writableBatch.getDef(), byteBuf);
     boolean firstColumn = true;
     int recordCount = 0;
-    for (VectorWrapper<?> v : batchLoader) {
+    for (final VectorWrapper<?> v : batchLoader) {
       if (firstColumn) {
         firstColumn = false;
       } else {
@@ -96,15 +98,15 @@ public class TestLoad extends ExecTest {
     for (int r = 0; r < batchLoader.getRecordCount(); r++) {
       boolean first = true;
       recordCount++;
-      for (VectorWrapper<?> v : batchLoader) {
+      for (final VectorWrapper<?> v : batchLoader) {
         if (first) {
           first = false;
         } else {
           System.out.print("\t");
         }
-        ValueVector.Accessor accessor = v.getValueVector().getAccessor();
+        final ValueVector.Accessor accessor = v.getValueVector().getAccessor();
         if (v.getField().getType().getMinorType() == TypeProtos.MinorType.VARCHAR) {
-          Object obj = accessor.getObject(r);
+          final Object obj = accessor.getObject(r);
           if (obj != null) {
             System.out.print(accessor.getObject(r));
           } else {
@@ -122,5 +124,4 @@ public class TestLoad extends ExecTest {
     batchLoader.clear();
     writableBatch.clear();
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
index 4e299dc..af4f2f0 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
@@ -27,6 +27,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import io.netty.buffer.DrillBuf;
 import org.apache.drill.common.AutoCloseables;
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.common.types.Types;
@@ -44,8 +45,9 @@ import org.apache.drill.exec.expr.holders.RepeatedVarBinaryHolder;
 import org.apache.drill.exec.expr.holders.UInt1Holder;
 import org.apache.drill.exec.expr.holders.UInt4Holder;
 import org.apache.drill.exec.expr.holders.VarCharHolder;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.vector.BaseValueVector;
 import org.apache.drill.exec.vector.BitVector;
@@ -69,11 +71,13 @@ public class TestValueVector extends ExecTest {
   private final static byte[] STR2 = new String("BBBBBBBBB2").getBytes(Charset.forName("UTF-8"));
   private final static byte[] STR3 = new String("CCCC3").getBytes(Charset.forName("UTF-8"));
 
-  private TopLevelAllocator allocator;
+  private DrillConfig drillConfig;
+  private BufferAllocator allocator;
 
   @Before
   public void init() {
-    allocator = new TopLevelAllocator();
+    drillConfig = DrillConfig.create();
+    allocator = RootAllocatorFactory.newRoot(drillConfig);
   }
 
   @After

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java
index ce09f68..c4a1a76 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java
@@ -46,7 +46,7 @@ import org.apache.drill.exec.client.DrillClient;
 import org.apache.drill.exec.exception.DrillbitStartupException;
 import org.apache.drill.exec.exception.SchemaChangeException;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.physical.impl.ScreenCreator;
 import org.apache.drill.exec.physical.impl.SingleSenderCreator.SingleSenderRootExec;
 import org.apache.drill.exec.physical.impl.mergereceiver.MergingRecordBatch;
@@ -234,7 +234,7 @@ public class TestDrillbitResilience extends DrillTest {
    */
   private static void assertDrillbitsOk() {
       final SingleRowListener listener = new SingleRowListener() {
-          private final BufferAllocator bufferAllocator = new TopLevelAllocator(zkHelper.getConfig());
+          private final BufferAllocator bufferAllocator = RootAllocatorFactory.newRoot(zkHelper.getConfig());
           private final RecordBatchLoader loader = new RecordBatchLoader(bufferAllocator);
 
           @Override
@@ -929,7 +929,7 @@ public class TestDrillbitResilience extends DrillTest {
   @Test // DRILL-3065
   public void failsAfterMSorterSorting() {
     final String query = "select n_name from cp.`tpch/nation.parquet` order by n_name";
-    Class<? extends Exception> typeOfException = RuntimeException.class;
+    final Class<? extends Exception> typeOfException = RuntimeException.class;
 
     final long before = countAllocatedMemory();
     final String controls = Controls.newBuilder()
@@ -944,7 +944,7 @@ public class TestDrillbitResilience extends DrillTest {
   @Test // DRILL-3085
   public void failsAfterMSorterSetup() {
     final String query = "select n_name from cp.`tpch/nation.parquet` order by n_name";
-    Class<? extends Exception> typeOfException = RuntimeException.class;
+    final Class<? extends Exception> typeOfException = RuntimeException.class;
 
     final long before = countAllocatedMemory();
     final String controls = Controls.newBuilder()

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestDirectCodecFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestDirectCodecFactory.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestDirectCodecFactory.java
index 644144e..3c5cbf7 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestDirectCodecFactory.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestDirectCodecFactory.java
@@ -23,9 +23,10 @@ import java.nio.ByteBuffer;
 import java.util.Random;
 
 import org.apache.drill.common.DeferredException;
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.ExecTest;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.store.parquet.DirectCodecFactory;
 import org.apache.drill.exec.store.parquet.DirectCodecFactory.ByteBufBytesInput;
 import org.apache.drill.exec.store.parquet.DirectCodecFactory.DirectBytesDecompressor;
@@ -38,7 +39,8 @@ import parquet.hadoop.CodecFactory.BytesCompressor;
 import parquet.hadoop.metadata.CompressionCodecName;
 
 public class TestDirectCodecFactory extends ExecTest {
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestDirectCodecFactory.class);
+  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestDirectCodecFactory.class);
+  private final DrillConfig drillConfig = DrillConfig.create();
 
   private static enum Decompression {
     ON_HEAP, OFF_HEAP, DRILLBUF
@@ -47,14 +49,14 @@ public class TestDirectCodecFactory extends ExecTest {
   private void test(int size, CompressionCodecName codec, boolean useOnHeapCompression, Decompression
decomp) {
     DrillBuf rawBuf = null;
     DrillBuf outBuf = null;
-    try (BufferAllocator allocator = new TopLevelAllocator();
-        DirectCodecFactory codecFactory = new DirectCodecFactory(new Configuration(), allocator))
{
+    try (final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
+        final DirectCodecFactory codecFactory = new DirectCodecFactory(new Configuration(),
allocator)) {
       try {
         rawBuf = allocator.buffer(size);
         final byte[] rawArr = new byte[size];
         outBuf = allocator.buffer(size * 2);
-        Random r = new Random();
-        byte[] random = new byte[1024];
+        final Random r = new Random();
+        final byte[] random = new byte[1024];
         int pos = 0;
         while (pos < size) {
           r.nextBytes(random);
@@ -63,10 +65,10 @@ public class TestDirectCodecFactory extends ExecTest {
           pos += random.length;
         }
 
-        BytesCompressor c = codecFactory.getCompressor(codec, 64 * 1024);
-        DirectBytesDecompressor d = codecFactory.getDecompressor(codec);
+        final BytesCompressor c = codecFactory.getCompressor(codec, 64 * 1024);
+        final DirectBytesDecompressor d = codecFactory.getDecompressor(codec);
 
-        BytesInput compressed;
+        final BytesInput compressed;
         if (useOnHeapCompression) {
           compressed = c.compress(BytesInput.from(rawArr));
         } else {
@@ -75,8 +77,8 @@ public class TestDirectCodecFactory extends ExecTest {
 
         switch (decomp) {
         case DRILLBUF: {
-          ByteBuffer buf = compressed.toByteBuffer();
-          DrillBuf b = allocator.buffer(buf.capacity());
+          final ByteBuffer buf = compressed.toByteBuffer();
+          final DrillBuf b = allocator.buffer(buf.capacity());
           try {
             b.writeBytes(buf);
             d.decompress(b, (int) compressed.size(), outBuf, size);
@@ -90,11 +92,11 @@ public class TestDirectCodecFactory extends ExecTest {
         }
 
         case OFF_HEAP: {
-          ByteBuffer buf = compressed.toByteBuffer();
-          DrillBuf b = allocator.buffer(buf.capacity());
+          final ByteBuffer buf = compressed.toByteBuffer();
+          final DrillBuf b = allocator.buffer(buf.capacity());
           try {
             b.writeBytes(buf);
-            BytesInput input = d.decompress(new ByteBufBytesInput(b), size);
+            final BytesInput input = d.decompress(new ByteBufBytesInput(b), size);
             Assert.assertArrayEquals(input.toByteArray(), rawArr);
           } finally {
             b.release();
@@ -102,14 +104,14 @@ public class TestDirectCodecFactory extends ExecTest {
           break;
         }
         case ON_HEAP: {
-          byte[] buf = compressed.toByteArray();
-          BytesInput input = d.decompress(BytesInput.from(buf), size);
+          final byte[] buf = compressed.toByteArray();
+          final BytesInput input = d.decompress(BytesInput.from(buf), size);
           Assert.assertArrayEquals(input.toByteArray(), rawArr);
           break;
         }
         }
       } catch (Exception e) {
-        String msg = String.format(
+        final String msg = String.format(
             "Failure while testing Codec: %s, OnHeapCompressionInput: %s, Decompression Mode:
%s, Data Size: %d",
             codec.name(),
             useOnHeapCompression, decomp.name(), size);
@@ -128,14 +130,14 @@ public class TestDirectCodecFactory extends ExecTest {
 
   @Test
   public void compressionCodecs() throws Exception {
-    int[] sizes = { 4 * 1024, 1 * 1024 * 1024 };
-    boolean[] comp = { true, false };
+    final int[] sizes = { 4 * 1024, 1 * 1024 * 1024 };
+    final boolean[] comp = { true, false };
 
-    try (DeferredException ex = new DeferredException()) {
-      for (int size : sizes) {
-        for (boolean useOnHeapComp : comp) {
-          for (Decompression decomp : Decompression.values()) {
-            for (CompressionCodecName codec : CompressionCodecName.values()) {
+    try (final DeferredException ex = new DeferredException()) {
+      for (final int size : sizes) {
+        for (final boolean useOnHeapComp : comp) {
+          for (final Decompression decomp : Decompression.values()) {
+            for (final CompressionCodecName codec : CompressionCodecName.values()) {
               if (codec == CompressionCodecName.LZO) {
                 // not installed as gpl.
                 continue;
@@ -151,5 +153,4 @@ public class TestDirectCodecFactory extends ExecTest {
       }
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java
index af1b896..8ded703 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java
@@ -41,7 +41,7 @@ import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.exception.SchemaChangeException;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.ops.FragmentContext;
 import org.apache.drill.exec.physical.impl.OutputMutator;
 import org.apache.drill.exec.proto.BitControl;
@@ -611,9 +611,9 @@ public class ParquetRecordReaderTest extends BaseTestQuery {
   @Ignore
   public void testPerformance(@Injectable final DrillbitContext bitContext,
                               @Injectable UserServer.UserClientConnection connection) throws
Exception {
-    DrillConfig c = DrillConfig.create();
-    FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
-    FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(),
connection, registry);
+    final DrillConfig c = DrillConfig.create();
+    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
+    final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(),
connection, registry);
 
 //    new NonStrictExpectations() {
 //      {
@@ -642,7 +642,7 @@ public class ParquetRecordReaderTest extends BaseTestQuery {
     int totalRowCount = 0;
 
     final FileSystem fs = new CachedSingleFileSystem(fileName);
-    final BufferAllocator allocator = new TopLevelAllocator();
+    final BufferAllocator allocator = RootAllocatorFactory.newRoot(c);
     for(int i = 0; i < 25; i++) {
       final ParquetRecordReader rr = new ParquetRecordReader(context, 256000, fileName, 0,
fs,
           new DirectCodecFactory(dfsConfig, allocator), f.getParquetMetadata(), columns);

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestResourceLeak.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestResourceLeak.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestResourceLeak.java
index d7e317c..dc539c5 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestResourceLeak.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestResourceLeak.java
@@ -19,7 +19,9 @@ package org.apache.drill.exec.testing;
 
 import com.google.common.base.Charsets;
 import com.google.common.io.Resources;
+
 import io.netty.buffer.DrillBuf;
+
 import org.apache.drill.QueryTestUtil;
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.exceptions.UserRemoteException;
@@ -33,7 +35,7 @@ import org.apache.drill.exec.expr.annotations.Output;
 import org.apache.drill.exec.expr.annotations.Param;
 import org.apache.drill.exec.expr.holders.Float8Holder;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.server.Drillbit;
 import org.apache.drill.exec.server.RemoteServiceSet;
 import org.apache.drill.test.DrillTest;
@@ -43,6 +45,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import javax.inject.Inject;
+
 import java.io.IOException;
 import java.net.URL;
 import java.util.Properties;
@@ -66,7 +69,7 @@ public class TestResourceLeak extends DrillTest {
   @BeforeClass
   public static void openClient() throws Exception {
     config = DrillConfig.create(TEST_CONFIGURATIONS);
-    allocator = new TopLevelAllocator(config);
+    allocator = RootAllocatorFactory.newRoot(config);
     serviceSet = RemoteServiceSet.getLocalServiceSet();
 
     bit = new Drillbit(config, serviceSet);
@@ -74,7 +77,7 @@ public class TestResourceLeak extends DrillTest {
     client = QueryTestUtil.createClient(config, serviceSet, 2, null);
   }
 
-  @Test()
+  @Test
   public void tpch01() throws Exception {
     final String query = getFile("memory/tpch01_memory_leak.sql");
     try {
@@ -89,7 +92,7 @@ public class TestResourceLeak extends DrillTest {
   }
 
   private static String getFile(String resource) throws IOException {
-    URL url = Resources.getResource(resource);
+    final URL url = Resources.getResource(resource);
     if (url == null) {
       throw new IOException(String.format("Unable to find path %s.", resource));
     }
@@ -115,12 +118,13 @@ public class TestResourceLeak extends DrillTest {
     @Inject DrillBuf buf;
     @Output Float8Holder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       buf.getAllocator().buffer(1);
       out.value = in.value;
     }
-
   }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
index 4b3aa8a..a0a0898 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
@@ -17,10 +17,11 @@
  */
 package org.apache.drill.exec.vector;
 
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.TransferPair;
 import org.apache.drill.exec.vector.NullableVarCharVector.Accessor;
@@ -28,37 +29,37 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class TestSplitAndTransfer {
-
   @Test
   public void test() throws Exception {
-    BufferAllocator allocator = new TopLevelAllocator();
-    MaterializedField field = MaterializedField.create("field", Types.optional(MinorType.VARCHAR));
-    NullableVarCharVector varCharVector = new NullableVarCharVector(field, allocator);
+    final DrillConfig drillConfig = DrillConfig.create();
+    final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
+    final MaterializedField field = MaterializedField.create("field", Types.optional(MinorType.VARCHAR));
+    final NullableVarCharVector varCharVector = new NullableVarCharVector(field, allocator);
     varCharVector.allocateNew(10000, 1000);
 
-    String[] compareArray = new String[500];
+    final String[] compareArray = new String[500];
 
     for (int i = 0; i < 500; i += 3) {
-      String s = String.format("%010d", i);
+      final String s = String.format("%010d", i);
       varCharVector.getMutator().set(i, s.getBytes());
       compareArray[i] = s;
     }
     varCharVector.getMutator().setValueCount(500);
 
-    TransferPair tp = varCharVector.getTransferPair();
-    NullableVarCharVector newVarCharVector = (NullableVarCharVector) tp.getTo();
-    Accessor accessor = newVarCharVector.getAccessor();
-    int[][] startLengths = {{0, 201}, {201, 200}, {401, 99}};
+    final TransferPair tp = varCharVector.getTransferPair();
+    final NullableVarCharVector newVarCharVector = (NullableVarCharVector) tp.getTo();
+    final Accessor accessor = newVarCharVector.getAccessor();
+    final int[][] startLengths = {{0, 201}, {201, 200}, {401, 99}};
 
     for (int[] startLength : startLengths) {
-      int start = startLength[0];
-      int length = startLength[1];
+      final int start = startLength[0];
+      final int length = startLength[1];
       tp.splitAndTransfer(start, length);
       newVarCharVector.getMutator().setValueCount(length);
       for (int i = 0; i < length; i++) {
-        boolean expectedSet = ((start + i) % 3) == 0;
+        final boolean expectedSet = ((start + i) % 3) == 0;
         if (expectedSet) {
-          byte[] expectedValue = compareArray[start + i].getBytes();
+          final byte[] expectedValue = compareArray[start + i].getBytes();
           Assert.assertFalse(accessor.isNull(i));
 //          System.out.println(new String(accessor.get(i)));
           Assert.assertArrayEquals(expectedValue, accessor.get(i));

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java
index f7f2706..5bb6815 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java
@@ -19,9 +19,11 @@ package org.apache.drill.exec.vector.complex;
 
 import static org.apache.drill.TestBuilder.listOf;
 import static org.apache.drill.TestBuilder.mapOf;
+
 import org.apache.drill.BaseTestQuery;
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.vector.UInt4Vector;
 import org.junit.Assert;
 import org.junit.Before;
@@ -36,7 +38,8 @@ public class TestEmptyPopulation extends BaseTestQuery {
   private UInt4Vector.Accessor accessor;
   private UInt4Vector.Mutator mutator;
   private EmptyValuePopulator populator;
-  private BufferAllocator allocator = new TopLevelAllocator();
+  private final DrillConfig drillConfig = DrillConfig.create();
+  private final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
 
 
   @Before
@@ -310,5 +313,4 @@ public class TestEmptyPopulation extends BaseTestQuery {
         .baselineValues(listOf(listOf(listOf(2L), listOf()), listOf()))
         .go();
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestRepeated.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestRepeated.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestRepeated.java
index 5640c8e..023dc08 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestRepeated.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestRepeated.java
@@ -20,10 +20,11 @@ package org.apache.drill.exec.vector.complex.writer;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.expr.holders.BigIntHolder;
 import org.apache.drill.exec.expr.holders.IntHolder;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.vector.complex.MapVector;
 import org.apache.drill.exec.vector.complex.fn.JsonWriter;
 import org.apache.drill.exec.vector.complex.impl.ComplexWriterImpl;
@@ -41,11 +42,12 @@ import com.google.common.base.Charsets;
 public class TestRepeated {
   // private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRepeated.class);
 
+  private static final DrillConfig drillConfig = DrillConfig.create();
   private static BufferAllocator allocator;
 
   @BeforeClass
   public static void setupAllocator() {
-    allocator = new TopLevelAllocator();
+    allocator = RootAllocatorFactory.newRoot(drillConfig);
   }
 
   @AfterClass

http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
index 25fcf26..b3fa0ea 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
@@ -39,7 +39,7 @@ import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.exec.client.DrillClient;
 import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.rpc.RpcException;
 import org.apache.drill.exec.server.Drillbit;
 import org.apache.drill.exec.server.RemoteServiceSet;
@@ -90,7 +90,7 @@ class DrillConnectionImpl extends AvaticaConnection
         }
 
         final DrillConfig dConfig = DrillConfig.create(info);
-        this.allocator = new TopLevelAllocator(dConfig);
+        this.allocator = RootAllocatorFactory.newRoot(dConfig);
         RemoteServiceSet set = GlobalServiceSetReference.SETS.get();
         if (set == null) {
           // We're embedded; start a local drill bit.
@@ -120,12 +120,12 @@ class DrillConnectionImpl extends AvaticaConnection
         this.client.connect(null, info);
       } else if(config.isDirect()) {
         final DrillConfig dConfig = DrillConfig.forClient();
-        this.allocator = new TopLevelAllocator(dConfig);
+        this.allocator = RootAllocatorFactory.newRoot(dConfig);
         this.client = new DrillClient(dConfig, true); // Get a direct connection
         this.client.connect(config.getZookeeperConnectionString(), info);
       } else {
         final DrillConfig dConfig = DrillConfig.forClient();
-        this.allocator = new TopLevelAllocator(dConfig);
+        this.allocator = RootAllocatorFactory.newRoot(dConfig);
         // TODO:  Check:  Why does new DrillClient() create another DrillConfig,
         // with enableServerConfigs true, and cause scanning for function
         // implementations (needed by a server, but not by a client-only


Mime
View raw message