[ 
https://issues.apache.org/jira/browse/LUCENE-2316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855736#action_12855736
 ] 

Michael McCandless commented on LUCENE-2316:
--------------------------------------------

I don't think Lucene relies on file length; we do use it for 
diagnostics/logging (eg IW's infoStream).

Hmm I guess we do use it for merging purposes (LogByteSizeMergePolicy), where 
we try to merge roughly similarly sized (by net size in bytes) segments.

I would rather not increase our reliance on it (eg LUCENE-2373 proposes to do 
so) -- it's a piece of metadata that is sometimes (eg over NFS) less reliable 
than file contents.  The less we rely on from the filesystem the more 
robust/portable Lucene will be...

Net/net I think we should keep the method, but restrict our use of it.

I do think we should move to throwing FNFE if the file does not exist... though 
I think a break in back compat may be OK, here?  (Vs do the new 
method/deprecated/abstract approach).

> Define clear semantics for Directory.fileLength
> -----------------------------------------------
>
>                 Key: LUCENE-2316
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2316
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Index
>            Reporter: Shai Erera
>            Priority: Minor
>             Fix For: 3.1
>
>
> On this thread: 
> http://mail-archives.apache.org/mod_mbox/lucene-java-dev/201003.mbox/%3c126142c1003121525v24499625u1589bbef4c079...@mail.gmail.com%3e
>  it was mentioned that Directory's fileLength behavior is not consistent 
> between Directory implementations if the given file name does not exist. 
> FSDirectory returns a 0 length while RAMDirectory throws FNFE.
> The problem is that the semantics of fileLength() are not defined. As 
> proposed in the thread, we'll define the following semantics:
> * Returns the length of the file denoted by <code>name</code> if the file 
> exists. The return value may be anything between 0 and Long.MAX_VALUE.
> * Throws FileNotFoundException if the file does not exist. Note that you can 
> call dir.fileExists(name) if you are not sure whether the file exists or not.
> For backwards we'll create a new method w/ clear semantics. Something like:
> {code}
> /**
>  * @deprecated the method will become abstract when #fileLength(name) has 
> been removed.
>  */
> public long getFileLength(String name) throws IOException {
>   long len = fileLength(name);
>   if (len == 0 && !fileExists(name)) {
>     throw new FileNotFoundException(name);
>   }
>   return len;
> }
> {code}
> The first line just calls the current impl. If it throws exception for a 
> non-existing file, we're ok. The second line verifies whether a 0 length is 
> for an existing file or not and throws an exception appropriately.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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

Reply via email to