private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, PACK)) { pw.writePack(pm, pm, out); pack.addFileExt(PACK); pack.setBlockSize(PACK, out.blockSize()); } }
private void compactReftable(DfsPackDescription pack, ReftableCompactor compact) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { compact.setConfig(configureReftable(reftableConfig, out)); compact.compact(out); pack.addFileExt(REFTABLE); pack.setReftableStats(compact.getStats()); } } }
private void writeReftable(DfsObjDatabase objdb, DfsPackDescription pack, ReftableCompactor compact) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { compact.setConfig(configureReftable(reftableConfig, out)); compact.compact(out); pack.addFileExt(REFTABLE); pack.setReftableStats(compact.getStats()); } }
/** {@inheritDoc} */ @Override protected void onPackHeader(long objectCount) throws IOException { if (objectCount == 0) { isEmptyPack = true; currBuf = new byte[256]; return; } packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE); out = objdb.writeFile(packDsc, PACK); packKey = packDsc.getStreamKey(PACK); int size = out.blockSize(); if (size <= 0) size = blockCache.getBlockSize(); else if (size < blockCache.getBlockSize()) size = (blockCache.getBlockSize() / size) * size; blockSize = size; currBuf = new byte[blockSize]; }
private void applyUpdates(RevWalk rw, List<ReceiveCommand> pending) throws IOException { List<Ref> newRefs = toNewRefs(rw, pending); long updateIndex = nextUpdateIndex(); Set<DfsPackDescription> prune = Collections.emptySet(); DfsPackDescription pack = odb.newPack(PackSource.INSERT); try (DfsOutputStream out = odb.writeFile(pack, REFTABLE)) { ReftableConfig cfg = DfsPackCompactor .configureReftable(reftableConfig, out); ReftableWriter.Stats stats; if (refdb.compactDuringCommit() && newRefs.size() * AVG_BYTES <= cfg.getRefBlockSize() && canCompactTopOfStack(cfg)) { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); write(tmp, cfg, updateIndex, newRefs, pending); stats = compactTopOfStack(out, cfg, tmp.toByteArray()); prune = toPruneTopOfStack(); } else { stats = write(out, cfg, updateIndex, newRefs, pending); } pack.addFileExt(REFTABLE); pack.setReftableStats(stats); } odb.commitPack(Collections.singleton(pack), prune); odb.addReftable(pack, prune); refdb.clearCache(); }
private static void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, INDEX)) { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); pack.setBlockSize(INDEX, out.blockSize()); pack.setIndexVersion(pw.getIndexVersion()); } }
private void beginPack() throws IOException { objectList = new BlockList<>(); objectMap = new ObjectIdOwnerMap<>(); cache = DfsBlockCache.getInstance(); rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); DfsOutputStream dfsOut = db.writeFile(packDsc, PACK); packDsc.setBlockSize(PACK, dfsOut.blockSize()); packOut = new PackStream(dfsOut); packKey = packDsc.getStreamKey(PACK); // Write the header as though it were a single object pack. byte[] buf = packOut.hdrBuf; System.arraycopy(Constants.PACK_SIGNATURE, 0, buf, 0, 4); NB.encodeInt32(buf, 4, 2); // Always use pack version 2. NB.encodeInt32(buf, 8, 1); // Always assume 1 object. packOut.write(buf, 0, 12); }
try (DfsOutputStream out = objdb.writeFile(pack, PACK)) { pw.writePack(pm, pm, out); pack.addFileExt(PACK); try (DfsOutputStream out = objdb.writeFile(pack, INDEX)) { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX)) { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeBitmapIndex(cnt);
private void writeReftable(DfsPackDescription pack, Collection<Ref> refs) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { ReftableConfig cfg = configureReftable(reftableConfig, out); ReftableWriter writer = new ReftableWriter(cfg) .setMinUpdateIndex(reftableInitialMinUpdateIndex) .setMaxUpdateIndex(reftableInitialMaxUpdateIndex) .begin(out) .sortAndWriteRefs(refs) .finish(); pack.addFileExt(REFTABLE); pack.setReftableStats(writer.getStats()); } }
PackIndex writePackIndex(DfsPackDescription pack, byte[] packHash, List<PackedObjectInfo> list) throws IOException { pack.setIndexVersion(INDEX_VERSION); pack.setObjectCount(list.size()); // If there are less than 58,000 objects, the entire index fits in under // 2 MiB. Callers will probably need the index immediately, so buffer // the index in process and load from the buffer. PackIndex packIndex = null; try (TemporaryBuffer.Heap buf = maybeGetTemporaryBuffer(list); DfsOutputStream os = db.writeFile(pack, INDEX); CountingOutputStream cnt = new CountingOutputStream(os)) { if (buf != null) { index(buf, packHash, list); packIndex = PackIndex.read(buf.openInputStream()); buf.writeTo(cnt, null); } else { index(cnt, packHash, list); } pack.addFileExt(INDEX); pack.setBlockSize(INDEX, os.blockSize()); pack.setFileSize(INDEX, cnt.getCount()); } return packIndex; }
private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { DfsOutputStream out = objdb.writeFile(pack, PACK); try { pw.writePack(pm, pm, out); pack.addFileExt(PACK); } finally { out.close(); } }
private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, PACK)) { pw.writePack(pm, pm, out); pack.addFileExt(PACK); pack.setBlockSize(PACK, out.blockSize()); } }
private void compactReftable(DfsPackDescription pack, ReftableCompactor compact) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { compact.setConfig(configureReftable(reftableConfig, out)); compact.compact(out); pack.addFileExt(REFTABLE); pack.setReftableStats(compact.getStats()); } } }
private void writeReftable(DfsObjDatabase objdb, DfsPackDescription pack, ReftableCompactor compact) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { compact.setConfig(configureReftable(reftableConfig, out)); compact.compact(out); pack.addFileExt(REFTABLE); pack.setReftableStats(compact.getStats()); } }
private void beginPack() throws IOException { objectList = new BlockList<PackedObjectInfo>(); objectMap = new ObjectIdOwnerMap<PackedObjectInfo>(); cache = DfsBlockCache.getInstance(); rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); packOut = new PackStream(db.writeFile(packDsc, PACK)); packKey = new DfsPackKey(); // Write the header as though it were a single object pack. byte[] buf = packOut.hdrBuf; System.arraycopy(Constants.PACK_SIGNATURE, 0, buf, 0, 4); NB.encodeInt32(buf, 4, 2); // Always use pack version 2. NB.encodeInt32(buf, 8, 1); // Always assume 1 object. packOut.write(buf, 0, 12); }
@Override protected void onPackHeader(long objectCount) throws IOException { if (objectCount == 0) { isEmptyPack = true; currBuf = new byte[256]; return; } packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE); packKey = new DfsPackKey(); out = objdb.writeFile(packDsc, PACK); int size = out.blockSize(); if (size <= 0) size = blockCache.getBlockSize(); else if (size < blockCache.getBlockSize()) size = (blockCache.getBlockSize() / size) * size; blockSize = size; currBuf = new byte[blockSize]; }
private static void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws IOException { DfsOutputStream out = objdb.writeFile(pack, INDEX); try { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); pack.setIndexVersion(pw.getIndexVersion()); } finally { out.close(); } }
private static void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, INDEX)) { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); pack.setBlockSize(INDEX, out.blockSize()); pack.setIndexVersion(pw.getIndexVersion()); } }
private void beginPack() throws IOException { objectList = new BlockList<>(); objectMap = new ObjectIdOwnerMap<>(); cache = DfsBlockCache.getInstance(); rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); DfsOutputStream dfsOut = db.writeFile(packDsc, PACK); packDsc.setBlockSize(PACK, dfsOut.blockSize()); packOut = new PackStream(dfsOut); packKey = packDsc.getStreamKey(PACK); // Write the header as though it were a single object pack. byte[] buf = packOut.hdrBuf; System.arraycopy(Constants.PACK_SIGNATURE, 0, buf, 0, 4); NB.encodeInt32(buf, 4, 2); // Always use pack version 2. NB.encodeInt32(buf, 8, 1); // Always assume 1 object. packOut.write(buf, 0, 12); }
private void writeReftable(DfsPackDescription pack, Collection<Ref> refs) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, REFTABLE)) { ReftableConfig cfg = configureReftable(reftableConfig, out); ReftableWriter writer = new ReftableWriter(cfg) .setMinUpdateIndex(reftableInitialMinUpdateIndex) .setMaxUpdateIndex(reftableInitialMaxUpdateIndex) .begin(out) .sortAndWriteRefs(refs) .finish(); pack.addFileExt(REFTABLE); pack.setReftableStats(writer.getStats()); } }