mirror of https://github.com/apache/lucene.git
- Changed FSDirectory to use a lock dir specified by
org.apache.lucene.lockDir system property or java.io.temp fall-back one git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150234 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
712e742b78
commit
14065e0077
|
@ -86,8 +86,12 @@ public final class FSDirectory extends Directory {
|
||||||
private static final boolean DISABLE_LOCKS =
|
private static final boolean DISABLE_LOCKS =
|
||||||
Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1;
|
Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1;
|
||||||
|
|
||||||
|
private static final String LOCK_DIR =
|
||||||
|
System.getProperty("org.apache.lucene.lockdir",
|
||||||
|
System.getProperty("java.io.tmpdir"));
|
||||||
|
|
||||||
private static MessageDigest DIGESTER;
|
private static MessageDigest DIGESTER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
DIGESTER = MessageDigest.getInstance("MD5");
|
DIGESTER = MessageDigest.getInstance("MD5");
|
||||||
|
@ -143,10 +147,15 @@ public final class FSDirectory extends Directory {
|
||||||
|
|
||||||
private File directory = null;
|
private File directory = null;
|
||||||
private int refCount;
|
private int refCount;
|
||||||
|
private File lockDir;
|
||||||
|
|
||||||
private FSDirectory(File path, boolean create) throws IOException {
|
private FSDirectory(File path, boolean create) throws IOException {
|
||||||
directory = path;
|
directory = path;
|
||||||
|
|
||||||
|
lockDir = new File(LOCK_DIR);
|
||||||
|
if (!lockDir.isAbsolute()) {
|
||||||
|
lockDir = new File(directory, LOCK_DIR);
|
||||||
|
}
|
||||||
if (create)
|
if (create)
|
||||||
create();
|
create();
|
||||||
|
|
||||||
|
@ -165,15 +174,14 @@ public final class FSDirectory extends Directory {
|
||||||
if (!file.delete())
|
if (!file.delete())
|
||||||
throw new IOException("couldn't delete " + files[i]);
|
throw new IOException("couldn't delete " + files[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
String lockPrefix = getLockPrefix().toString(); // clear old locks
|
String lockPrefix = getLockPrefix().toString(); // clear old locks
|
||||||
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
files = lockDir.list();
|
||||||
files = tmpdir.list();
|
for (int i = 0; i < files.length; i++) {
|
||||||
for (int i = 0; i < files.length; i++) {
|
|
||||||
if (!files[i].startsWith(lockPrefix))
|
if (!files[i].startsWith(lockPrefix))
|
||||||
continue;
|
continue;
|
||||||
File file = new File(tmpdir, files[i]);
|
File lockFile = new File(lockDir, files[i]);
|
||||||
if (!file.delete())
|
if (!lockFile.delete())
|
||||||
throw new IOException("couldn't delete " + files[i]);
|
throw new IOException("couldn't delete " + files[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,9 +321,8 @@ public final class FSDirectory extends Directory {
|
||||||
buf.append("-");
|
buf.append("-");
|
||||||
buf.append(name);
|
buf.append(name);
|
||||||
|
|
||||||
// make the lock file in tmp, where anyone can create files.
|
// create a lock file
|
||||||
final File lockFile = new File(System.getProperty("java.io.tmpdir"),
|
final File lockFile = new File(lockDir, buf.toString());
|
||||||
buf.toString());
|
|
||||||
|
|
||||||
return new Lock() {
|
return new Lock() {
|
||||||
public boolean obtain() throws IOException {
|
public boolean obtain() throws IOException {
|
||||||
|
@ -347,7 +354,7 @@ public final class FSDirectory extends Directory {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e.toString());
|
throw new RuntimeException(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte digest[];
|
byte digest[];
|
||||||
synchronized (DIGESTER) {
|
synchronized (DIGESTER) {
|
||||||
digest = DIGESTER.digest(dirName.getBytes());
|
digest = DIGESTER.digest(dirName.getBytes());
|
||||||
|
@ -396,7 +403,7 @@ final class FSInputStream extends InputStream {
|
||||||
//debug_printInfo("OPEN");
|
//debug_printInfo("OPEN");
|
||||||
/* DEBUG */
|
/* DEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DEBUG */
|
/* DEBUG */
|
||||||
//public void close() throws IOException {
|
//public void close() throws IOException {
|
||||||
// debug_printInfo("CLOSE");
|
// debug_printInfo("CLOSE");
|
||||||
|
@ -404,7 +411,7 @@ final class FSInputStream extends InputStream {
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//private void debug_printInfo(String op) {
|
//private void debug_printInfo(String op) {
|
||||||
// try { throw new Exception(op + " <" + name + ">");
|
// try { throw new Exception(op + " <" + name + ">");
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// java.io.StringWriter sw = new java.io.StringWriter();
|
// java.io.StringWriter sw = new java.io.StringWriter();
|
||||||
// java.io.PrintWriter pw = new java.io.PrintWriter(sw);
|
// java.io.PrintWriter pw = new java.io.PrintWriter(sw);
|
||||||
|
@ -461,7 +468,7 @@ final class FSInputStream extends InputStream {
|
||||||
clone.isClone = true;
|
clone.isClone = true;
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Method used for testing. Returns true if the underlying
|
/** Method used for testing. Returns true if the underlying
|
||||||
* file descriptor is valid.
|
* file descriptor is valid.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -73,10 +73,6 @@ 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 static final String LOCK_DIR =
|
|
||||||
System.getProperty("org.apache.lucene.lockdir",
|
|
||||||
System.getProperty("java.io.tmpdir"));
|
|
||||||
|
|
||||||
/** Attempts to obtain exclusive access and immediately return
|
/** Attempts to obtain exclusive access and immediately return
|
||||||
* upon success or failure.
|
* upon success or failure.
|
||||||
|
|
Loading…
Reference in New Issue