gortiz commented on code in PR #10370:
URL: https://github.com/apache/pinot/pull/10370#discussion_r1155731525


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/inv/BitmapInvertedIndexWriter.java:
##########
@@ -57,14 +57,33 @@ public final class BitmapInvertedIndexWriter implements 
Closeable {
   private final ByteBuffer _offsetBuffer;
   private ByteBuffer _bitmapBuffer;
   private long _bytesWritten;
+  private final boolean _ownsChannel;
 
   public BitmapInvertedIndexWriter(File outputFile, int numBitmaps)
       throws IOException {
+    this(new RandomAccessFile(outputFile, "rw").getChannel(), numBitmaps, 
true);
+  }
+
+  /**
+   * Creates a new writer that uses the given {@link FileChannel}.
+   * It will start to write on the current position of the channel assuming it 
is the last useful byte in the file.
+   * When this object is {@link #close() closed}, the channel is truncated to 
the last byte written by this writer.
+   * @param fileChannel the file channel to be used
+   * @param numBitmaps the number of bitmaps that are expected. The actual 
value cannot be higher than this value. Fewer
+   *                   bitmaps than the given value can be used, but in that 
case the representation will not be as
+   *                   expected.
+   * @param ownsChannel whether this writer owns the channel or not. If the 
channel is owned then it will be closed when
+   *                    this object is closed. Otherwise the owner will have 
to close it by itself. Even if this writer
+   *                    does not own the channel, it will be truncated when 
the writer is closed.
+   */
+  public BitmapInvertedIndexWriter(FileChannel fileChannel, int numBitmaps, 
boolean ownsChannel)
+      throws IOException {
+    _ownsChannel = ownsChannel;
     int sizeForOffsets = (numBitmaps + 1) * Integer.BYTES;
     long bitmapBufferEstimate = Math.min(PESSIMISTIC_BITMAP_SIZE_ESTIMATE * 
numBitmaps, MAX_INITIAL_BUFFER_SIZE);
-    _fileChannel = new RandomAccessFile(outputFile, "rw").getChannel();
-    _offsetBuffer = _fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 
sizeForOffsets);
-    _bytesWritten = sizeForOffsets;
+    _fileChannel = fileChannel;
+    _offsetBuffer = _fileChannel.map(FileChannel.MapMode.READ_WRITE, 
_fileChannel.position(), sizeForOffsets);
+    _bytesWritten = sizeForOffsets + _fileChannel.position();

Review Comment:
   changed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to