@Override protected void onPackFooter(byte[] hash) throws IOException { // TODO Combine together fractional chunks to reduce overhead. // Fractional chunks are common for single-commit pushes since // they are broken out by object type. // TODO Try to combine the chunk data and its index into a single // put call for the last chunk of each type. This would break the // read back we do in seekDatabase during delta resolution. // If there are deltas to be resolved the pending chunks // will need to be reloaded later. Ensure they are stored. // endChunk(OBJ_COMMIT); endChunk(OBJ_TREE); endChunk(OBJ_BLOB); endChunk(OBJ_TAG); // These are only necessary during initial parsing. Drop them now. // objStreamPos = null; objChunkPtrs = null; }
@Override protected void onPackFooter(byte[] hash) throws IOException { // TODO Combine together fractional chunks to reduce overhead. // Fractional chunks are common for single-commit pushes since // they are broken out by object type. // TODO Try to combine the chunk data and its index into a single // put call for the last chunk of each type. This would break the // read back we do in seekDatabase during delta resolution. // If there are deltas to be resolved the pending chunks // will need to be reloaded later. Ensure they are stored. // endChunk(OBJ_COMMIT); endChunk(OBJ_TREE); endChunk(OBJ_BLOB); endChunk(OBJ_TAG); // These are only necessary during initial parsing. Drop them now. // objStreamPos = null; objChunkPtrs = null; }
private void appendToFragment(byte[] raw, int pos, int len) throws DhtException { while (0 < len) { if (currChunk.free() == 0) { int typeCode = typeOf(currChunkPtr); currChunk.setFragment(); currFragments.add(endChunk(typeCode)); currChunk = openChunk(typeCode); } int n = Math.min(len, currChunk.free()); currChunk.append(raw, pos, n); currPackedSize += n; pos += n; len -= n; } }
private void appendToFragment(byte[] raw, int pos, int len) throws DhtException { while (0 < len) { if (currChunk.free() == 0) { int typeCode = typeOf(currChunkPtr); currChunk.setFragment(); currFragments.add(endChunk(typeCode)); currChunk = openChunk(typeCode); } int n = Math.min(len, currChunk.free()); currChunk.append(raw, pos, n); currPackedSize += n; pos += n; len -= n; } }
private void endFragmentedObject() throws DhtException { currChunk.setFragment(); ChunkKey lastKey = endChunk(typeOf(currChunkPtr)); if (lastKey != null) currFragments.add(lastKey); ChunkMeta.Builder protoBuilder = ChunkMeta.newBuilder(); for (ChunkKey key : currFragments) protoBuilder.addFragment(key.asString()); ChunkMeta protoMeta = protoBuilder.build(); for (ChunkKey key : currFragments) { ChunkMeta oldMeta = chunkMeta.get(key); if (oldMeta != null) { ChunkMeta.Builder newMeta = ChunkMeta.newBuilder(oldMeta); newMeta.clearFragment(); newMeta.mergeFrom(protoMeta); ChunkMeta meta = newMeta.build(); dirtyMeta.put(key, meta); chunkMeta.put(key, meta); } else { dirtyMeta.put(key, protoMeta); chunkMeta.put(key, protoMeta); } } currFragments = null; }
private void endFragmentedObject() throws DhtException { currChunk.setFragment(); ChunkKey lastKey = endChunk(typeOf(currChunkPtr)); if (lastKey != null) currFragments.add(lastKey); ChunkMeta.Builder protoBuilder = ChunkMeta.newBuilder(); for (ChunkKey key : currFragments) protoBuilder.addFragment(key.asString()); ChunkMeta protoMeta = protoBuilder.build(); for (ChunkKey key : currFragments) { ChunkMeta oldMeta = chunkMeta.get(key); if (oldMeta != null) { ChunkMeta.Builder newMeta = ChunkMeta.newBuilder(oldMeta); newMeta.clearFragment(); newMeta.mergeFrom(protoMeta); ChunkMeta meta = newMeta.build(); dirtyMeta.put(key, meta); chunkMeta.put(key, meta); } else { dirtyMeta.put(key, protoMeta); chunkMeta.put(key, protoMeta); } } currFragments = null; }
@Override protected void onBeginWholeObject(long streamPosition, int type, long inflatedSize) throws IOException { ChunkFormatter w = begin(type); if (!w.whole(type, inflatedSize)) { endChunk(type); w = begin(type); if (!w.whole(type, inflatedSize)) throw panicCannotInsert(); } currType = type; currDataPos = w.position(); currPackedSize = 0; currInflatedSize = inflatedSize; objStreamPos.add(streamPosition); }
@Override protected void onBeginWholeObject(long streamPosition, int type, long inflatedSize) throws IOException { ChunkFormatter w = begin(type); if (!w.whole(type, inflatedSize)) { endChunk(type); w = begin(type); if (!w.whole(type, inflatedSize)) throw panicCannotInsert(); } currType = type; currDataPos = w.position(); currPackedSize = 0; currInflatedSize = inflatedSize; objStreamPos.add(streamPosition); }
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }
@Override protected void onBeginRefDelta(long deltaPos, AnyObjectId baseId, long inflatedSize) throws IOException { // Try to get the base type, but only if it was seen before in this // pack stream. If not assume worst-case of BLOB type. // int typeCode; DhtInfo baseInfo = objectMap.get(baseId); if (baseInfo != null && baseInfo.isInPack()) { typeCode = baseInfo.getType(); currType = typeCode; } else { typeCode = OBJ_BLOB; currType = -1; } ChunkFormatter w = begin(typeCode); if (!w.refDelta(inflatedSize, baseId)) { endChunk(typeCode); w = begin(typeCode); if (!w.refDelta(inflatedSize, baseId)) throw panicCannotInsert(); } currDataPos = w.position(); currPackedSize = 0; currInflatedSize = inflatedSize; objStreamPos.add(deltaPos); }
@Override protected void onBeginRefDelta(long deltaPos, AnyObjectId baseId, long inflatedSize) throws IOException { // Try to get the base type, but only if it was seen before in this // pack stream. If not assume worst-case of BLOB type. // int typeCode; DhtInfo baseInfo = objectMap.get(baseId); if (baseInfo != null && baseInfo.isInPack()) { typeCode = baseInfo.getType(); currType = typeCode; } else { typeCode = OBJ_BLOB; currType = -1; } ChunkFormatter w = begin(typeCode); if (!w.refDelta(inflatedSize, baseId)) { endChunk(typeCode); w = begin(typeCode); if (!w.refDelta(inflatedSize, baseId)) throw panicCannotInsert(); } currDataPos = w.position(); currPackedSize = 0; currInflatedSize = inflatedSize; objStreamPos.add(deltaPos); }