提交 4d30ee3f authored 作者: Thomas Mueller's avatar Thomas Mueller

Temporary files were sometimes deleted too late.

上级 35d966ee
......@@ -598,8 +598,8 @@ public class Database implements DataHandler {
systemSession.commit(true);
if (!readOnly && persistent) {
emergencyReserve = openFile(createTempFile(), "rw", false);
emergencyReserve.autoDelete();
emergencyReserve.setLength(SysProperties.EMERGENCY_SPACE_INITIAL);
emergencyReserve.autoDelete();
}
traceSystem.getTrace(Trace.DATABASE).info("opened " + databaseName);
}
......
......@@ -108,7 +108,6 @@ public class UndoLog {
if (file == null) {
String fileName = database.createTempFile();
file = database.openFile(fileName, "rw", false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH);
rowBuff = DataPage.create(database, Constants.DEFAULT_DATA_PAGE_SIZE);
DataPage buff = rowBuff;
......@@ -119,6 +118,7 @@ public class UndoLog {
} else {
saveIfPossible(entry, rowBuff);
}
file.autoDelete();
}
}
......
......@@ -68,7 +68,6 @@ class ResultDiskBuffer implements ResultExternal {
String fileName = session.getDatabase().createTempFile();
file = session.getDatabase().openFile(fileName, "rw", false);
file.setCheckedWriting(false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH);
if (sort != null) {
tapes = new ObjectArray();
......@@ -127,6 +126,7 @@ class ResultDiskBuffer implements ResultExternal {
public void done() throws SQLException {
file.seek(FileStore.HEADER_LENGTH);
file.autoDelete();
}
public void reset() {
......
......@@ -84,7 +84,6 @@ public class RowList {
this.cache = db.getDataFile().getCache();
String fileName = db.createTempFile();
file = db.openFile(fileName, "rw", false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH);
rowBuff = DataPage.create(db, Constants.DEFAULT_DATA_PAGE_SIZE);
file.seek(FileStore.HEADER_LENGTH);
......@@ -100,6 +99,7 @@ public class RowList {
writeRow(buff, r);
}
flushBuffer(buff);
file.autoDelete();
list.clear();
memory = 0;
}
......@@ -118,7 +118,6 @@ public class RowList {
file.write(buff.getBytes(), 0, buff.length());
}
/**
* Add a row to the list.
*
......@@ -258,6 +257,7 @@ public class RowList {
*/
public void close() {
if (file != null) {
file.autoDelete();
file.closeAndDeleteSilently();
file = null;
rowBuff = null;
......
......@@ -241,6 +241,7 @@ public class FileStore {
public void closeAndDeleteSilently() {
if (file != null) {
closeSilently();
TempFileDeleter.updateAutoDelete(autoDeleteReference);
TempFileDeleter.deleteFile(autoDeleteReference, name);
name = null;
}
......@@ -457,7 +458,11 @@ public class FileStore {
* Automatically delete the file once it is no longer in use.
*/
public void autoDelete() {
if (autoDeleteReference == null) {
autoDeleteReference = TempFileDeleter.addFile(name, this);
} else {
TempFileDeleter.updateAutoDelete(autoDeleteReference);
}
}
/**
......
......@@ -61,6 +61,22 @@ public class TempFileDeleter {
return ref;
}
/**
* Update the last modified date of the auto-delete reference. If the file
* was modified after that, it will not be deleted (because it might have
* been deleted and then re-created).
*
* @param ref the reference
*/
public static synchronized void updateAutoDelete(Reference ref) {
TempFile f2 = (TempFile) REF_MAP.get(ref);
if (f2 != null) {
String fileName = f2.fileName;
long mod = FileUtils.getLastModified(fileName);
f2.lastModified = mod;
}
}
/**
* Delete the given file now. This will remove the reference from the list.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论