@Override public PackParser newPackParser(InputStream in) throws IOException { return new DhtPackParser(objdb, in); }
@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(); }
private ChunkKey chunkOf(long objectPtr) throws DhtException { List<ChunkKey> list = chunkByOrder[typeOf(objectPtr)]; int idx = chunkIdx(objectPtr); if (list == null || list.size() <= idx) { throw new DhtException(MessageFormat.format( DhtText.get().packParserInvalidPointer, // Constants.typeString(typeOf(objectPtr)), // Integer.valueOf(idx), // Integer.valueOf(offsetOf(objectPtr)))); } return list.get(idx); }
treeParser = null; final int objCnt = getObjectCount(); if (objCnt == 0) { createObjectLists(); if (isSaveAsCachedPack()) putCachedPack(); computeChunkEdges(); putChunkIndexes(); putDirtyMeta(); dbWriteBuffer.flush(); putGlobalIndex(resolving); dbWriteBuffer.flush(); rollback();
currFragments = new LinkedList<ChunkKey>(); if (currFragments != null) { appendToFragment(raw, pos, len); return; final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType(); endChunk(type); final ChunkFormatter w = begin(type); switch (typeOld) { case OBJ_COMMIT: w.adjustObjectCount(1, typeOld); if (!w.append(dataOld, hdrPos, hdrLen)) throw panicCannotInsert(); break; if (!longOfsDelta(w, currInflatedSize, currBasePtr)) throw panicCannotInsert(); break; throw panicCannotInsert(); dataOld = 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); }
private void putChunkIndexes() throws DhtException { List<DhtInfo> objs = objectListByChunk; int sIdx = 0; DhtInfo oe = objs.get(0); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey key = chunkOf(oe.chunkPtr); int type = typeOf(oe.chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { oe = objs.get(objIdx); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { putChunkIndex(objs.subList(sIdx, objIdx), key, type); sIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } putChunkIndex(objs.subList(sIdx, objs.size()), key, type); }
private Edges edges(long chunkPtr) throws DhtException { if (isInCurrentChunk(chunkPtr)) { int type = typeOf(chunkPtr); Edges s = openEdges[type]; if (s == null) { s = new Edges(); openEdges[type] = s; } return s; } else { ChunkKey key = chunkOf(chunkPtr); Edges s = chunkEdges.get(key); if (s == null) { s = new Edges(); chunkEdges.put(key, s); } return s; } }
private void computeChunkEdges() throws DhtException { List<DhtInfo> objs = objectListByChunk; int beginIdx = 0; ChunkKey key = chunkOf(objs.get(0).chunkPtr); int type = typeOf(objs.get(0).chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { DhtInfo oe = objs.get(objIdx); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { computeEdges(objs.subList(beginIdx, objIdx), key, type); beginIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } computeEdges(objs.subList(beginIdx, objs.size()), key, type); }
private List<ChunkKey> toChunkList(Set<DhtInfo> objects) throws DhtException { if (objects == null || objects.isEmpty()) return null; Map<ChunkKey, ChunkOrderingEntry> map = new HashMap<ChunkKey, ChunkOrderingEntry>(); for (DhtInfo obj : objects) { if (!obj.isInPack()) continue; long chunkPtr = obj.chunkPtr; ChunkKey key = chunkOf(chunkPtr); ChunkOrderingEntry e = map.get(key); if (e == null) { e = new ChunkOrderingEntry(); e.key = key; e.order = chunkIdx(chunkPtr); map.put(key, e); } else { e.order = Math.min(e.order, chunkIdx(chunkPtr)); } } ChunkOrderingEntry[] tmp = map.values().toArray( new ChunkOrderingEntry[map.size()]); Arrays.sort(tmp); ChunkKey[] out = new ChunkKey[tmp.length]; for (int i = 0; i < tmp.length; i++) out[i] = tmp[i].key; return Arrays.asList(out); }
chunkOf(oe.chunkPtr), // dbWriteBuffer); cnt++; deleteChunks(chunkByOrder[OBJ_COMMIT]); deleteChunks(chunkByOrder[OBJ_TREE]); deleteChunks(chunkByOrder[OBJ_BLOB]); deleteChunks(chunkByOrder[OBJ_TAG]);
addChunkList(info, version, chunkByOrder[OBJ_TAG]); addChunkList(info, version, chunkByOrder[OBJ_COMMIT]); addChunkList(info, version, chunkByOrder[OBJ_TREE]); addChunkList(info, version, chunkByOrder[OBJ_BLOB]); info.setName(computePackName().name()); info.setVersion(ObjectId.fromRaw(version.digest()).name());
linkIterators = newListIteratorArray(segments); oe.info(chunkOf(oe.chunkPtr)), // dbWriteBuffer); cnt++;
treeParser = null; final int objCnt = getObjectCount(); if (objCnt == 0) { createObjectLists(); if (isSaveAsCachedPack()) putCachedPack(); computeChunkEdges(); putChunkIndexes(); putDirtyMeta(); dbWriteBuffer.flush(); putGlobalIndex(resolving); dbWriteBuffer.flush(); rollback();
currFragments = new LinkedList<ChunkKey>(); if (currFragments != null) { appendToFragment(raw, pos, len); return; final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType(); endChunk(type); final ChunkFormatter w = begin(type); switch (typeOld) { case OBJ_COMMIT: w.adjustObjectCount(1, typeOld); if (!w.append(dataOld, hdrPos, hdrLen)) throw panicCannotInsert(); break; if (!longOfsDelta(w, currInflatedSize, currBasePtr)) throw panicCannotInsert(); break; throw panicCannotInsert(); dataOld = 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); }
private void putChunkIndexes() throws DhtException { List<DhtInfo> objs = objectListByChunk; int sIdx = 0; DhtInfo oe = objs.get(0); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey key = chunkOf(oe.chunkPtr); int type = typeOf(oe.chunkPtr); int objIdx = 1; for (; objIdx < objs.size(); objIdx++) { oe = objs.get(objIdx); oe.setOffset(offsetOf(oe.chunkPtr)); ChunkKey oeKey = chunkOf(oe.chunkPtr); if (!key.equals(oeKey)) { putChunkIndex(objs.subList(sIdx, objIdx), key, type); sIdx = objIdx; key = oeKey; type = typeOf(oe.chunkPtr); } if (type != OBJ_MIXED && type != typeOf(oe.chunkPtr)) type = OBJ_MIXED; } putChunkIndex(objs.subList(sIdx, objs.size()), key, type); }