Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

- Added WRITE_LOCK_NAME and COMMIT_LOCK_NAME, so that their names are not hard-coded in half a dozen places in the code.

Otis Gospodnetic9e968c91272d
diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.java
index efc635b74fd..3505fc6e2b8 100644
--- a/src/java/org/apache/lucene/index/IndexReader.java
+++ b/src/java/org/apache/lucene/index/IndexReader.java
@@ -76,6 +76,9 @@ import org.apache.lucene.document.Field; // for javadoc
document in the index. These document numbers are ephemeral--they may change
as documents are added to and deleted from an index. Clients should thus not
rely on a given document having the same number between sessions.
+
+ @author Doug Cutting
+ @version $Id$
*/
public abstract class IndexReader {
protected IndexReader(Directory directory) {
@@ -104,7 +107,9 @@ public abstract class IndexReader {
/** Returns an IndexReader reading the index in the given Directory. */
public static IndexReader open(final Directory directory) throws IOException{
synchronized (directory) { // in- & inter-process sync
- return (IndexReader)new Lock.With(directory.makeLock("commit.lock"), IndexWriter.COMMIT_LOCK_TIMEOUT) {
+ return (IndexReader)new Lock.With(
+ directory.makeLock("IndexWriter.COMMIT_LOCK_NAME"),
+ IndexWriter.COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
IndexReader result = null;
@@ -264,7 +269,7 @@ public abstract class IndexReader {
*/
public final synchronized void delete(int docNum) throws IOException {
if (writeLock == null) {
- Lock writeLock = directory.makeLock("write.lock");
+ Lock writeLock = directory.makeLock("IndexWriter.WRITE_LOCK_NAME");
if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock
throw new IOException("Index locked for write: " + writeLock);
this.writeLock = writeLock;
@@ -355,8 +360,8 @@ public abstract class IndexReader {
*/
public static boolean isLocked(Directory directory) throws IOException {
return
- directory.makeLock("write.lock").isLocked() ||
- directory.makeLock("commit.lock").isLocked();
+ directory.makeLock("IndexWriter.WRITE_LOCK_NAME").isLocked() ||
+ directory.makeLock("IndexWriter.COMMIT_LOCK_NAME").isLocked();
}
@@ -378,7 +383,7 @@ public abstract class IndexReader {
* currently accessing this index.
*/
public static void unlock(Directory directory) throws IOException {
- directory.makeLock("write.lock").release();
- directory.makeLock("commit.lock").release();
+ directory.makeLock("IndexWriter.WRITE_LOCK_NAME").release();
+ directory.makeLock("IndexWriter.COMMIT_LOCK_NAME").release();
}
}
diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java
index 327bb65abbb..1af9fad294b 100644
--- a/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/src/java/org/apache/lucene/index/IndexWriter.java
@@ -89,6 +89,9 @@ import org.apache.lucene.analysis.Analyzer;
public class IndexWriter {
public static long WRITE_LOCK_TIMEOUT = 1000;
public static long COMMIT_LOCK_TIMEOUT = 10000;
+
+ public static final String WRITE_LOCK_NAME = "write.lock";
+ public static final String COMMIT_LOCK_NAME = "commit.lock";
private Directory directory; // where this index resides
private Analyzer analyzer; // how to analyze text
@@ -166,13 +169,13 @@ public class IndexWriter {
directory = d;
analyzer = a;
- Lock writeLock = directory.makeLock("write.lock");
+ Lock writeLock = directory.makeLock("IndexWriter.WRITE_LOCK_NAME");
if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock
throw new IOException("Index locked for write: " + writeLock);
this.writeLock = writeLock; // save it
synchronized (directory) { // in- & inter-process sync
- new Lock.With(directory.makeLock("commit.lock"), COMMIT_LOCK_TIMEOUT) {
+ new Lock.With(directory.makeLock("COMMIT_LOCK_NAME"), COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
if (create)
segmentInfos.write(directory);
@@ -395,7 +398,7 @@ public class IndexWriter {
directory));
synchronized (directory) { // in- & inter-process sync
- new Lock.With(directory.makeLock("commit.lock"), COMMIT_LOCK_TIMEOUT) {
+ new Lock.With(directory.makeLock("COMMIT_LOCK_NAME"), COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
segmentInfos.write(directory); // commit before deleting
deleteSegments(segmentsToDelete); // delete now-unused segments