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

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2004-05-09 12:41:47 +00:00
parent f0017af921
commit 5bc6296927
3 changed files with 16 additions and 5 deletions

View File

@ -290,7 +290,7 @@ public final class FSDirectory extends Directory {
// create a lock file // create a lock file
final File lockFile = new File(lockDir, buf.toString()); final File lockFile = new File(lockDir, buf.toString());
return new Lock() { return new Lock(lockFile) {
public boolean obtain() throws IOException { public boolean obtain() throws IOException {
if (DISABLE_LOCKS) if (DISABLE_LOCKS)
return true; return true;

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import java.io.File;
import java.io.IOException; import java.io.IOException;
/** An interprocess mutex lock. /** An interprocess mutex lock.
@ -35,6 +36,14 @@ import java.io.IOException;
*/ */
public abstract class Lock { public abstract class Lock {
public static long LOCK_POLL_INTERVAL = 1000; 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 /** Attempts to obtain exclusive access and immediately return
* upon success or failure. * upon success or failure.
@ -55,7 +64,11 @@ public abstract class Lock {
int sleepCount = 0; int sleepCount = 0;
while (!locked) { while (!locked) {
if (++sleepCount == maxSleepCount) { 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 { try {
Thread.sleep(LOCK_POLL_INTERVAL); Thread.sleep(LOCK_POLL_INTERVAL);

View File

@ -18,7 +18,6 @@ package org.apache.lucene.store;
import java.io.IOException; import java.io.IOException;
import java.io.File; import java.io.File;
import java.util.Vector;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Enumeration; import java.util.Enumeration;
@ -115,7 +114,6 @@ public final class RAMDirectory extends Directory {
/** Set the modified time of an existing file to now. */ /** Set the modified time of an existing file to now. */
public void touchFile(String name) throws IOException { public void touchFile(String name) throws IOException {
// final boolean MONITOR = false; // final boolean MONITOR = false;
int count = 0;
RAMFile file = (RAMFile)files.get(name); RAMFile file = (RAMFile)files.get(name);
long ts2, ts1 = System.currentTimeMillis(); long ts2, ts1 = System.currentTimeMillis();