Search in sources :

Example 1 with PageChildren

use of org.h2.mvstore.Page.PageChildren in project h2database by h2database.

the class MVStore method collectReferencedChunks.

private void collectReferencedChunks(Set<Integer> targetChunkSet, int mapId, long pos, int level) {
    int c = DataUtils.getPageChunkId(pos);
    targetChunkSet.add(c);
    if (DataUtils.getPageType(pos) == DataUtils.PAGE_TYPE_LEAF) {
        return;
    }
    PageChildren refs = readPageChunkReferences(mapId, pos, -1);
    if (!refs.chunkList) {
        Set<Integer> target = new HashSet<>();
        for (int i = 0; i < refs.children.length; i++) {
            long p = refs.children[i];
            collectReferencedChunks(target, mapId, p, level + 1);
        }
        // we don't need a reference to this chunk
        target.remove(c);
        long[] children = new long[target.size()];
        int i = 0;
        for (Integer p : target) {
            children[i++] = DataUtils.getPagePos(p, 0, 0, DataUtils.PAGE_TYPE_LEAF);
        }
        refs.children = children;
        refs.chunkList = true;
        if (cacheChunkRef != null) {
            cacheChunkRef.put(refs.pos, refs, refs.getMemory());
        }
    }
    for (long p : refs.children) {
        targetChunkSet.add(DataUtils.getPageChunkId(p));
    }
}
Also used : PageChildren(org.h2.mvstore.Page.PageChildren) HashSet(java.util.HashSet)

Example 2 with PageChildren

use of org.h2.mvstore.Page.PageChildren in project h2database by h2database.

the class MVStore method readPageChunkReferences.

private PageChildren readPageChunkReferences(int mapId, long pos, int parentChunk) {
    if (DataUtils.getPageType(pos) == DataUtils.PAGE_TYPE_LEAF) {
        return null;
    }
    PageChildren r;
    if (cacheChunkRef != null) {
        r = cacheChunkRef.get(pos);
    } else {
        r = null;
    }
    if (r == null) {
        // if possible, create it from the cached page
        if (cache != null) {
            Page p = cache.get(pos);
            if (p != null) {
                r = new PageChildren(p);
            }
        }
        if (r == null) {
            // page was not cached: read the data
            Chunk c = getChunk(pos);
            long filePos = c.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, c.toString());
            }
            long maxPos = (c.block + c.len) * BLOCK_SIZE;
            r = PageChildren.read(fileStore, pos, mapId, filePos, maxPos);
        }
        r.removeDuplicateChunkReferences();
        if (cacheChunkRef != null) {
            cacheChunkRef.put(pos, r, r.getMemory());
        }
    }
    if (r.children.length == 0) {
        int chunk = DataUtils.getPageChunkId(pos);
        if (chunk == parentChunk) {
            return null;
        }
    }
    return r;
}
Also used : PageChildren(org.h2.mvstore.Page.PageChildren)

Aggregations

PageChildren (org.h2.mvstore.Page.PageChildren)2 HashSet (java.util.HashSet)1