提交 aab03e23 authored 作者: Thomas Mueller's avatar Thomas Mueller

After a crash, the database file did not always shrink because old transaction…

After a crash, the database file did not always shrink because old transaction log pages were not removed from the file.
上级 e30c2323
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Various CallableStatement methods could throw a NullPointerException. <ul><li>After a crash, the database file did not always shrink because
old transaction log pages were not removed from the file.
</li><li>Various CallableStatement methods could throw a NullPointerException.
</li><li>LOB files were not deleted when running DROP ALL OBJECTS. </li><li>LOB files were not deleted when running DROP ALL OBJECTS.
</li><li>MS SQL Server compatibility: support "N" in front of string literals ("National Language" strings). Issue 240. </li><li>MS SQL Server compatibility: support "N" in front of string literals ("National Language" strings). Issue 240.
</li><li>CAST: when converting a string to binary, it is hex encoded (every byte two characters); </li><li>CAST: when converting a string to binary, it is hex encoded (every byte two characters);
......
...@@ -850,4 +850,15 @@ public class PageLog { ...@@ -850,4 +850,15 @@ public class PageLog {
return store.createData(); return store.createData();
} }
/**
* Get the smallest possible page id used. This is the trunk page if only
* appending at the end of the file, or 0.
*
* @return the smallest possible page.
*/
int getMinPageId() {
return pageOut == null ? 0 : pageOut.getMinPageId();
}
} }
...@@ -18,9 +18,11 @@ public class PageOutputStream { ...@@ -18,9 +18,11 @@ public class PageOutputStream {
private PageStore store; private PageStore store;
private final Trace trace; private final Trace trace;
private int trunkPageId;
private final BitField exclude; private final BitField exclude;
private final boolean atEnd;
private final int minPageId;
private int trunkPageId;
private int trunkNext; private int trunkNext;
private IntArray reservedPages = new IntArray(); private IntArray reservedPages = new IntArray();
private PageStreamTrunk trunk; private PageStreamTrunk trunk;
...@@ -31,7 +33,6 @@ public class PageOutputStream { ...@@ -31,7 +33,6 @@ public class PageOutputStream {
private boolean needFlush; private boolean needFlush;
private boolean writing; private boolean writing;
private int pageCount; private int pageCount;
private boolean atEnd;
private int logKey; private int logKey;
/** /**
...@@ -51,6 +52,7 @@ public class PageOutputStream { ...@@ -51,6 +52,7 @@ public class PageOutputStream {
// minus one, because we increment before creating a trunk page // minus one, because we increment before creating a trunk page
this.logKey = logKey - 1; this.logKey = logKey - 1;
this.atEnd = atEnd; this.atEnd = atEnd;
minPageId = atEnd ? trunkPage : 0;
} }
/** /**
...@@ -209,4 +211,14 @@ public class PageOutputStream { ...@@ -209,4 +211,14 @@ public class PageOutputStream {
} }
} }
/**
* Get the smallest possible page id used. This is the trunk page if only
* appending at the end of the file, or 0.
*
* @return the smallest possible page.
*/
int getMinPageId() {
return minPageId;
}
} }
...@@ -665,15 +665,21 @@ public class PageStore implements CacheWriter { ...@@ -665,15 +665,21 @@ public class PageStore implements CacheWriter {
DbException.throwInternalError("not free: " + f); DbException.throwInternalError("not free: " + f);
} }
Page p = getPage(full); Page p = getPage(full);
if (p != null) { if (p == null) {
freePage(full);
} else if (p instanceof PageStreamData || p instanceof PageStreamTrunk) {
if (p.getPos() < log.getMinPageId()) {
// an old transaction log page
// probably a leftover from a crash
freePage(full);
}
} else {
trace.debug("move " + p.getPos() + " to " + free); trace.debug("move " + p.getPos() + " to " + free);
try { try {
p.moveTo(systemSession, free); p.moveTo(systemSession, free);
} finally { } finally {
changeCount++; changeCount++;
} }
} else {
freePage(full);
} }
return true; return true;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论