提交 46943a3d authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store: avoid writing empty pages more than once; better cache free list.

上级 72a556e8
...@@ -200,6 +200,9 @@ public class PageStore implements CacheWriter { ...@@ -200,6 +200,9 @@ public class PageStore implements CacheWriter {
// TODO reduce DEFAULT_MAX_LOG_SIZE, and don't divide here // TODO reduce DEFAULT_MAX_LOG_SIZE, and don't divide here
private long maxLogSize = Constants.DEFAULT_MAX_LOG_SIZE / 10; private long maxLogSize = Constants.DEFAULT_MAX_LOG_SIZE / 10;
private Session systemSession; private Session systemSession;
private BitField freed = new BitField();
private ObjectArray<PageFreeList> freeLists = ObjectArray.newInstance();
/** /**
* Create a new page store object. * Create a new page store object.
...@@ -335,9 +338,11 @@ public class PageStore implements CacheWriter { ...@@ -335,9 +338,11 @@ public class PageStore implements CacheWriter {
// write back the free list // write back the free list
writeBack(); writeBack();
byte[] empty = new byte[pageSize]; byte[] empty = new byte[pageSize];
// TODO avoid to write empty pages more than once
for (int i = PAGE_ID_FREE_LIST_ROOT; i < pageCount; i++) { for (int i = PAGE_ID_FREE_LIST_ROOT; i < pageCount; i++) {
if (!isUsed(i)) { if (isUsed(i)) {
freed.clear(i);
} else if (!freed.get(i)) {
freed.set(i);
file.seek((long) i << pageSizeShift); file.seek((long) i << pageSizeShift);
file.write(empty, 0, pageSize); file.write(empty, 0, pageSize);
writeCount++; writeCount++;
...@@ -391,6 +396,8 @@ public class PageStore implements CacheWriter { ...@@ -391,6 +396,8 @@ public class PageStore implements CacheWriter {
} }
} }
pageCount = lastUsed + 1; pageCount = lastUsed + 1;
// the easiest way to remove superfluous entries
freeLists.clear();
trace.debug("pageCount:" + pageCount); trace.debug("pageCount:" + pageCount);
file.setLength((long) pageCount << pageSizeShift); file.setLength((long) pageCount << pageSizeShift);
} }
...@@ -701,11 +708,17 @@ public class PageStore implements CacheWriter { ...@@ -701,11 +708,17 @@ public class PageStore implements CacheWriter {
} }
private PageFreeList getFreeList(int i) throws SQLException { private PageFreeList getFreeList(int i) throws SQLException {
PageFreeList list = null;
if (i < freeLists.size()) {
list = freeLists.get(i);
if (list != null) {
return list;
}
}
int p = PAGE_ID_FREE_LIST_ROOT + i * freeListPagesPerList; int p = PAGE_ID_FREE_LIST_ROOT + i * freeListPagesPerList;
while (p >= pageCount) { while (p >= pageCount) {
increaseFileSize(INCREMENT_PAGES); increaseFileSize(INCREMENT_PAGES);
} }
PageFreeList list = null;
if (p < pageCount) { if (p < pageCount) {
list = (PageFreeList) getPage(p); list = (PageFreeList) getPage(p);
} }
...@@ -713,6 +726,10 @@ public class PageStore implements CacheWriter { ...@@ -713,6 +726,10 @@ public class PageStore implements CacheWriter {
list = PageFreeList.create(this, p); list = PageFreeList.create(this, p);
cache.put(list); cache.put(list);
} }
while (freeLists.size() <= i) {
freeLists.add(null);
}
freeLists.set(i, list);
return list; return list;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论