int estimatePadBetweenBlocks(int currentBlockSize) { if (alignBlocks) { long m = (size() + currentBlockSize) % blockSize; return m > 0 ? blockSize - (int) m : 0; } return 0; }
Section(byte keyType) { idx = new IndexBuilder(keyType); firstBlockPosition = out.size(); }
Stats(ReftableWriter w, ReftableOutputStream o) { refBlockSize = w.refBlockSize; logBlockSize = w.logBlockSize; restartInterval = w.restartInterval; minUpdateIndex = w.minUpdateIndex; maxUpdateIndex = w.maxUpdateIndex; paddingUsed = o.paddingUsed(); totalBytes = o.size(); refCnt = w.refs.entryCnt; refBytes = w.refs.bytes; objCnt = w.objs != null ? w.objs.entryCnt : 0; objBytes = w.objs != null ? w.objs.bytes : 0; objIdLen = w.objIdLen; logCnt = w.logs != null ? w.logs.entryCnt : 0; logBytes = w.logs != null ? w.logs.bytes : 0; IndexBuilder refIdx = w.refs.idx; refIndexSize = refIdx.bytes; refIndexLevels = refIdx.levels; IndexBuilder objIdx = w.objs != null ? w.objs.idx : null; objIndexSize = objIdx != null ? objIdx.bytes : 0; objIndexLevels = objIdx != null ? objIdx.levels : 0; }
void padBetweenBlocksToNextBlock() throws IOException { if (alignBlocks) { long m = size() % blockSize; if (m > 0) { int pad = blockSize - (int) m; ensureBytesAvailableInBlockBuf(pad); Arrays.fill(blockBuf, 0, pad, (byte) 0); out.write(blockBuf, 0, pad); paddingUsed += pad; } } }
void finishSectionMaybeWriteIndex() throws IOException { flushCurBlock(); cur = null; if (shouldHaveIndex(idx)) { idx.writeIndex(); } bytes = out.size() - firstBlockPosition; } }
void flushCurBlock() throws IOException { idx.entries.add(new IndexEntry(cur.lastKey(), out.size())); cur.writeTo(out); }
private void writeMultiLevelIndex(List<IndexEntry> keys) throws IOException { levels = 1; while (maxIndexLevels == 0 || levels < maxIndexLevels) { keys = writeOneLevel(keys); if (keys == null) { return; } levels++; } // When maxIndexLevels has restricted the writer, write one // index block with the entire remaining set of keys. BlockWriter b = new BlockWriter( INDEX_BLOCK_TYPE, keyType, MAX_BLOCK_SIZE, Math.max(restartInterval, keys.size() / MAX_RESTARTS)); for (Entry e : keys) { b.mustAdd(e); } rootPosition = out.size(); b.writeTo(out); }
private List<IndexEntry> writeOneLevel(List<IndexEntry> keys) throws IOException { Section thisLevel = new Section(keyType); for (Entry e : keys) { thisLevel.write(e); } if (!thisLevel.idx.entries.isEmpty()) { thisLevel.flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } cur = null; return thisLevel.idx.entries; } // The current block fit entire level; make it the root. rootPosition = out.size(); cur.writeTo(out); cur = null; return null; } }
long write(BlockWriter.Entry entry) throws IOException { if (cur == null) { beginBlock(entry); } else if (!cur.tryAdd(entry)) { flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } beginBlock(entry); } entryCnt++; return out.size(); }
int estimatePadBetweenBlocks(int currentBlockSize) { if (alignBlocks) { long m = (size() + currentBlockSize) % blockSize; return m > 0 ? blockSize - (int) m : 0; } return 0; }
Section(byte keyType) { idx = new IndexBuilder(keyType); firstBlockPosition = out.size(); }
void padBetweenBlocksToNextBlock() throws IOException { if (alignBlocks) { long m = size() % blockSize; if (m > 0) { int pad = blockSize - (int) m; ensureBytesAvailableInBlockBuf(pad); Arrays.fill(blockBuf, 0, pad, (byte) 0); out.write(blockBuf, 0, pad); paddingUsed += pad; } } }
void finishSectionMaybeWriteIndex() throws IOException { flushCurBlock(); cur = null; if (shouldHaveIndex(idx)) { idx.writeIndex(); } bytes = out.size() - firstBlockPosition; } }
void flushCurBlock() throws IOException { idx.entries.add(new IndexEntry(cur.lastKey(), out.size())); cur.writeTo(out); }
private void writeMultiLevelIndex(List<IndexEntry> keys) throws IOException { levels = 1; while (maxIndexLevels == 0 || levels < maxIndexLevels) { keys = writeOneLevel(keys); if (keys == null) { return; } levels++; } // When maxIndexLevels has restricted the writer, write one // index block with the entire remaining set of keys. BlockWriter b = new BlockWriter( INDEX_BLOCK_TYPE, keyType, MAX_BLOCK_SIZE, Math.max(restartInterval, keys.size() / MAX_RESTARTS)); for (Entry e : keys) { b.mustAdd(e); } rootPosition = out.size(); b.writeTo(out); }
private List<IndexEntry> writeOneLevel(List<IndexEntry> keys) throws IOException { Section thisLevel = new Section(keyType); for (Entry e : keys) { thisLevel.write(e); } if (!thisLevel.idx.entries.isEmpty()) { thisLevel.flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } cur = null; return thisLevel.idx.entries; } // The current block fit entire level; make it the root. rootPosition = out.size(); cur.writeTo(out); cur = null; return null; } }
long write(BlockWriter.Entry entry) throws IOException { if (cur == null) { beginBlock(entry); } else if (!cur.tryAdd(entry)) { flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } beginBlock(entry); } entryCnt++; return out.size(); }