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/01/13 16:40:34 UTC
svn commit: r495911 - in /lucene/java/trunk/src:
java/org/apache/lucene/store/ test/org/apache/lucene/store/
Author: mikemccand
Date: Sat Jan 13 07:40:34 2007
New Revision: 495911
URL: http://svn.apache.org/viewvc?view=rev&rev=495911
Log:
LUCENE-771:
* API change: change LockFactory.clearAllLocks() to
LockFactory.clearLock(String lockName) because locks are no longer
so "global". (This API is not released yet). Now FSDirectory
just clears specifically the write lock when create=true.
* Fix abstraction violation of LockFactory: FSDirectory now calls
clearLock() instead of doing File deletes itself (duh!).
Modified:
lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java
lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java
lucene/java/trunk/src/java/org/apache/lucene/store/NoLockFactory.java
lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
lucene/java/trunk/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java
lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
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=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Sat Jan 13 07:40:34 2007
@@ -332,15 +332,7 @@
}
}
- if (lockFactory.getLockPrefix() != null) {
- lockFactory.clearAllLocks();
- } else {
- // Lock file is stored in the index, so we just remove
- // it ourselves here:
- File lockFile = new File(directory, IndexWriter.WRITE_LOCK_NAME);
- if (lockFile.exists() && !lockFile.delete())
- throw new IOException("Cannot delete " + lockFile);
- }
+ lockFactory.clearLock(IndexWriter.WRITE_LOCK_NAME);
}
/** Returns an array of strings, one for each Lucene index file in the directory. */
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java?view=diff&rev=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/LockFactory.java Sat Jan 13 07:40:34 2007
@@ -56,9 +56,10 @@
public abstract Lock makeLock(String lockName);
/**
- * Clear any existing locks. Only call this at a time when you
- * are certain the lock files are not in use. {@link FSDirectory}
- * calls this when creating a new index.
+ * Attempt to clear (forcefully unlock and remove) the
+ * specified lock. Only call this at a time when you are
+ * certain this lock is no longer in use.
+ * @param lockName name of the lock to be cleared.
*/
- abstract void clearAllLocks() throws IOException;
+ abstract public void clearLock(String lockName) throws IOException;
}
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=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/NativeFSLockFactory.java Sat Jan 13 07:40:34 2007
@@ -129,24 +129,19 @@
return new NativeFSLock(lockDir, lockName);
}
- protected void clearAllLocks() throws IOException {
+ public void clearLock(String lockName) throws IOException {
// Note that this isn't strictly required anymore
// because the existence of these files does not mean
// they are locked, but, still do this in case people
// really want to see the files go away:
- if (lockDir.exists() && lockPrefix != null) {
- String[] files = lockDir.list();
- if (files == null)
- throw new IOException("Cannot read lock directory " +
- lockDir.getAbsolutePath());
- String prefix = lockPrefix + "-n-";
- for (int i = 0; i < files.length; i++) {
- if (files[i].startsWith(prefix)) {
- File lockFile = new File(lockDir, files[i]);
- if (!lockFile.delete())
- throw new IOException("Cannot delete " + lockFile);
- }
- }
+ if (lockDir.exists()) {
+ if (lockPrefix != null) {
+ lockName = lockPrefix + "-n-" + lockName;
+ }
+ File lockFile = new File(lockDir, lockName);
+ if (lockFile.exists() && !lockFile.delete()) {
+ throw new IOException("Cannot delete " + lockFile);
+ }
}
}
};
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/NoLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/NoLockFactory.java?view=diff&rev=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/NoLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/NoLockFactory.java Sat Jan 13 07:40:34 2007
@@ -42,7 +42,7 @@
return singletonLock;
}
- public void clearAllLocks() {};
+ public void clearLock(String lockName) {};
};
class NoLock extends Lock {
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=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/SimpleFSLockFactory.java Sat Jan 13 07:40:34 2007
@@ -68,20 +68,15 @@
return new SimpleFSLock(lockDir, lockName);
}
- protected void clearAllLocks() throws IOException {
- if (lockDir.exists() && lockPrefix != null) {
- String[] files = lockDir.list();
- if (files == null)
- throw new IOException("Cannot read lock directory " +
- lockDir.getAbsolutePath());
- String prefix = lockPrefix + "-";
- for (int i = 0; i < files.length; i++) {
- if (!files[i].startsWith(prefix))
- continue;
- File lockFile = new File(lockDir, files[i]);
- if (!lockFile.delete())
- throw new IOException("Cannot delete " + lockFile);
- }
+ public void clearLock(String lockName) throws IOException {
+ if (lockDir.exists()) {
+ if (lockPrefix != null) {
+ lockName = lockPrefix + "-" + lockName;
+ }
+ File lockFile = new File(lockDir, lockName);
+ if (lockFile.exists() && !lockFile.delete()) {
+ throw new IOException("Cannot delete " + lockFile);
+ }
}
}
};
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java?view=diff&rev=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java Sat Jan 13 07:40:34 2007
@@ -43,8 +43,12 @@
return new SingleInstanceLock(locks, lockName);
}
- public void clearAllLocks() throws IOException {
- locks = new HashSet();
+ public void clearLock(String lockName) throws IOException {
+ synchronized(locks) {
+ if (locks.contains(lockName)) {
+ locks.remove(lockName);
+ }
+ }
}
};
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=495911&r1=495910&r2=495911
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Sat Jan 13 07:40:34 2007
@@ -494,7 +494,7 @@
return lock;
}
- public void clearAllLocks() {}
+ public void clearLock(String specificLockName) {}
public class MockLock extends Lock {
public int lockAttempts;