mirror of https://github.com/apache/lucene.git
Make RAMDirectory's touchFile method wait long enough for the system clock
to register a new timestamp. This makes locking logic more robust. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
28ef35ee3e
commit
250f13e99c
|
@ -146,8 +146,23 @@ 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;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
RAMFile file = (RAMFile)files.get(name);
|
RAMFile file = (RAMFile)files.get(name);
|
||||||
file.lastModified = System.currentTimeMillis();
|
long ts2, ts1 = System.currentTimeMillis();
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
Thread.sleep(0, 1);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
ts2 = System.currentTimeMillis();
|
||||||
|
if (MONITOR) count ++;
|
||||||
|
} while(ts1 == ts2);
|
||||||
|
|
||||||
|
file.lastModified = ts2;
|
||||||
|
|
||||||
|
if (MONITOR)
|
||||||
|
System.out.println("SLEEP COUNT: " + count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the length in bytes of a file in the directory. */
|
/** Returns the length in bytes of a file in the directory. */
|
||||||
|
@ -187,21 +202,21 @@ public final class RAMDirectory extends Directory {
|
||||||
*/
|
*/
|
||||||
public final Lock makeLock(final String name) {
|
public final Lock makeLock(final String name) {
|
||||||
return new Lock() {
|
return new Lock() {
|
||||||
public boolean obtain() throws IOException {
|
public boolean obtain() throws IOException {
|
||||||
synchronized (files) {
|
synchronized (files) {
|
||||||
if (!fileExists(name)) {
|
if (!fileExists(name)) {
|
||||||
createFile(name).close();
|
createFile(name).close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void release() {
|
public void release() {
|
||||||
deleteFile(name);
|
deleteFile(name);
|
||||||
}
|
}
|
||||||
public boolean isLocked() {
|
public boolean isLocked() {
|
||||||
return fileExists(name);
|
return fileExists(name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +289,7 @@ final class RAMOutputStream extends OutputStream {
|
||||||
bytesToCopy = len - bytesToCopy; // remaining bytes
|
bytesToCopy = len - bytesToCopy; // remaining bytes
|
||||||
bufferNumber++;
|
bufferNumber++;
|
||||||
if (bufferNumber == file.buffers.size())
|
if (bufferNumber == file.buffers.size())
|
||||||
file.buffers.addElement(new byte[OutputStream.BUFFER_SIZE]);
|
file.buffers.addElement(new byte[OutputStream.BUFFER_SIZE]);
|
||||||
buffer = (byte[])file.buffers.elementAt(bufferNumber);
|
buffer = (byte[])file.buffers.elementAt(bufferNumber);
|
||||||
System.arraycopy(src, srcOffset, buffer, 0, bytesToCopy);
|
System.arraycopy(src, srcOffset, buffer, 0, bytesToCopy);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue