Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

#28855 - better lock obtain timed out error message (Daniel Naber)

Erik Hatcher5bc629692781
diff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.java
index 8e0a2fe5d26..62bc2531abf 100644
--- a/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/src/java/org/apache/lucene/store/FSDirectory.java
@@ -290,7 +290,7 @@ public final class FSDirectory extends Directory {
// create a lock file
final File lockFile = new File(lockDir, buf.toString());
- return new Lock() {
+ return new Lock(lockFile) {
public boolean obtain() throws IOException {
if (DISABLE_LOCKS)
return true;
diff --git a/src/java/org/apache/lucene/store/Lock.java b/src/java/org/apache/lucene/store/Lock.java
index fd5c98b743b..55edce43613 100644
--- a/src/java/org/apache/lucene/store/Lock.java
+++ b/src/java/org/apache/lucene/store/Lock.java
@@ -18,6 +18,7 @@ package org.apache.lucene.store;
import org.apache.lucene.index.IndexWriter;
+import java.io.File;
import java.io.IOException;
/** An interprocess mutex lock.
@@ -35,7 +36,15 @@ import java.io.IOException;
*/
public abstract class Lock {
public static long LOCK_POLL_INTERVAL = 1000;
+ private File lockFile = null;
+
+ Lock(File lockFile) {
+ this.lockFile = lockFile;
+ }
+ Lock() {
+ }
+
/** Attempts to obtain exclusive access and immediately return
* upon success or failure.
* @return true iff exclusive access is obtained
@@ -55,7 +64,11 @@ public abstract class Lock {
int sleepCount = 0;
while (!locked) {
if (++sleepCount == maxSleepCount) {
- throw new IOException("Lock obtain timed out");
+ String s = "Lock obtain timed out";
+ if (lockFile != null) {
+ s += ", lock file =" + lockFile.getAbsolutePath();
+ }
+ throw new IOException(s);
}
try {
Thread.sleep(LOCK_POLL_INTERVAL);
diff --git a/src/java/org/apache/lucene/store/RAMDirectory.java b/src/java/org/apache/lucene/store/RAMDirectory.java
index 842a86e5658..ca698c2a2a9 100644
--- a/src/java/org/apache/lucene/store/RAMDirectory.java
+++ b/src/java/org/apache/lucene/store/RAMDirectory.java
@@ -18,7 +18,6 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.io.File;
-import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
@@ -115,8 +114,7 @@ public final class RAMDirectory extends Directory {
/** Set the modified time of an existing file to now. */
public void touchFile(String name) throws IOException {
// final boolean MONITOR = false;
- int count = 0;
-
+
RAMFile file = (RAMFile)files.get(name);
long ts2, ts1 = System.currentTimeMillis();
do {