You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/01/15 18:27:31 UTC

[GitHub] [lucene-solr] uschindler commented on a change in pull request #2052: LUCENE-8982: Make NativeUnixDirectory pure java with FileChannel direct IO flag, and rename to DirectIODirectory

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



##########
File path: lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
##########
@@ -307,7 +314,14 @@ public void close() throws IOException {
 
     @Override
     public long getFilePointer() {
-      return filePos + buffer.position();
+      long filePointer = filePos + buffer.position();
+
+      // opening the input and immediately calling getFilePointer without calling readX (and thus refill) first,
+      // will result in negative value equal to bufferSize being returned,
+      // due to the initialization method filePos = -bufferSize used in constructor.
+      assert filePointer == -buffer.capacity() || filePointer >= 0 :
+        "filePointer should either be initial value equal to negative buffer capacity, or larger than or equal to 0";
+      return Math.max(filePointer, 0);

Review comment:
       Thanks, this was driving me crazy when I tried to fix this (I gave up after some beers deep night).




----------------------------------------------------------------
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:
users@infra.apache.org



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