fjy closed pull request #6692: Resolves #3562 replace Files.map() with 
FileUtils.map()
URL: https://github.com/apache/incubator-druid/pull/6692
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/benchmarks/src/main/java/org/apache/druid/benchmark/FloatCompressionBenchmark.java
 
b/benchmarks/src/main/java/org/apache/druid/benchmark/FloatCompressionBenchmark.java
index 602cf3010a6..8ac9941b582 100644
--- 
a/benchmarks/src/main/java/org/apache/druid/benchmark/FloatCompressionBenchmark.java
+++ 
b/benchmarks/src/main/java/org/apache/druid/benchmark/FloatCompressionBenchmark.java
@@ -20,7 +20,8 @@
 package org.apache.druid.benchmark;
 
 import com.google.common.base.Supplier;
-import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.MappedByteBufferHandler;
 import org.apache.druid.segment.data.ColumnarFloats;
 import org.apache.druid.segment.data.CompressedColumnarFloatsSupplier;
 import org.openjdk.jmh.annotations.Benchmark;
@@ -33,6 +34,7 @@
 import org.openjdk.jmh.annotations.Scope;
 import org.openjdk.jmh.annotations.Setup;
 import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
 import org.openjdk.jmh.annotations.Warmup;
 import org.openjdk.jmh.infra.Blackhole;
 
@@ -64,15 +66,24 @@
 
   private Supplier<ColumnarFloats> supplier;
 
+  private MappedByteBufferHandler bufferHandler;
+
   @Setup
   public void setup() throws Exception
   {
     File dir = new File(dirPath);
     File compFile = new File(dir, file + "-" + strategy);
-    ByteBuffer buffer = Files.map(compFile);
+    bufferHandler = FileUtils.map(compFile);
+    ByteBuffer buffer = bufferHandler.get();
     supplier = CompressedColumnarFloatsSupplier.fromByteBuffer(buffer, 
ByteOrder.nativeOrder());
   }
 
+  @TearDown
+  public void tearDown()
+  {
+    bufferHandler.close();
+  }
+
   @Benchmark
   public void readContinuous(Blackhole bh)
   {
diff --git 
a/benchmarks/src/main/java/org/apache/druid/benchmark/LongCompressionBenchmark.java
 
b/benchmarks/src/main/java/org/apache/druid/benchmark/LongCompressionBenchmark.java
index a85a72205c0..f8383bfbf60 100644
--- 
a/benchmarks/src/main/java/org/apache/druid/benchmark/LongCompressionBenchmark.java
+++ 
b/benchmarks/src/main/java/org/apache/druid/benchmark/LongCompressionBenchmark.java
@@ -20,7 +20,8 @@
 package org.apache.druid.benchmark;
 
 import com.google.common.base.Supplier;
-import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.MappedByteBufferHandler;
 import org.apache.druid.segment.data.ColumnarLongs;
 import org.apache.druid.segment.data.CompressedColumnarLongsSupplier;
 import org.openjdk.jmh.annotations.Benchmark;
@@ -33,6 +34,7 @@
 import org.openjdk.jmh.annotations.Scope;
 import org.openjdk.jmh.annotations.Setup;
 import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
 import org.openjdk.jmh.annotations.Warmup;
 import org.openjdk.jmh.infra.Blackhole;
 
@@ -67,15 +69,24 @@
 
   private Supplier<ColumnarLongs> supplier;
 
+  private MappedByteBufferHandler bufferHandler;
+
   @Setup
   public void setup() throws Exception
   {
     File dir = new File(dirPath);
     File compFile = new File(dir, file + "-" + strategy + "-" + format);
-    ByteBuffer buffer = Files.map(compFile);
+    bufferHandler = FileUtils.map(compFile);
+    ByteBuffer buffer = bufferHandler.get();
     supplier = CompressedColumnarLongsSupplier.fromByteBuffer(buffer, 
ByteOrder.nativeOrder());
   }
 
+  @TearDown
+  public void tearDown()
+  {
+    bufferHandler.close();
+  }
+
   @Benchmark
   public void readContinuous(Blackhole bh)
   {
@@ -99,4 +110,3 @@ public void readSkipping(Blackhole bh)
   }
 
 }
-
diff --git 
a/benchmarks/src/main/java/org/apache/druid/benchmark/VSizeSerdeBenchmark.java 
b/benchmarks/src/main/java/org/apache/druid/benchmark/VSizeSerdeBenchmark.java
index 6a4c85bb10c..8c049a3f4b4 100644
--- 
a/benchmarks/src/main/java/org/apache/druid/benchmark/VSizeSerdeBenchmark.java
+++ 
b/benchmarks/src/main/java/org/apache/druid/benchmark/VSizeSerdeBenchmark.java
@@ -19,7 +19,8 @@
 
 package org.apache.druid.benchmark;
 
-import com.google.common.io.Files;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.MappedByteBufferHandler;
 import org.apache.druid.java.util.common.logger.Logger;
 import org.apache.druid.segment.data.VSizeLongSerde;
 import org.openjdk.jmh.annotations.Benchmark;
@@ -41,6 +42,7 @@
 import java.net.URISyntaxException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.concurrent.TimeUnit;
 
 @State(Scope.Benchmark)
@@ -78,26 +80,29 @@ public void setup() throws IOException, URISyntaxException
     // to construct a heapByteBuffer since they have different performance
     File base = new 
File(this.getClass().getClassLoader().getResource("").toURI());
     dummy = new File(base, "dummy");
-    try (Writer writer = java.nio.file.Files.newBufferedWriter(dummy.toPath(), 
StandardCharsets.UTF_8)) {
+    try (Writer writer = Files.newBufferedWriter(dummy.toPath(), 
StandardCharsets.UTF_8)) {
       String EMPTY_STRING = "        ";
       for (int i = 0; i < values + 10; i++) {
         writer.write(EMPTY_STRING);
       }
     }
-    ByteBuffer buffer = Files.map(dummy);
-    d1 = VSizeLongSerde.getDeserializer(1, buffer, 10);
-    d2 = VSizeLongSerde.getDeserializer(2, buffer, 10);
-    d4 = VSizeLongSerde.getDeserializer(4, buffer, 10);
-    d8 = VSizeLongSerde.getDeserializer(8, buffer, 10);
-    d12 = VSizeLongSerde.getDeserializer(12, buffer, 10);
-    d16 = VSizeLongSerde.getDeserializer(16, buffer, 10);
-    d20 = VSizeLongSerde.getDeserializer(20, buffer, 10);
-    d24 = VSizeLongSerde.getDeserializer(24, buffer, 10);
-    d32 = VSizeLongSerde.getDeserializer(32, buffer, 10);
-    d40 = VSizeLongSerde.getDeserializer(40, buffer, 10);
-    d48 = VSizeLongSerde.getDeserializer(48, buffer, 10);
-    d56 = VSizeLongSerde.getDeserializer(56, buffer, 10);
-    d64 = VSizeLongSerde.getDeserializer(64, buffer, 10);
+
+    try (MappedByteBufferHandler bufferHandler = FileUtils.map(dummy)) {
+      ByteBuffer buffer = bufferHandler.get();
+      d1 = VSizeLongSerde.getDeserializer(1, buffer, 10);
+      d2 = VSizeLongSerde.getDeserializer(2, buffer, 10);
+      d4 = VSizeLongSerde.getDeserializer(4, buffer, 10);
+      d8 = VSizeLongSerde.getDeserializer(8, buffer, 10);
+      d12 = VSizeLongSerde.getDeserializer(12, buffer, 10);
+      d16 = VSizeLongSerde.getDeserializer(16, buffer, 10);
+      d20 = VSizeLongSerde.getDeserializer(20, buffer, 10);
+      d24 = VSizeLongSerde.getDeserializer(24, buffer, 10);
+      d32 = VSizeLongSerde.getDeserializer(32, buffer, 10);
+      d40 = VSizeLongSerde.getDeserializer(40, buffer, 10);
+      d48 = VSizeLongSerde.getDeserializer(48, buffer, 10);
+      d56 = VSizeLongSerde.getDeserializer(56, buffer, 10);
+      d64 = VSizeLongSerde.getDeserializer(64, buffer, 10);
+    }
   }
 
   @TearDown


 

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to