dmitrys 2003/09/25 14:45:58
Modified: src/java/org/apache/lucene/store RAMDirectory.java
Log:
Make RAMDirectory's touchFile method wait long enough for the system clock
to register a new timestamp. This makes locking logic more robust.
Revision Changes Path
1.9 +33 -18
jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java
Index: RAMDirectory.java
===================================================================
RCS file:
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RAMDirectory.java 1 May 2003 19:50:17 -0000 1.8
+++ RAMDirectory.java 25 Sep 2003 21:45:58 -0000 1.9
@@ -146,8 +146,23 @@
/** 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);
- 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. */
@@ -187,21 +202,21 @@
*/
public final Lock makeLock(final String name) {
return new Lock() {
- public boolean obtain() throws IOException {
- synchronized (files) {
- if (!fileExists(name)) {
- createFile(name).close();
- return true;
- }
- return false;
- }
- }
- public void release() {
- deleteFile(name);
- }
- public boolean isLocked() {
- return fileExists(name);
- }
+ public boolean obtain() throws IOException {
+ synchronized (files) {
+ if (!fileExists(name)) {
+ createFile(name).close();
+ return true;
+ }
+ return false;
+ }
+ }
+ public void release() {
+ deleteFile(name);
+ }
+ public boolean isLocked() {
+ return fileExists(name);
+ }
};
}
@@ -274,7 +289,7 @@
bytesToCopy = len - bytesToCopy; // remaining bytes
bufferNumber++;
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);
System.arraycopy(src, srcOffset, buffer, 0, bytesToCopy);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]