提交 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 { ...@@ -598,8 +598,8 @@ public class Database implements DataHandler {
systemSession.commit(true); systemSession.commit(true);
if (!readOnly && persistent) { if (!readOnly && persistent) {
emergencyReserve = openFile(createTempFile(), "rw", false); emergencyReserve = openFile(createTempFile(), "rw", false);
emergencyReserve.autoDelete();
emergencyReserve.setLength(SysProperties.EMERGENCY_SPACE_INITIAL); emergencyReserve.setLength(SysProperties.EMERGENCY_SPACE_INITIAL);
emergencyReserve.autoDelete();
} }
traceSystem.getTrace(Trace.DATABASE).info("opened " + databaseName); traceSystem.getTrace(Trace.DATABASE).info("opened " + databaseName);
} }
......
...@@ -108,7 +108,6 @@ public class UndoLog { ...@@ -108,7 +108,6 @@ public class UndoLog {
if (file == null) { if (file == null) {
String fileName = database.createTempFile(); String fileName = database.createTempFile();
file = database.openFile(fileName, "rw", false); file = database.openFile(fileName, "rw", false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH); file.seek(FileStore.HEADER_LENGTH);
rowBuff = DataPage.create(database, Constants.DEFAULT_DATA_PAGE_SIZE); rowBuff = DataPage.create(database, Constants.DEFAULT_DATA_PAGE_SIZE);
DataPage buff = rowBuff; DataPage buff = rowBuff;
...@@ -119,6 +118,7 @@ public class UndoLog { ...@@ -119,6 +118,7 @@ public class UndoLog {
} else { } else {
saveIfPossible(entry, rowBuff); saveIfPossible(entry, rowBuff);
} }
file.autoDelete();
} }
} }
......
...@@ -68,7 +68,6 @@ class ResultDiskBuffer implements ResultExternal { ...@@ -68,7 +68,6 @@ class ResultDiskBuffer implements ResultExternal {
String fileName = session.getDatabase().createTempFile(); String fileName = session.getDatabase().createTempFile();
file = session.getDatabase().openFile(fileName, "rw", false); file = session.getDatabase().openFile(fileName, "rw", false);
file.setCheckedWriting(false); file.setCheckedWriting(false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH); file.seek(FileStore.HEADER_LENGTH);
if (sort != null) { if (sort != null) {
tapes = new ObjectArray(); tapes = new ObjectArray();
...@@ -127,6 +126,7 @@ class ResultDiskBuffer implements ResultExternal { ...@@ -127,6 +126,7 @@ class ResultDiskBuffer implements ResultExternal {
public void done() throws SQLException { public void done() throws SQLException {
file.seek(FileStore.HEADER_LENGTH); file.seek(FileStore.HEADER_LENGTH);
file.autoDelete();
} }
public void reset() { public void reset() {
......
...@@ -84,7 +84,6 @@ public class RowList { ...@@ -84,7 +84,6 @@ public class RowList {
this.cache = db.getDataFile().getCache(); this.cache = db.getDataFile().getCache();
String fileName = db.createTempFile(); String fileName = db.createTempFile();
file = db.openFile(fileName, "rw", false); file = db.openFile(fileName, "rw", false);
file.autoDelete();
file.seek(FileStore.HEADER_LENGTH); file.seek(FileStore.HEADER_LENGTH);
rowBuff = DataPage.create(db, Constants.DEFAULT_DATA_PAGE_SIZE); rowBuff = DataPage.create(db, Constants.DEFAULT_DATA_PAGE_SIZE);
file.seek(FileStore.HEADER_LENGTH); file.seek(FileStore.HEADER_LENGTH);
...@@ -100,6 +99,7 @@ public class RowList { ...@@ -100,6 +99,7 @@ public class RowList {
writeRow(buff, r); writeRow(buff, r);
} }
flushBuffer(buff); flushBuffer(buff);
file.autoDelete();
list.clear(); list.clear();
memory = 0; memory = 0;
} }
...@@ -118,7 +118,6 @@ public class RowList { ...@@ -118,7 +118,6 @@ public class RowList {
file.write(buff.getBytes(), 0, buff.length()); file.write(buff.getBytes(), 0, buff.length());
} }
/** /**
* Add a row to the list. * Add a row to the list.
* *
...@@ -258,6 +257,7 @@ public class RowList { ...@@ -258,6 +257,7 @@ public class RowList {
*/ */
public void close() { public void close() {
if (file != null) { if (file != null) {
file.autoDelete();
file.closeAndDeleteSilently(); file.closeAndDeleteSilently();
file = null; file = null;
rowBuff = null; rowBuff = null;
......
...@@ -241,6 +241,7 @@ public class FileStore { ...@@ -241,6 +241,7 @@ public class FileStore {
public void closeAndDeleteSilently() { public void closeAndDeleteSilently() {
if (file != null) { if (file != null) {
closeSilently(); closeSilently();
TempFileDeleter.updateAutoDelete(autoDeleteReference);
TempFileDeleter.deleteFile(autoDeleteReference, name); TempFileDeleter.deleteFile(autoDeleteReference, name);
name = null; name = null;
} }
...@@ -457,7 +458,11 @@ public class FileStore { ...@@ -457,7 +458,11 @@ public class FileStore {
* Automatically delete the file once it is no longer in use. * Automatically delete the file once it is no longer in use.
*/ */
public void autoDelete() { public void autoDelete() {
autoDeleteReference = TempFileDeleter.addFile(name, this); if (autoDeleteReference == null) {
autoDeleteReference = TempFileDeleter.addFile(name, this);
} else {
TempFileDeleter.updateAutoDelete(autoDeleteReference);
}
} }
/** /**
......
...@@ -60,6 +60,22 @@ public class TempFileDeleter { ...@@ -60,6 +60,22 @@ public class TempFileDeleter {
deleteUnused(); deleteUnused();
return ref; 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. * Delete the given file now. This will remove the reference from the list.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论