提交 9069ba5c authored 作者: Noel Grandin's avatar Noel Grandin

flatten methods

上级 5a2ea19a
...@@ -1413,22 +1413,23 @@ public class MVStore { ...@@ -1413,22 +1413,23 @@ public class MVStore {
registerChunk(DataUtils.getPageChunkId(pos)); registerChunk(DataUtils.getPageChunkId(pos));
} }
int count = page.map.getChildPageCount(page); int count = page.map.getChildPageCount(page);
if (count > 0) { if (count == 0) {
ChunkIdsCollector childCollector = getChild(); return;
for (int i = 0; i < count; i++) { }
Page childPage = page.getChildPageIfLoaded(i); ChunkIdsCollector childCollector = getChild();
if (childPage != null) { for (int i = 0; i < count; i++) {
childCollector.visit(childPage); Page childPage = page.getChildPageIfLoaded(i);
} else { if (childPage != null) {
childCollector.visit(page.getChildPagePos(i)); childCollector.visit(childPage);
} } else {
} childCollector.visit(page.getChildPagePos(i));
// and cache resulting set of chunk ids
if (DataUtils.isPageSaved(pos) && cacheChunkRef != null) {
int[] chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
} }
} }
// and cache resulting set of chunk ids
if (DataUtils.isPageSaved(pos) && cacheChunkRef != null) {
int[] chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
}
} }
public void visit(long pos) { public void visit(long pos) {
...@@ -1436,37 +1437,38 @@ public class MVStore { ...@@ -1436,37 +1437,38 @@ public class MVStore {
return; return;
} }
registerChunk(DataUtils.getPageChunkId(pos)); registerChunk(DataUtils.getPageChunkId(pos));
if (DataUtils.getPageType(pos) != DataUtils.PAGE_TYPE_LEAF) { if (DataUtils.getPageType(pos) == DataUtils.PAGE_TYPE_LEAF) {
int chunkIds[]; return;
if (cacheChunkRef != null && (chunkIds = cacheChunkRef.get(pos)) != null) { }
// there is a cached set of chunk ids for this position int chunkIds[];
for (int chunkId : chunkIds) { if (cacheChunkRef != null && (chunkIds = cacheChunkRef.get(pos)) != null) {
registerChunk(chunkId); // there is a cached set of chunk ids for this position
} for (int chunkId : chunkIds) {
registerChunk(chunkId);
}
} else {
ChunkIdsCollector childCollector = getChild();
Page page;
if (cache != null && (page = cache.get(pos)) != null) {
// there is a full page in cache, use it
childCollector.visit(page);
} else { } else {
ChunkIdsCollector childCollector = getChild(); // page was not cached: read the data
Page page; Chunk chunk = getChunk(pos);
if (cache != null && (page = cache.get(pos)) != null) { long filePos = chunk.block * BLOCK_SIZE;
// there is a full page in cache, use it filePos += DataUtils.getPageOffset(pos);
childCollector.visit(page); if (filePos < 0) {
} else { throw DataUtils.newIllegalStateException(
// page was not cached: read the data DataUtils.ERROR_FILE_CORRUPT,
Chunk chunk = getChunk(pos); "Negative position {0}; p={1}, c={2}", filePos, pos, chunk.toString());
long filePos = chunk.block * BLOCK_SIZE;
filePos += DataUtils.getPageOffset(pos);
if (filePos < 0) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_FILE_CORRUPT,
"Negative position {0}; p={1}, c={2}", filePos, pos, chunk.toString());
}
long maxPos = (chunk.block + chunk.len) * BLOCK_SIZE;
Page.readChildrenPositions(fileStore, pos, filePos, maxPos, childCollector);
}
// and cache resulting set of chunk ids
if (cacheChunkRef != null) {
chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
} }
long maxPos = (chunk.block + chunk.len) * BLOCK_SIZE;
Page.readChildrenPositions(fileStore, pos, filePos, maxPos, childCollector);
}
// and cache resulting set of chunk ids
if (cacheChunkRef != null) {
chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论