提交 530549d2 authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store bugfixes

上级 06214924
...@@ -33,7 +33,7 @@ import org.h2.store.PageStore; ...@@ -33,7 +33,7 @@ import org.h2.store.PageStore;
* </ul> * </ul>
*/ */
public class PageDataLeaf extends PageData { public class PageDataLeaf extends PageData {
/** /**
* The start of the data in the last overflow page. * The start of the data in the last overflow page.
*/ */
...@@ -222,11 +222,6 @@ public class PageDataLeaf extends PageData { ...@@ -222,11 +222,6 @@ public class PageDataLeaf extends PageData {
all.checkCapacity(data.length()); all.checkCapacity(data.length());
all.write(data.getBytes(), 0, data.length()); all.write(data.getBytes(), 0, data.length());
data.truncate(index.getPageStore().getPageSize()); data.truncate(index.getPageStore().getPageSize());
// write the page now to disk, to avoid problems
// when the page needs to be written before the overflow
// is written to disk (the cache first removes elements,
// moves them in a write queue, and then writes them)
write(null);
do { do {
int type, size, next; int type, size, next;
if (remaining <= pageSize - PageDataOverflow.START_LAST) { if (remaining <= pageSize - PageDataOverflow.START_LAST) {
...@@ -507,19 +502,5 @@ public class PageDataLeaf extends PageData { ...@@ -507,19 +502,5 @@ public class PageDataLeaf extends PageData {
public int getMemorySize() { public int getMemorySize() {
return index.getMemorySizePerPage(); return index.getMemorySizePerPage();
} }
void setParentPageId(int id) {
// never reset the written flag not only for speed, but also
// because if would cause the page to be written again if
// it contains overflow, which would cause the data to be read,
// and that's not possible because the overflow page may be
// not in the cache but in the write queue already
if (written) {
data.setInt(START_PARENT, id);
this.parentPageId = id;
} else {
super.setParentPageId(id);
}
}
} }
...@@ -110,6 +110,7 @@ public class PageDataOverflow extends Page { ...@@ -110,6 +110,7 @@ public class PageDataOverflow extends Page {
Data data = store.createData(); Data data = store.createData();
PageDataOverflow p = new PageDataOverflow(store, page, data); PageDataOverflow p = new PageDataOverflow(store, page, data);
data.writeByte((byte) type); data.writeByte((byte) type);
data.writeShortInt(0);
data.writeInt(parentPageId); data.writeInt(parentPageId);
if (type == Page.TYPE_DATA_OVERFLOW) { if (type == Page.TYPE_DATA_OVERFLOW) {
data.writeInt(next); data.writeInt(next);
......
...@@ -126,8 +126,11 @@ public class CacheLRU implements Cache { ...@@ -126,8 +126,11 @@ public class CacheLRU implements Cache {
private void removeOld() throws SQLException { private void removeOld() throws SQLException {
int i = 0; int i = 0;
int todoImplementInOtherCachesAsWell;
ObjectArray<CacheObject> changed = ObjectArray.newInstance(); ObjectArray<CacheObject> changed = ObjectArray.newInstance();
while (sizeMemory * 4 > maxSize * 3 && recordCount > Constants.CACHE_MIN_RECORDS) { int mem = sizeMemory;
int rc = recordCount;
while (mem * 4 > maxSize * 3 && rc > Constants.CACHE_MIN_RECORDS) {
i++; i++;
if (i == recordCount) { if (i == recordCount) {
writer.flushLog(); writer.flushLog();
...@@ -151,10 +154,13 @@ public class CacheLRU implements Cache { ...@@ -151,10 +154,13 @@ public class CacheLRU implements Cache {
addToFront(last); addToFront(last);
continue; continue;
} }
remove(last.getPos());
if (last.isChanged()) { if (last.isChanged()) {
changed.add(last); changed.add(last);
} else {
remove(last.getPos());
} }
rc--;
mem -= last.getMemorySize();
} }
if (changed.size() > 0) { if (changed.size() > 0) {
CacheObject.sort(changed); CacheObject.sort(changed);
...@@ -162,6 +168,10 @@ public class CacheLRU implements Cache { ...@@ -162,6 +168,10 @@ public class CacheLRU implements Cache {
CacheObject rec = changed.get(i); CacheObject rec = changed.get(i);
writer.writeBack(rec); writer.writeBack(rec);
} }
for (i = 0; i < changed.size(); i++) {
CacheObject rec = changed.get(i);
remove(rec.getPos());
}
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论