[
https://issues.apache.org/jira/browse/LUCENE-6508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14563953#comment-14563953
]
Robert Muir commented on LUCENE-6508:
-------------------------------------
Hi Uwe, I propose something like the following.
I like the example usage actually and think we should keep it.
I think javadocs need improvement on the semantics of close(), i dont think we
should use specialized exceptions but just deliver any exact exception that
happens.
I also want to set things up for impls to improve safety (best-effort) in some
cases. For example its dangerous for SimpleFSLockFactory to delete the lock
file, if someone removed the file and something else has it. It just
contributes to chaos, when a file creation time check could easily detect it.
{code}
/** An interprocess mutex lock.
* <p>Typical use might look like:<pre class="prettyprint">
* try (Lock lock = directory.obtainLock("my.lock")) {
* public Object doBody() {
* <i>... code to execute while locked ...</i>
* }
* }.run();
* </pre>
*
* @see Directory#obtainLock(String)
*
* @lucene.internal
*/
public abstract class Lock implements Closeable {
/**
* Releases exclusive access.
* <p>
* Note that exceptions thrown from close may require
* human intervention, as it may mean the lock was no
* longer valid, or that fs permissions prevent removal
* of the lock file, or other reasons.
* <p>
* {@inheritDoc}
*/
public abstract void close() throws IOException;
/**
* Best effort check that this lock is still valid. Locks
* could become invalidated externally for a number of reasons,
* for example if a user deletes the lock file manually or
* when a network filesystem is in use.
* @throws IOException if the lock is no longer valid.
*/
public abstract void ensureValid() throws IOException;
}
{code}
> Simplify Directory/lock api
> ---------------------------
>
> Key: LUCENE-6508
> URL: https://issues.apache.org/jira/browse/LUCENE-6508
> Project: Lucene - Core
> Issue Type: Bug
> Reporter: Robert Muir
> Assignee: Uwe Schindler
> Attachments: LUCENE-6508-deadcode1.patch
>
>
> See LUCENE-6507 for some background. In general it would be great if you can
> just acquire an immutable lock (or you get a failure) and then you close that
> to release it.
> Today the API might be too much for what is needed by IW.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]