From 5bc629692781ffb313571dd869c9c4645719ed53 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Sun, 9 May 2004 12:41:47 +0000 Subject: [PATCH] #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 --- src/java/org/apache/lucene/store/FSDirectory.java | 2 +- src/java/org/apache/lucene/store/Lock.java | 15 ++++++++++++++- .../org/apache/lucene/store/RAMDirectory.java | 4 +--- 3 files changed, 16 insertions(+), 5 deletions(-) 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 {