提交 6e0434cd authored 作者: Thomas Mueller's avatar Thomas Mueller

Page store: improved auto-recovery after power failure.

上级 9ad55876
...@@ -119,7 +119,7 @@ public class PageStore implements CacheWriter { ...@@ -119,7 +119,7 @@ public class PageStore implements CacheWriter {
/** /**
* The smallest possible page size. * The smallest possible page size.
*/ */
public static final int PAGE_SIZE_MIN = 128; public static final int PAGE_SIZE_MIN = 64;
/** /**
* The biggest possible page size. * The biggest possible page size.
...@@ -130,6 +130,7 @@ public class PageStore implements CacheWriter { ...@@ -130,6 +130,7 @@ public class PageStore implements CacheWriter {
* The default page size. * The default page size.
*/ */
public static final int PAGE_SIZE_DEFAULT = 2 * 1024; public static final int PAGE_SIZE_DEFAULT = 2 * 1024;
// public static final int PAGE_SIZE_DEFAULT = 64;
private static final int PAGE_ID_FREE_LIST_ROOT = 3; private static final int PAGE_ID_FREE_LIST_ROOT = 3;
private static final int PAGE_ID_META_ROOT = 4; private static final int PAGE_ID_META_ROOT = 4;
...@@ -484,7 +485,7 @@ public class PageStore implements CacheWriter { ...@@ -484,7 +485,7 @@ public class PageStore implements CacheWriter {
int indexId = data.readVarInt(); int indexId = data.readVarInt();
PageDataIndex index = (PageDataIndex) metaObjects.get(indexId); PageDataIndex index = (PageDataIndex) metaObjects.get(indexId);
if (index == null) { if (index == null) {
Message.throwInternalError("index not found " + indexId); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "index not found " + indexId);
} }
p = PageDataLeaf.read(index, data, pageId); p = PageDataLeaf.read(index, data, pageId);
break; break;
...@@ -493,7 +494,7 @@ public class PageStore implements CacheWriter { ...@@ -493,7 +494,7 @@ public class PageStore implements CacheWriter {
int indexId = data.readVarInt(); int indexId = data.readVarInt();
PageDataIndex index = (PageDataIndex) metaObjects.get(indexId); PageDataIndex index = (PageDataIndex) metaObjects.get(indexId);
if (index == null) { if (index == null) {
Message.throwInternalError("index not found " + indexId); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "index not found " + indexId);
} }
p = PageDataNode.read(index, data, pageId); p = PageDataNode.read(index, data, pageId);
break; break;
...@@ -506,7 +507,7 @@ public class PageStore implements CacheWriter { ...@@ -506,7 +507,7 @@ public class PageStore implements CacheWriter {
int indexId = data.readVarInt(); int indexId = data.readVarInt();
PageBtreeIndex index = (PageBtreeIndex) metaObjects.get(indexId); PageBtreeIndex index = (PageBtreeIndex) metaObjects.get(indexId);
if (index == null) { if (index == null) {
Message.throwInternalError("index not found " + indexId); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "index not found " + indexId);
} }
p = PageBtreeLeaf.read(index, data, pageId); p = PageBtreeLeaf.read(index, data, pageId);
break; break;
...@@ -515,7 +516,7 @@ public class PageStore implements CacheWriter { ...@@ -515,7 +516,7 @@ public class PageStore implements CacheWriter {
int indexId = data.readVarInt(); int indexId = data.readVarInt();
PageBtreeIndex index = (PageBtreeIndex) metaObjects.get(indexId); PageBtreeIndex index = (PageBtreeIndex) metaObjects.get(indexId);
if (index == null) { if (index == null) {
Message.throwInternalError("index not found " + indexId); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, "index not found " + indexId);
} }
p = PageBtreeNode.read(index, data, pageId); p = PageBtreeNode.read(index, data, pageId);
break; break;
...@@ -931,10 +932,8 @@ public class PageStore implements CacheWriter { ...@@ -931,10 +932,8 @@ public class PageStore implements CacheWriter {
*/ */
void readPage(int pos, Data page) throws SQLException { void readPage(int pos, Data page) throws SQLException {
synchronized (database) { synchronized (database) {
if (pos >= pageCount) { if (pos < 0 || pos >= pageCount) {
throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, pos + " of " + pageCount); throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, pos + " of " + pageCount);
} else if (pos < 0) {
throw Message.throwInternalError("negative offset: " + pos);
} }
file.seek((long) pos << pageSizeShift); file.seek((long) pos << pageSizeShift);
file.readFully(page.getBytes(), 0, pageSize); file.readFully(page.getBytes(), 0, pageSize);
...@@ -1036,6 +1035,7 @@ public class PageStore implements CacheWriter { ...@@ -1036,6 +1035,7 @@ public class PageStore implements CacheWriter {
} }
openIndex.close(systemSession); openIndex.close(systemSession);
} }
allocatePage(PAGE_ID_META_ROOT);
recoveryRunning = false; recoveryRunning = false;
reservedPages = null; reservedPages = null;
writeIndexRowCounts(); writeIndexRowCounts();
...@@ -1548,4 +1548,16 @@ public class PageStore implements CacheWriter { ...@@ -1548,4 +1548,16 @@ public class PageStore implements CacheWriter {
return true; return true;
} }
/**
* Check if the undo entry for the given page has been written.
*
* @param pageId the page id
*/
public void checkUndo(int pageId) throws SQLException {
if (SysProperties.CHECK && !recoveryRunning) {
// ensure the undo entry is already written
// log.addUndo(pageId, null);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论