You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2007/02/28 00:33:33 UTC
svn commit: r512493 - in /lucene/java/trunk: ./
src/java/org/apache/lucene/store/ src/test/org/apache/lucene/store/
Author: mikemccand
Date: Tue Feb 27 15:33:31 2007
New Revision: 512493
URL: http://svn.apache.org/viewvc?view=rev&rev=512493
Log:
LUCENE-812: make sure Native/SimpleFSLockFactory can be set via system property
Modified:
lucene/java/trunk/CHANGES.txt
lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=512493&r1=512492&r2=512493
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Feb 27 15:33:31 2007
@@ -29,6 +29,11 @@
that there is a single trailing wildcard (and no additional wildcard
or '?' in the query text). (Doron Cohen)
+ 3. LUCENE-812: Add no-argument constructors to NativeFSLockFactory
+ and SimpleFSLockFactory. This enables all 4 builtin LockFactory
+ implementations to be specified via the System property
+ org.apache.lucene.store.FSDirectoryLockFactoryClass. (Mike McCandless)
+
Optimizations
======================= Release 2.1.0 2007-02-14 =======================
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=512493&r1=512492&r2=512493
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Tue Feb 27 15:33:31 2007
@@ -291,6 +291,12 @@
} catch (ClassCastException e) {
throw new IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory");
}
+
+ if (lockFactory instanceof NativeFSLockFactory) {
+ ((NativeFSLockFactory) lockFactory).setLockDir(path);
+ } else if (lockFactory instanceof SimpleFSLockFactory) {
+ ((SimpleFSLockFactory) lockFactory).setLockDir(path);
+ }
} else {
// Our default lock is SimpleFSLockFactory;
// default lockDir is our index directory:
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java?view=diff&rev=512493&r1=512492&r2=512493
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java Tue Feb 27 15:33:31 2007
@@ -52,10 +52,6 @@
* is fine because the OS will free the locks held against
* these files even though the files still remain.</p>
*
- * <p>Native locks file names have the substring "-n-", which
- * you can use to differentiate them from lock files created
- * by {@link SimpleFSLockFactory}.</p>
- *
* @see LockFactory
*/
@@ -91,6 +87,17 @@
}
/**
+ * Create a NativeFSLockFactory instance, with null (unset)
+ * lock directory. This is package-private and is only
+ * used by FSDirectory when creating this LockFactory via
+ * the System property
+ * org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ */
+ NativeFSLockFactory() throws IOException {
+ this((File) null);
+ }
+
+ /**
* Create a NativeFSLockFactory instance, storing lock
* files into the specified lockDirName:
*
@@ -107,20 +114,30 @@
* @param lockDir where lock files are created.
*/
public NativeFSLockFactory(File lockDir) throws IOException {
+ setLockDir(lockDir);
+ }
+ /**
+ * Set the lock directory. This is package-private and is
+ * only used externally by FSDirectory when creating this
+ * LockFactory via the System property
+ * org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ */
+ void setLockDir(File lockDir) throws IOException {
this.lockDir = lockDir;
-
- // Ensure that lockDir exists and is a directory.
- if (!lockDir.exists()) {
- if (!lockDir.mkdirs())
- throw new IOException("Cannot create directory: " +
+ if (lockDir != null) {
+ // Ensure that lockDir exists and is a directory.
+ if (!lockDir.exists()) {
+ if (!lockDir.mkdirs())
+ throw new IOException("Cannot create directory: " +
+ lockDir.getAbsolutePath());
+ } else if (!lockDir.isDirectory()) {
+ throw new IOException("Found regular file where directory expected: " +
lockDir.getAbsolutePath());
- } else if (!lockDir.isDirectory()) {
- throw new IOException("Found regular file where directory expected: " +
- lockDir.getAbsolutePath());
- }
+ }
- acquireTestLock();
+ acquireTestLock();
+ }
}
public synchronized Lock makeLock(String lockName) {
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java?view=diff&rev=512493&r1=512492&r2=512493
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java Tue Feb 27 15:33:31 2007
@@ -41,11 +41,22 @@
private File lockDir;
/**
+ * Create a SimpleFSLockFactory instance, with null (unset)
+ * lock directory. This is package-private and is only
+ * used by FSDirectory when creating this LockFactory via
+ * the System property
+ * org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ */
+ SimpleFSLockFactory() throws IOException {
+ this((File) null);
+ }
+
+ /**
* Instantiate using the provided directory (as a File instance).
* @param lockDir where lock files should be created.
*/
public SimpleFSLockFactory(File lockDir) throws IOException {
- init(lockDir);
+ setLockDir(lockDir);
}
/**
@@ -54,10 +65,16 @@
*/
public SimpleFSLockFactory(String lockDirName) throws IOException {
lockDir = new File(lockDirName);
- init(lockDir);
+ setLockDir(lockDir);
}
- protected void init(File lockDir) throws IOException {
+ /**
+ * Set the lock directory. This is package-private and is
+ * only used externally by FSDirectory when creating this
+ * LockFactory via the System property
+ * org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ */
+ void setLockDir(File lockDir) throws IOException {
this.lockDir = lockDir;
}
Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?view=diff&rev=512493&r1=512492&r2=512493
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Tue Feb 27 15:33:31 2007
@@ -197,23 +197,47 @@
// Verify: setting custom lock factory class (as system property) works:
+ // Verify: all 4 builtin LockFactory implementations are
+ // settable this way
// Verify: FSDirectory does basic locking correctly
public void testLockClassProperty() throws IOException {
String indexDirName = "index.TestLockFactory3";
+ String prpName = "org.apache.lucene.store.FSDirectoryLockFactoryClass";
- System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass",
- "org.apache.lucene.store.NoLockFactory");
+ try {
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ // NoLockFactory:
+ System.setProperty(prpName, "org.apache.lucene.store.NoLockFactory");
+ IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
+ NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
+ writer.close();
- assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
- NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
+ // SingleInstanceLockFactory:
+ System.setProperty(prpName, "org.apache.lucene.store.SingleInstanceLockFactory");
+ writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
+ SingleInstanceLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
+ writer.close();
- // Put back to the correct default for subsequent tests:
- // System.clearProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass");
- System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass", "");
+ // NativeFSLockFactory:
+ System.setProperty(prpName, "org.apache.lucene.store.NativeFSLockFactory");
+ writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
+ NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
+ writer.close();
+
+ // SimpleFSLockFactory:
+ System.setProperty(prpName, "org.apache.lucene.store.SimpleFSLockFactory");
+ writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
+ SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
+ writer.close();
+ } finally {
+ // Put back to the correct default for subsequent tests:
+ System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass", "");
+ }
- writer.close();
// Cleanup
rmDir(indexDirName);
}