提交 1b31e3e9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Database file lock: the exception "lock file modified in the future" is longer thrown.

上级 dfaf34f5
...@@ -262,9 +262,14 @@ public class FileLock { ...@@ -262,9 +262,14 @@ public class FileLock {
long last = fs.getLastModified(fileName); long last = fs.getLastModified(fileName);
long dist = System.currentTimeMillis() - last; long dist = System.currentTimeMillis() - last;
if (dist < -TIME_GRANULARITY) { if (dist < -TIME_GRANULARITY) {
throw getExceptionFatal("Lock file modification time is in the future; " + // lock file modified in the future -
"if required please delete the file " + fileName + " manually and retry; " + // wait for a bit longer than usual
"dist=" + dist, null); try {
Thread.sleep(2 * sleep);
} catch (Exception e) {
trace.debug("sleep", e);
}
return;
} else if (dist > TIME_GRANULARITY) { } else if (dist > TIME_GRANULARITY) {
return; return;
} }
......
...@@ -46,11 +46,22 @@ public class TestFileLock extends TestBase implements Runnable { ...@@ -46,11 +46,22 @@ public class TestFileLock extends TestBase implements Runnable {
} }
public void test() throws Exception { public void test() throws Exception {
testFutureModificationDate();
testSimple(); testSimple();
test(false); test(false);
test(true); test(true);
} }
private void testFutureModificationDate() throws Exception {
File f = new File(FILE);
f.delete();
f.createNewFile();
f.setLastModified(System.currentTimeMillis() + 10000);
FileLock lock = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
lock.lock(FileLock.LOCK_FILE);
lock.unlock();
}
private void testSimple() throws SQLException { private void testSimple() throws SQLException {
FileLock lock1 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP); FileLock lock1 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
FileLock lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP); FileLock lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论