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

Faster storage re-use algorithm thanks to Greg Dhuse from cleversafe.com.

上级 92114d22
...@@ -210,18 +210,6 @@ public class Storage { ...@@ -210,18 +210,6 @@ public class Storage {
file.removeRecord(session, pos, record, blockCount); file.removeRecord(session, pos, record, blockCount);
} }
private boolean isFreeAndMine(int pos, int blocks) {
synchronized (database) {
BitField used = file.getUsed();
for (int i = blocks + pos - 1; i >= pos; i--) {
if (file.getPageOwner(file.getPage(i)) != id || used.get(i)) {
return false;
}
}
return true;
}
}
private void refillFreeList() { private void refillFreeList() {
if (freeList.size() != 0 || freeCount == 0) { if (freeList.size() != 0 || freeCount == 0) {
return; return;
...@@ -254,15 +242,46 @@ public class Storage { ...@@ -254,15 +242,46 @@ public class Storage {
if (freeList.size() > 0) { if (freeList.size() > 0) {
synchronized (database) { synchronized (database) {
BitField used = file.getUsed(); BitField used = file.getUsed();
int lastPage = Integer.MIN_VALUE;
int lastBlockLow = Integer.MAX_VALUE;
int lastBlockHigh = 0;
nextEntry:
for (int i = 0; i < freeList.size(); i++) { for (int i = 0; i < freeList.size(); i++) {
int px = freeList.get(i); int px = freeList.get(i);
if (px >= lastBlockLow && px <= lastBlockHigh) {
// we have already tested this block
// and found that it's used
continue;
}
if (used.get(px)) { if (used.get(px)) {
// sometimes some entries in the freeList // sometimes some entries in the freeList
// are not free (free 2, free 1, allocate 1+2) // are not free (free 2, free 1, allocate 1+2)
// these entries are removed right here // these entries are removed right here
freeList.remove(i--); freeList.remove(i--);
} else { continue;
if (isFreeAndMine(px, blockCount)) { }
lastBlockLow = px;
lastBlockHigh = px + blockCount - 1;
while (lastBlockHigh >= lastBlockLow) {
int page = file.getPage(lastBlockHigh);
if (page != lastPage) {
if (file.getPageOwner(page) != id) {
continue nextEntry;
}
lastPage = page;
}
if (used.get(lastBlockHigh)) {
continue nextEntry;
}
--lastBlockHigh;
}
// range found
int pos = px; int pos = px;
freeList.remove(i); freeList.remove(i);
file.setUsed(pos, blockCount); file.setUsed(pos, blockCount);
...@@ -271,8 +290,6 @@ public class Storage { ...@@ -271,8 +290,6 @@ public class Storage {
} }
} }
} }
}
}
int pos = file.allocate(this, blockCount); int pos = file.allocate(this, blockCount);
file.setUsed(pos, blockCount); file.setUsed(pos, blockCount);
freeCount -= blockCount; freeCount -= blockCount;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论