zacharymorn commented on a change in pull request #2052:
URL: https://github.com/apache/lucene-solr/pull/2052#discussion_r519134971



##########
File path: lucene/misc/src/java/org/apache/lucene/store/DirectIODirectory.java
##########
@@ -164,15 +149,16 @@ public IndexOutput createOutput(String name, IOContext 
context) throws IOExcepti
     private long fileLength;
     private boolean isOpen;
 
-    public NativeUnixIndexOutput(Path path, String name, int bufferSize) 
throws IOException {
-      super("NativeUnixIndexOutput(path=\"" + path.toString() + "\")", name);
-      //this.path = path;
-      final FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), 
false);
-      fos = new FileOutputStream(fd);
-      //fos = new FileOutputStream(path);
-      channel = fos.getChannel();
-      buffer = ByteBuffer.allocateDirect(bufferSize);
-      this.bufferSize = bufferSize;
+  @SuppressForbidden(reason = "com.sun.nio.file.ExtendedOpenOption: Direct I/O 
with FileChannel requires the use of internal proprietary API 
ExtendedOpenOption.DIRECT")
+  public DirectIOIndexOutput(Path path, String name) throws IOException {
+      super("DirectIOIndexOutput(path=\"" + path.toString() + "\")", name);
+
+      int blockSize = Math.toIntExact(Files.getFileStore(path).getBlockSize());
+      bufferSize = Math.addExact(blockSize, blockSize - 1);
+      buffer = ByteBuffer.allocateDirect(bufferSize).alignedSlice(blockSize);

Review comment:
       `ByteBuffer.alignedSlice` was added since JDK 9 which was released in 
2017, so I guess it's just the code hasn't been updated to take advantage of 
the new API?




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

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



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

Reply via email to