Mailing List Archive

cvs commit: jakarta-lucene/src/java/org/apache/lucene/store FSDirectory.java
otis 2002/06/21 07:57:46

Modified: . TODO.txt
src/java/org/apache/lucene/store FSDirectory.java
Log:
- Added the ability to disable creation of locks on the file system, in order
to allow Lucene to be used on read-only media.
To disable lock creation set 'disableLocks' system property to 'true'.

Revision Changes Path
1.2 +4 -6 jakarta-lucene/TODO.txt

Index: TODO.txt
===================================================================
RCS file: /home/cvs/jakarta-lucene/TODO.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TODO.txt 27 May 2002 23:56:54 -0000 1.1
+++ TODO.txt 21 Jun 2002 14:57:46 -0000 1.2
@@ -32,10 +32,8 @@
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=lucene-dev@jakarta.apache.org&msgId=114749
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=lucene-dev@jakarta.apache.org&msgId=114757

-- Add to FSDirectory the ability to specify where lock files live and
- to disable the use of lock files altogether (for read-only media).
- c.f.
- http://nagoya.apache.org/eyebrowse/BrowseList?listName=lucene-user@jakarta.apache.org&by=thread&from=57011
+- Add to FSDirectory the ability to disable the use of lock files altogether (for read-only media).
+ Status: COMPLETED

- Add some requested methods:
String[] Document.getValues(String fieldName);



1.7 +18 -3 jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java

Index: FSDirectory.java
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FSDirectory.java 15 Mar 2002 05:52:57 -0000 1.6
+++ FSDirectory.java 21 Jun 2002 14:57:46 -0000 1.7
@@ -77,6 +77,8 @@
* require Java 1.2. Instead we use refcounts... */
private static final Hashtable DIRECTORIES = new Hashtable();

+ private static final boolean DISABLE_LOCKS = Boolean.getBoolean("disableLocks");
+
/** Returns the directory instance for the named location.
*
* <p>Directories are cached, so that, for a given canonical path, the same
@@ -211,18 +213,31 @@
return new FSInputStream(new File(directory, name));
}

- /** Construct a {@link Lock}.
+ /**
+ * Constructs a {@link Lock} with the specified name.
+ * If JDK 1.1 is used the lock file is not really made.
+ * If system property <I>disableLocks</I> has the value of 'true'
+ * the lock will not be created. Assigning this property any other value
+ * will <B>not</B> prevent creation of locks.
+ * <BR>
+ * This is useful for using Lucene on read-only medium, such as CD-ROM.
+ *
* @param name the name of the lock file
+ * @return an instance of <code>Lock</code> holding the lock
*/
public final Lock makeLock(String name) {
final File lockFile = new File(directory, name);
return new Lock() {
public boolean obtain() throws IOException {
- if (Constants.JAVA_1_1) return true; // locks disabled in jdk 1.1
+ if (Constants.JAVA_1_1)
+ return true; // locks disabled in jdk 1.1
+ if (DISABLE_LOCKS)
+ return true;
return lockFile.createNewFile();
}
public void release() {
- if (Constants.JAVA_1_1) return; // locks disabled in jdk 1.1
+ if (Constants.JAVA_1_1)
+ return; // locks disabled in jdk 1.1
lockFile.delete();
}
public String toString() {




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
Re: cvs commit: jakarta-lucene/src/java/org/apache/lucene/store FSDirectory.java [ In reply to ]
otis@apache.org wrote:
[ ... ]
> + private static final boolean DISABLE_LOCKS = Boolean.getBoolean("disableLocks");
[ ... ]
> public boolean obtain() throws IOException {
> - if (Constants.JAVA_1_1) return true; // locks disabled in jdk 1.1
> + if (Constants.JAVA_1_1)
> + return true; // locks disabled in jdk 1.1
> + if (DISABLE_LOCKS)
> + return true;
> return lockFile.createNewFile();
> }

It would be simpler to just define DISABLE_LOCKS as:

private static final boolean DISABLE_LOCKS
Boolean.getBoolean("disableLocks") || Constants.JAVA_1_1;

Then obtain() and release() can just have one check, of the form:

if (DISABLE_LOCKS)
...

Also, documentation of the "disableLocks" property should be added to
FSDirectory's javadoc. We don't want undocumented features!

Doug


--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
cvs commit: jakarta-lucene/src/java/org/apache/lucene/store FSDirectory.java [ In reply to ]
otis 2002/06/25 09:09:15

Modified: src/java/org/apache/lucene/store FSDirectory.java
Log:
- Reduced the number of condition checks for disabling locks.
- Documented the use of 'disableLocks' system property in class Javadoc.

Revision Changes Path
1.8 +20 -18 jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java

Index: FSDirectory.java
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FSDirectory.java 21 Jun 2002 14:57:46 -0000 1.7
+++ FSDirectory.java 25 Jun 2002 16:09:15 -0000 1.8
@@ -63,10 +63,13 @@
import org.apache.lucene.util.Constants;

/**
- Straightforward implementation of Directory as a directory of files.
- @see Directory
- @author Doug Cutting
-*/
+ * Straight forward implementation of Directory as a directory of files.
+ * If the system property 'disableLocks' has the String value of "true", lock
+ * creation will be disabled.
+ *
+ * @see Directory
+ * @author Doug Cutting
+ */

final public class FSDirectory extends Directory {
/** This cache of directories ensures that there is a unique Directory
@@ -77,14 +80,15 @@
* require Java 1.2. Instead we use refcounts... */
private static final Hashtable DIRECTORIES = new Hashtable();

- private static final boolean DISABLE_LOCKS = Boolean.getBoolean("disableLocks");
+ private static final boolean DISABLE_LOCKS =
+ Boolean.getBoolean("disableLocks") || Constants.JAVA_1_1;

/** Returns the directory instance for the named location.
- *
+ *
* <p>Directories are cached, so that, for a given canonical path, the same
* FSDirectory instance will always be returned. This permits
* synchronization on directories.
- *
+ *
* @param path the path to the directory.
* @param create if true, create, or erase any existing contents.
* @return the FSDirectory for the named file. */
@@ -94,11 +98,11 @@
}

/** Returns the directory instance for the named location.
- *
+ *
* <p>Directories are cached, so that, for a given canonical path, the same
* FSDirectory instance will always be returned. This permits
* synchronization on directories.
- *
+ *
* @param file the path to the directory.
* @param create if true, create, or erase any existing contents.
* @return the FSDirectory for the named file. */
@@ -151,19 +155,19 @@
public final String[] list() throws IOException {
return directory.list();
}
-
+
/** Returns true iff a file with the given name exists. */
public final boolean fileExists(String name) throws IOException {
File file = new File(directory, name);
return file.exists();
}
-
+
/** Returns the time the named file was last modified. */
public final long fileModified(String name) throws IOException {
File file = new File(directory, name);
return file.lastModified();
}
-
+
/** Returns the time the named file was last modified. */
public static final long fileModified(File directory, String name)
throws IOException {
@@ -229,15 +233,13 @@
final File lockFile = new File(directory, name);
return new Lock() {
public boolean obtain() throws IOException {
- if (Constants.JAVA_1_1)
- return true; // locks disabled in jdk 1.1
if (DISABLE_LOCKS)
return true;
return lockFile.createNewFile();
}
public void release() {
- if (Constants.JAVA_1_1)
- return; // locks disabled in jdk 1.1
+ if (DISABLE_LOCKS)
+ return;
lockFile.delete();
}
public String toString() {
@@ -308,7 +310,7 @@
}

protected final void finalize() throws IOException {
- close(); // close the file
+ close(); // close the file
}

public Object clone() {
@@ -345,7 +347,7 @@
}

protected final void finalize() throws IOException {
- file.close(); // close the file
+ file.close(); // close the file
}

}




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
cvs commit: jakarta-lucene/src/java/org/apache/lucene/store FSDirectory.java [ In reply to ]
otis 2002/06/26 10:30:11

Modified: src/java/org/apache/lucene/store FSDirectory.java
Log:
- Changed the 'disableLocks' system property name to 'disableLuceneLocks'.
- Fixed my own misspelling from the previous commit.

Revision Changes Path
1.9 +5 -5 jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java

Index: FSDirectory.java
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FSDirectory.java 25 Jun 2002 16:09:15 -0000 1.8
+++ FSDirectory.java 26 Jun 2002 17:30:11 -0000 1.9
@@ -63,9 +63,9 @@
import org.apache.lucene.util.Constants;

/**
- * Straight forward implementation of Directory as a directory of files.
- * If the system property 'disableLocks' has the String value of "true", lock
- * creation will be disabled.
+ * Straightforward implementation of Directory as a directory of files.
+ * If the system property 'disableLuceneLocks' has the String value of "true",
+ * lock creation will be disabled.
*
* @see Directory
* @author Doug Cutting
@@ -81,7 +81,7 @@
private static final Hashtable DIRECTORIES = new Hashtable();

private static final boolean DISABLE_LOCKS =
- Boolean.getBoolean("disableLocks") || Constants.JAVA_1_1;
+ Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1;

/** Returns the directory instance for the named location.
*
@@ -220,7 +220,7 @@
/**
* Constructs a {@link Lock} with the specified name.
* If JDK 1.1 is used the lock file is not really made.
- * If system property <I>disableLocks</I> has the value of 'true'
+ * If system property <I>disableLuceneLocks</I> has the value of 'true'
* the lock will not be created. Assigning this property any other value
* will <B>not</B> prevent creation of locks.
* <BR>




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