提交 086f526f authored 作者: christian.peter.io's avatar christian.peter.io

Performance improvements for "SHUTDOWN COMPACT"

上级 9a808b19
...@@ -12,6 +12,7 @@ import java.util.ArrayList; ...@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.TransactionCommand; import org.h2.command.dml.TransactionCommand;
...@@ -174,7 +175,7 @@ public class PageStore implements CacheWriter { ...@@ -174,7 +175,7 @@ public class PageStore implements CacheWriter {
private boolean recordPageReads; private boolean recordPageReads;
private ArrayList<Integer> recordedPagesList; private ArrayList<Integer> recordedPagesList;
private BitSet recordedPages; private Hashtable<Integer, Integer> recordedPagesIndex;
/** /**
* The change count is something like a "micro-transaction-id". * The change count is something like a "micro-transaction-id".
...@@ -505,7 +506,7 @@ public class PageStore implements CacheWriter { ...@@ -505,7 +506,7 @@ public class PageStore implements CacheWriter {
cache.clear(); cache.clear();
ArrayList<Table> tables = database.getAllTablesAndViews(false); ArrayList<Table> tables = database.getAllTablesAndViews(false);
recordedPagesList = New.arrayList(); recordedPagesList = New.arrayList();
recordedPages = new BitSet(); recordedPagesIndex = new Hashtable<Integer, Integer>();
recordPageReads = true; recordPageReads = true;
for (int i = 0; i < tables.size(); i++) { for (int i = 0; i < tables.size(); i++) {
Table table = tables.get(i); Table table = tables.get(i);
...@@ -543,14 +544,16 @@ public class PageStore implements CacheWriter { ...@@ -543,14 +544,16 @@ public class PageStore implements CacheWriter {
} }
cache.clear(); cache.clear();
swap(source, target, temp); swap(source, target, temp);
int index = recordedPagesList.indexOf(target); Integer index = recordedPagesIndex.get(target);
if (index >= 0) { if (index != null) {
recordedPagesList.set(index, source); recordedPagesList.set(index, source);
recordedPagesIndex.put(source, index);
} }
recordedPagesList.set(i, target); recordedPagesList.set(i, target);
recordedPagesIndex.put(target, i);
} }
recordedPagesList = null; recordedPagesList = null;
recordedPages = null; recordedPagesIndex = null;
} }
// TODO can most likely be simplified // TODO can most likely be simplified
checkpoint(); checkpoint();
...@@ -1227,9 +1230,9 @@ public class PageStore implements CacheWriter { ...@@ -1227,9 +1230,9 @@ public class PageStore implements CacheWriter {
*/ */
void readPage(int pos, Data page) { void readPage(int pos, Data page) {
if (recordPageReads) { if (recordPageReads) {
if (pos >= MIN_PAGE_COUNT && !recordedPages.get(pos)) { if (pos >= MIN_PAGE_COUNT && !recordedPagesIndex.containsKey(pos)) {
recordedPagesIndex.put(pos, recordedPagesList.size());
recordedPagesList.add(pos); recordedPagesList.add(pos);
recordedPages.set(pos);
} }
} }
synchronized (database) { synchronized (database) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论