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

New experimental feature SHUTDOWN DEFRAG.

上级 dc492ea5
......@@ -538,13 +538,13 @@ public class PageDataLeaf extends PageData {
p2.writeData();
p2.data.truncate(index.getPageStore().getPageSize());
store.update(p2);
store.free(getPos());
if (parentPageId == ROOT) {
index.setRootPageId(session, newPos);
} else {
PageDataNode p = (PageDataNode) store.getPage(parentPageId);
p.moveChild(getPos(), newPos);
}
store.free(getPos());
}
/**
......
......@@ -10,7 +10,6 @@ import java.lang.reflect.Array;
import org.h2.engine.Session;
import org.h2.util.CacheObject;
/**
* A page. Format:
* <ul><li>0-3: parent page id (0 for root)
......@@ -253,4 +252,13 @@ public abstract class Page extends CacheObject {
}
}
/**
* If this page can be moved. Transaction log and free-list pages can not.
*
* @return true if moving is allowed
*/
public boolean canMove() {
return true;
}
}
......@@ -222,4 +222,8 @@ public class PageFreeList extends Page {
return false;
}
public boolean canMove() {
return false;
}
}
......@@ -520,24 +520,34 @@ public class PageStore implements CacheWriter {
}
}
recordPageReads = false;
int target = MIN_PAGE_COUNT - 1;
for (int i = 0; i < recordedPagesList.size(); i++) {
writeBack();
cache.clear();
int a = MIN_PAGE_COUNT + i;
int b = recordedPagesList.get(i);
if (a == b) {
int source = recordedPagesList.get(i);
Page pageSource = getPage(source);
if (!pageSource.canMove()) {
continue;
}
while (true) {
Page pageTarget = getPage(++target);
if (pageTarget == null || pageTarget.canMove()) {
break;
}
}
if (target == source) {
continue;
}
int temp = getFirstFree();
if (temp == -1) {
DbException.throwInternalError("no free page for defrag");
}
swap(a, b, temp);
int index = recordedPagesList.indexOf(a);
cache.clear();
swap(source, target, temp);
int index = recordedPagesList.indexOf(target);
if (index >= 0) {
recordedPagesList.set(index, b);
recordedPagesList.set(index, source);
}
recordedPagesList.set(i, a);
recordedPagesList.set(i, target);
}
recordedPagesList = null;
recordedPages = null;
......@@ -606,17 +616,23 @@ public class PageStore implements CacheWriter {
Page pageA = null;
if (isUsed(a)) {
pageA = getPage(a);
pageA.moveTo(systemSession, free);
if (pageA != null) {
pageA.moveTo(systemSession, free);
}
free(a);
}
if (isUsed(b)) {
Page pageB = getPage(b);
pageB.moveTo(systemSession, a);
if (pageB != null) {
pageB.moveTo(systemSession, a);
}
free(b);
}
if (pageA != null) {
f = getPage(free);
f.moveTo(systemSession, b);
if (f != null) {
f.moveTo(systemSession, b);
}
free(free);
}
}
......
......@@ -165,4 +165,8 @@ public class PageStreamData extends Page {
return DATA_START;
}
public boolean canMove() {
return false;
}
}
\ No newline at end of file
......@@ -287,4 +287,8 @@ public class PageStreamTrunk extends Page {
return "page[" + getPos() + "] stream trunk key:" + logKey + " next:" + nextTrunk;
}
public boolean canMove() {
return false;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论