/** * Only keep one reference to the same chunk. Only leaf references are * removed (references to inner nodes are not removed, as they could * indirectly point to other chunks). */ void removeDuplicateChunkReferences() { HashSet<Integer> chunks = new HashSet<>(); // we don't need references to leaves in the same chunk chunks.add(DataUtils.getPageChunkId(pos)); for (int i = 0; i < children.length; i++) { long p = children[i]; int chunkId = DataUtils.getPageChunkId(p); boolean wasNew = chunks.add(chunkId); if (DataUtils.getPageType(p) == DataUtils.PAGE_TYPE_NODE) { continue; } if (wasNew) { continue; } removeChild(i--); } }
@Override public String toString() { StringBuilder buff = new StringBuilder(); buff.append("id: ").append(System.identityHashCode(this)).append('\n'); buff.append("version: ").append(Long.toHexString(version)).append('\n'); buff.append("pos: ").append(Long.toHexString(pos)).append('\n'); if (pos != 0) { int chunkId = DataUtils.getPageChunkId(pos); buff.append("chunk: ").append(Long.toHexString(chunkId)).append('\n'); } for (int i = 0; i <= keys.length; i++) { if (i > 0) { buff.append(" "); } if (children != null) { buff.append('[').append(Long.toHexString(children[i].pos)).append("] "); } if (i < keys.length) { buff.append(keys[i]); if (values != null) { buff.append(':'); buff.append(values[i]); } } } return buff.toString(); }
/** * Get the chunk for the given position. * * @param pos the position * @return the chunk */ private Chunk getChunk(long pos) { Chunk c = getChunkIfFound(pos); if (c == null) { int chunkId = DataUtils.getPageChunkId(pos); throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} not found", chunkId); } return c; }
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) { targetChunkSet.add(DataUtils.getPageChunkId(p));
private Chunk getChunkIfFound(long pos) { int chunkId = DataUtils.getPageChunkId(pos); Chunk c = chunks.get(chunkId); if (c == null) { checkOpen(); if (!Thread.holdsLock(this)) { // it could also be unsynchronized metadata // access (if synchronization on this was forgotten) throw DataUtils.newIllegalStateException( DataUtils.ERROR_CHUNK_NOT_FOUND, "Chunk {0} no longer exists", chunkId); } String s = meta.get(Chunk.getMetaKey(chunkId)); if (s == null) { return null; } c = Chunk.fromString(s); if (c.block == Long.MAX_VALUE) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} is invalid", chunkId); } chunks.put(c.id, c); } return c; }
counts[i], keys[i], DataUtils.getPageChunkId(cp), DataUtils.getPageOffset(cp)); counts[entries], keys.length >= entries ? null : keys[entries], DataUtils.getPageChunkId(cp), DataUtils.getPageOffset(cp)); } else { len + "x%n", counts[i], DataUtils.getPageChunkId(cp), DataUtils.getPageOffset(cp));
Page p = new Page(map, 0); p.pos = pos; int chunkId = DataUtils.getPageChunkId(pos); int offset = DataUtils.getPageOffset(pos); p.read(buff, chunkId, offset, maxLength);
int chunkId = DataUtils.getPageChunkId(pos); int offset = DataUtils.getPageOffset(pos); int start = buff.position();
private int rewrite(Page p, Set<Integer> set) { if (p.isLeaf()) { long pos = p.getPos(); int chunkId = DataUtils.getPageChunkId(pos); if (!set.contains(chunkId)) { return 0; int chunkId = DataUtils.getPageChunkId(childPos); if (!set.contains(chunkId)) { continue; int chunkId = DataUtils.getPageChunkId(pos); if (set.contains(chunkId)) {
int chunk = DataUtils.getPageChunkId(pos); if (chunk == parentChunk) { return null;
/** * Collect the set of chunks referenced directly by this page. * * @param target the target set */ void collectReferencedChunks(Set<Integer> target) { target.add(DataUtils.getPageChunkId(pos)); for (long p : children) { target.add(DataUtils.getPageChunkId(p)); } }
/** * Collect the set of chunks referenced directly by this page. * * @param target the target set */ void collectReferencedChunks(Set<Integer> target) { target.add(DataUtils.getPageChunkId(pos)); for (long p : children) { target.add(DataUtils.getPageChunkId(p)); } }
/** * Only keep one reference to the same chunk. Only leaf references are * removed (references to inner nodes are not removed, as they could * indirectly point to other chunks). */ void removeDuplicateChunkReferences() { HashSet<Integer> chunks = new HashSet<>(); // we don't need references to leaves in the same chunk chunks.add(DataUtils.getPageChunkId(pos)); for (int i = 0; i < children.length; i++) { long p = children[i]; int chunkId = DataUtils.getPageChunkId(p); boolean wasNew = chunks.add(chunkId); if (DataUtils.getPageType(p) == DataUtils.PAGE_TYPE_NODE) { continue; } if (wasNew) { continue; } removeChild(i--); } }
@Override public String toString() { StringBuilder buff = new StringBuilder(); buff.append("id: ").append(System.identityHashCode(this)).append('\n'); buff.append("version: ").append(Long.toHexString(version)).append("\n"); buff.append("pos: ").append(Long.toHexString(pos)).append("\n"); if (pos != 0) { int chunkId = DataUtils.getPageChunkId(pos); buff.append("chunk: ").append(Long.toHexString(chunkId)).append("\n"); } for (int i = 0; i <= keys.length; i++) { if (i > 0) { buff.append(" "); } if (children != null) { buff.append("[" + Long.toHexString(children[i].pos) + "] "); } if (i < keys.length) { buff.append(keys[i]); if (values != null) { buff.append(':'); buff.append(values[i]); } } } return buff.toString(); }
/** * Only keep one reference to the same chunk. Only leaf references are * removed (references to inner nodes are not removed, as they could * indirectly point to other chunks). */ void removeDuplicateChunkReferences() { HashSet<Integer> chunks = New.hashSet(); // we don't need references to leaves in the same chunk chunks.add(DataUtils.getPageChunkId(pos)); for (int i = 0; i < children.length; i++) { long p = children[i]; int chunkId = DataUtils.getPageChunkId(p); boolean wasNew = chunks.add(chunkId); if (DataUtils.getPageType(p) == DataUtils.PAGE_TYPE_NODE) { continue; } if (wasNew) { continue; } removeChild(i--); } }
/** * Only keep one reference to the same chunk. Only leaf references are * removed (references to inner nodes are not removed, as they could * indirectly point to other chunks). */ void removeDuplicateChunkReferences() { HashSet<Integer> chunks = New.hashSet(); // we don't need references to leaves in the same chunk chunks.add(DataUtils.getPageChunkId(pos)); for (int i = 0; i < children.length; i++) { long p = children[i]; int chunkId = DataUtils.getPageChunkId(p); boolean wasNew = chunks.add(chunkId); if (DataUtils.getPageType(p) == DataUtils.PAGE_TYPE_NODE) { continue; } if (wasNew) { continue; } removeChild(i--); } }
/** * Get the chunk for the given position. * * @param pos the position * @return the chunk */ private Chunk getChunk(long pos) { Chunk c = getChunkIfFound(pos); if (c == null) { int chunkId = DataUtils.getPageChunkId(pos); throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} not found", chunkId); } return c; }
/** * Get the chunk for the given position. * * @param pos the position * @return the chunk */ private Chunk getChunk(long pos) { Chunk c = getChunkIfFound(pos); if (c == null) { int chunkId = DataUtils.getPageChunkId(pos); throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} not found", chunkId); } return c; }
/** * Get the chunk for the given position. * * @param pos the position * @return the chunk */ private Chunk getChunk(long pos) { Chunk c = getChunkIfFound(pos); if (c == null) { int chunkId = DataUtils.getPageChunkId(pos); throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} not found", chunkId); } return c; }
private Chunk getChunkIfFound(long pos) { int chunkId = DataUtils.getPageChunkId(pos); Chunk c = chunks.get(chunkId); if (c == null) { checkOpen(); if (!Thread.holdsLock(this)) { // it could also be unsynchronized metadata // access (if synchronization on this was forgotten) throw DataUtils.newIllegalStateException( DataUtils.ERROR_CHUNK_NOT_FOUND, "Chunk {0} no longer exists", chunkId); } String s = meta.get(Chunk.getMetaKey(chunkId)); if (s == null) { return null; } c = Chunk.fromString(s); if (c.block == Long.MAX_VALUE) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_FILE_CORRUPT, "Chunk {0} is invalid", chunkId); } chunks.put(c.id, c); } return c; }