You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Robert Muir (JIRA)" <ji...@apache.org> on 2016/07/11 13:32:11 UTC

[jira] [Commented] (LUCENE-7375) Can we allow FSDirectory subclasses to customize whether the ctor does a mkdir?

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

Robert Muir commented on LUCENE-7375:
-------------------------------------

the mkdir is necessary if the Directory will ever be used to perform any writes, otherwise locking is broken.

Lucene was broken here forever, because it used getCanonicalPath on a directory that may or may not exist: that would then be used by e.g. NativeFSLock as the key for the in-memory map and so on.

This was just one of the many ways that locking was broken.

You can see this by reading the javadocs:
https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath()

{quote}
 Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.
{quote}

So, in order for locking to work, its critical that we create the file.

> Can we allow FSDirectory subclasses to customize whether the ctor does a mkdir?
> -------------------------------------------------------------------------------
>
>                 Key: LUCENE-7375
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7375
>             Project: Lucene - Core
>          Issue Type: Improvement
>            Reporter: Michael McCandless
>
> Today, just instantiating an {{FSDirectory}} always brings the directory into existence, even if you will do no writes ({{createOutput}}).
> We have gone back and forth on this, over the ages.  E.g. see LUCENE-16 (only 2 digits there!!), LUCENE-773 (only 3 digits there!!), LUCENE-1464.  At one point we created the directory lazily, on the first write ({{createOutput}}) attempt, but now we always create it when you instantiate {{FSDirectory}}.
> This causes some hassle for consumers, e.g. in https://github.com/elastic/elasticsearch/pull/19338 ES is forking {{SimpleFSDirectory}} in order to have a read-only directory impl.
> Maybe we can do the {{Files.createDirectories}} in protected method that a subclass could override?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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