private ChunkFormatter openChunk(int typeCode) throws DhtException { if (typeCode == 0) throw new DhtException("Invalid internal typeCode 0"); ChunkFormatter w = openChunks[typeCode]; if (w == null) { w = new ChunkFormatter(repo, options); w.setSource(GitStore.ChunkInfo.Source.RECEIVE); w.setObjectType(typeCode); openChunks[typeCode] = w; } return w; }
void rollback() { ptr = mark; adjustObjectCount(-1, currentObjectType); }
boolean ofsDelta(long inflatedSize, long negativeOffset) { final int ofsPtr = encodeVarInt(negativeOffset); final int ofsLen = varIntBuf.length - ofsPtr; if (free() < 10 + ofsLen || maxObjects <= objectsTotal) return false; header(Constants.OBJ_OFS_DELTA, inflatedSize); objectsOfsDelta++; currentObjectType = Constants.OBJ_OFS_DELTA; currentObjectBase = null; if (append(varIntBuf, ofsPtr, ofsLen)) return true; rollback(); return false; }
private ChunkFormatter newChunk() { ChunkFormatter fmt; fmt = new ChunkFormatter(repo, options); fmt.setSource(GitStore.ChunkInfo.Source.INSERT); return fmt; }
int position = chunk.position(); if (!chunk.whole(type, inflatedSize)) throw new DhtException(DhtText.get().cannotInsertObject); if (chunk.free() == 0) { packedSize += chunk.size(); chunk.setObjectType(type); chunk.setFragment(); fragmentList.add(chunk.end(chunkDigest)); chunk.safePut(db, dbBuffer()); chunk = newChunk(); chunk.appendDeflateOutput(def); if (chunk.free() == 0) { packedSize += chunk.size(); chunk.setObjectType(type); chunk.setFragment(); fragmentList.add(chunk.end(chunkDigest)); chunk.safePut(db, dbBuffer()); chunk = newChunk(); chunk.appendDeflateOutput(def); if (!chunk.isEmpty()) { packedSize += chunk.size(); chunk.setObjectType(type); ChunkKey key = chunk.end(chunkDigest);
if (currChunk.append(raw, pos, len)) { currPackedSize += len; return; if (currFragments == null && currChunk.getObjectCount() == 1) currFragments = new LinkedList<ChunkKey>(); if (currFragments != null) { final int dataEnd = currChunk.position(); final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType(); currChunk.rollback(); endChunk(type); case OBJ_TAG: case OBJ_REF_DELTA: w.adjustObjectCount(1, typeOld); if (!w.append(dataOld, hdrPos, hdrLen)) throw panicCannotInsert(); break; currDataPos = w.position(); if (dataPos < dataEnd && !w.append(dataOld, dataPos, dataEnd - dataPos)) throw panicCannotInsert(); dataOld = null;
private ChunkKey endChunk(int typeCode) throws DhtException { ChunkFormatter w = openChunks[typeCode]; if (w == null) return null; openChunks[typeCode] = null; currChunk = null; if (w.isEmpty()) return null; ChunkKey key = w.end(chunkKeyDigest); ChunkInfo info = w.getChunkInfo(); if (chunkByOrder[typeCode] == null) chunkByOrder[typeCode] = new ArrayList<ChunkKey>(); chunkByOrder[typeCode].add(key); infoByKey.put(key, info); if (w.getChunkMeta() != null) chunkMeta.put(key, w.getChunkMeta()); Edges e = openEdges[typeCode]; if (e != null) { chunkEdges.put(key, e); openEdges[typeCode] = null; } if (currFragments == null) chunkReadBackCache.put(key, w.getPackChunk()); w.unsafePut(db, dbWriteBuffer); return key; }
activeChunk = newChunk(); if (activeChunk.whole(deflater(), type, data, off, len, objId)) return objId; if (!activeChunk.isEmpty()) { activeChunk.end(digest()); activeChunk.safePut(db, dbBuffer()); activeChunk = newChunk(); if (activeChunk.whole(deflater(), type, data, off, len, objId)) return objId;
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; } }
boolean whole(Deflater def, int type, byte[] data, int off, final int size, ObjectId objId) { if (free() < 10 || maxObjects <= objectsTotal) return false; header(type, size); objectsWhole++; currentObjectType = type; def.finish(); do { int left = free(); if (left == 0) { rollback(); return false; rollback(); return false;
void unsafePut(Database db, WriteBuffer dbWriteBuffer) throws DhtException { db.repository().put(repo, getChunkInfo(), dbWriteBuffer); db.chunk().put(builder, dbWriteBuffer); linkObjects(db, dbWriteBuffer); }
chunkData = cloneArray(chunkData, ptr + TRAILER_SIZE); NB.encodeInt32(chunkData, ptr, options.nextChunkSalt()); ptr += 4; return getChunkKey();
boolean append(byte[] data, int off, int len) { if (free() < len) return false; System.arraycopy(data, off, chunkData, ptr, len); ptr += len; return true; }
private void linkObjects(Database db, WriteBuffer dbWriteBuffer) throws DhtException { if (objectList != null && !objectList.isEmpty()) { for (StoredObject obj : objectList) { db.objectIndex().add(ObjectIndexKey.create(repo, obj), obj.link(getChunkKey()), dbWriteBuffer); } } }
ChunkKey getChunkKey() { return getChunkInfo().getChunkKey(); }
int position = chunk.position(); if (!chunk.whole(type, inflatedSize)) throw new DhtException(DhtText.get().cannotInsertObject); if (chunk.free() == 0) { packedSize += chunk.size(); chunk.setObjectType(type); chunk.setFragment(); fragmentList.add(chunk.end(chunkDigest)); chunk.safePut(db, dbBuffer()); chunk = newChunk(); chunk.appendDeflateOutput(def); if (chunk.free() == 0) { packedSize += chunk.size(); chunk.setObjectType(type); chunk.setFragment(); fragmentList.add(chunk.end(chunkDigest)); chunk.safePut(db, dbBuffer()); chunk = newChunk(); chunk.appendDeflateOutput(def); if (!chunk.isEmpty()) { packedSize += chunk.size(); chunk.setObjectType(type); ChunkKey key = chunk.end(chunkDigest);
if (currChunk.append(raw, pos, len)) { currPackedSize += len; return; if (currFragments == null && currChunk.getObjectCount() == 1) currFragments = new LinkedList<ChunkKey>(); if (currFragments != null) { final int dataEnd = currChunk.position(); final int hdrPos = offsetOf(currChunkPtr); final int hdrLen = dataPos - hdrPos; final int type = typeOf(currChunkPtr); byte[] dataOld = currChunk.getRawChunkDataArray(); final int typeOld = currChunk.getCurrentObjectType(); currChunk.rollback(); endChunk(type); case OBJ_TAG: case OBJ_REF_DELTA: w.adjustObjectCount(1, typeOld); if (!w.append(dataOld, hdrPos, hdrLen)) throw panicCannotInsert(); break; currDataPos = w.position(); if (dataPos < dataEnd && !w.append(dataOld, dataPos, dataEnd - dataPos)) throw panicCannotInsert(); dataOld = null;
private ChunkKey endChunk(int typeCode) throws DhtException { ChunkFormatter w = openChunks[typeCode]; if (w == null) return null; openChunks[typeCode] = null; currChunk = null; if (w.isEmpty()) return null; ChunkKey key = w.end(chunkKeyDigest); ChunkInfo info = w.getChunkInfo(); if (chunkByOrder[typeCode] == null) chunkByOrder[typeCode] = new ArrayList<ChunkKey>(); chunkByOrder[typeCode].add(key); infoByKey.put(key, info); if (w.getChunkMeta() != null) chunkMeta.put(key, w.getChunkMeta()); Edges e = openEdges[typeCode]; if (e != null) { chunkEdges.put(key, e); openEdges[typeCode] = null; } if (currFragments == null) chunkReadBackCache.put(key, w.getPackChunk()); w.unsafePut(db, dbWriteBuffer); return key; }