private boolean tryAdd(Entry entry, boolean tryRestart) { byte[] key = entry.key; int prefixLen = 0; boolean restart = tryRestart && nextShouldBeRestart(); if (!restart) { Entry priorEntry = entries.get(entries.size() - 1); byte[] prior = priorEntry.key; prefixLen = commonPrefix(prior, prior.length, key); if (prefixLen <= 5 /* "refs/" */ && keyType == REF_BLOCK_TYPE) { // Force restart points at transitions between namespaces // such as "refs/heads/" to "refs/tags/". restart = true; prefixLen = 0; } else if (prefixLen == 0) { restart = true; } } entry.restart = restart; entry.prefixLen = prefixLen; int entryBytes = entry.sizeBytes(); if (computeBlockBytes(entryBytes, restart) > blockLimitBytes) { return false; } entriesSumBytes += entryBytes; entries.add(entry); if (restart) { restartCnt++; } return true; }
void writeTo(ReftableOutputStream os) throws IOException { os.beginBlock(blockType); IntList restarts = new IntList(restartCnt); for (Entry entry : entries) { if (entry.restart) { restarts.add(os.bytesWrittenInBlock()); } entry.writeKey(os); entry.writeValue(os); } if (restarts.size() == 0 || restarts.size() > MAX_RESTARTS) { throw new IllegalStateException(); } for (int i = 0; i < restarts.size(); i++) { os.writeInt24(restarts.get(i)); } os.writeInt16(restarts.size()); os.flushBlock(); }
boolean tryAdd(Entry entry) { if (entry instanceof ObjEntry && computeBlockBytes(entry.sizeBytes(), 1) > blockLimitBytes) { // If the ObjEntry has so many ref block pointers that its // encoding overflows any block, reconfigure it to tell readers to // instead scan all refs for this ObjectId. That significantly // shrinks the entry to a very small size, which may now fit into // this block. ((ObjEntry) entry).markScanRequired(); } if (tryAdd(entry, true)) { return true; } else if (nextShouldBeRestart()) { // It was time for another restart, but the entry doesn't fit // with its complete key, as the block is nearly full. Try to // force it to fit with prefix compression rather than waste // the tail of the block with padding. return tryAdd(entry, false); } return false; }
void writeTo(ReftableOutputStream os) throws IOException { os.beginBlock(blockType); IntList restarts = new IntList(restartCnt); for (Entry entry : entries) { if (entry.restart) { restarts.add(os.bytesWrittenInBlock()); } entry.writeKey(os); entry.writeValue(os); } if (restarts.size() == 0 || restarts.size() > MAX_RESTARTS) { throw new IllegalStateException(); } for (int i = 0; i < restarts.size(); i++) { os.writeInt24(restarts.get(i)); } os.writeInt16(restarts.size()); os.flushBlock(); }
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException { byte blockType = entry.blockType(); int bs = out.bytesAvailableInBlock(); cur = new BlockWriter(blockType, idx.keyType, bs, restartInterval); cur.mustAdd(entry); }
void writeKey(ReftableOutputStream os) { int sfxLen = key.length - prefixLen; os.writeVarint(prefixLen); os.writeVarint(encodeSuffixAndType(sfxLen, valueType())); os.write(key, prefixLen, sfxLen); }
private BlockSizeTooSmallException blockSizeTooSmall(Entry entry) { // Compute size required to fit this entry by itself. int min = FILE_HEADER_LEN + computeBlockBytes(entry.sizeBytes(), 1); return new BlockSizeTooSmallException(min); }
private boolean tryAdd(Entry entry, boolean tryRestart) { byte[] key = entry.key; int prefixLen = 0; boolean restart = tryRestart && nextShouldBeRestart(); if (!restart) { Entry priorEntry = entries.get(entries.size() - 1); byte[] prior = priorEntry.key; prefixLen = commonPrefix(prior, prior.length, key); if (prefixLen <= 5 /* "refs/" */ && keyType == REF_BLOCK_TYPE) { // Force restart points at transitions between namespaces // such as "refs/heads/" to "refs/tags/". restart = true; prefixLen = 0; } else if (prefixLen == 0) { restart = true; } } entry.restart = restart; entry.prefixLen = prefixLen; int entryBytes = entry.sizeBytes(); if (computeBlockBytes(entryBytes, restart) > blockLimitBytes) { return false; } entriesSumBytes += entryBytes; entries.add(entry); if (restart) { restartCnt++; } return true; }
boolean tryAdd(Entry entry) { if (entry instanceof ObjEntry && computeBlockBytes(entry.sizeBytes(), 1) > blockLimitBytes) { // If the ObjEntry has so many ref block pointers that its // encoding overflows any block, reconfigure it to tell readers to // instead scan all refs for this ObjectId. That significantly // shrinks the entry to a very small size, which may now fit into // this block. ((ObjEntry) entry).markScanRequired(); } if (tryAdd(entry, true)) { return true; } else if (nextShouldBeRestart()) { // It was time for another restart, but the entry doesn't fit // with its complete key, as the block is nearly full. Try to // force it to fit with prefix compression rather than waste // the tail of the block with padding. return tryAdd(entry, false); } return false; }
void writeKey(ReftableOutputStream os) { int sfxLen = key.length - prefixLen; os.writeVarint(prefixLen); os.writeVarint(encodeSuffixAndType(sfxLen, valueType())); os.write(key, prefixLen, sfxLen); }
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException { byte blockType = entry.blockType(); int bs = out.bytesAvailableInBlock(); cur = new BlockWriter(blockType, idx.keyType, bs, restartInterval); cur.mustAdd(entry); }
private BlockSizeTooSmallException blockSizeTooSmall(Entry entry) { // Compute size required to fit this entry by itself. int min = FILE_HEADER_LEN + computeBlockBytes(entry.sizeBytes(), 1); return new BlockSizeTooSmallException(min); }