try (DfsOutputStream out = objdb.writeFile(pack, PACK)) {
pw.writePack(pm, pm, out);
pack.addFileExt(PACK);
+ pack.setBlockSize(PACK, out.blockSize());
}
- try (CountingOutputStream cnt =
- new CountingOutputStream(objdb.writeFile(pack, INDEX))) {
+ 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());
}
if (pw.prepareBitmapIndex(pm)) {
- try (CountingOutputStream cnt = new CountingOutputStream(
- objdb.writeFile(pack, BITMAP_INDEX))) {
+ try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX)) {
+ CountingOutputStream cnt = new CountingOutputStream(out);
pw.writeBitmapIndex(cnt);
pack.addFileExt(BITMAP_INDEX);
pack.setFileSize(BITMAP_INDEX, cnt.getCount());
+ pack.setBlockSize(BITMAP_INDEX, out.blockSize());
}
}
rollback = true;
packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT);
- packOut = new PackStream(db.writeFile(packDsc, PACK));
+ 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.
packIndex = PackIndex.read(buf.openInputStream());
}
- DfsOutputStream os = db.writeFile(pack, INDEX);
- try (CountingOutputStream cnt = new CountingOutputStream(os)) {
+ try (DfsOutputStream os = db.writeFile(pack, INDEX)) {
+ CountingOutputStream cnt = new CountingOutputStream(os);
if (buf != null)
buf.writeTo(cnt, null);
else
index(cnt, packHash, list);
pack.addFileExt(INDEX);
+ pack.setBlockSize(INDEX, os.blockSize());
pack.setFileSize(INDEX, cnt.getCount());
} finally {
if (buf != null) {
private static void writePack(DfsObjDatabase objdb,
DfsPackDescription pack,
PackWriter pw, ProgressMonitor pm) throws IOException {
- DfsOutputStream out = objdb.writeFile(pack, PACK);
- try {
+ try (DfsOutputStream out = objdb.writeFile(pack, PACK)) {
pw.writePack(pm, pm, out);
pack.addFileExt(PACK);
- } finally {
- out.close();
+ pack.setBlockSize(PACK, out.blockSize());
}
}
private static void writeIndex(DfsObjDatabase objdb,
DfsPackDescription pack,
PackWriter pw) throws IOException {
- DfsOutputStream out = objdb.writeFile(pack, INDEX);
- try {
+ 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());
- } finally {
- out.close();
}
}
private PackSource packSource;
private long lastModified;
private long[] sizeMap;
+ private int[] blockSizeMap;
private long objectCount;
private long deltaCount;
private PackStatistics stats;
this.repoDesc = repoDesc;
int dot = name.lastIndexOf('.');
this.packName = (dot < 0) ? name : name.substring(0, dot);
- this.sizeMap = new long[PackExt.values().length];
+
+ int extCnt = PackExt.values().length;
+ sizeMap = new long[extCnt];
+ blockSizeMap = new int[extCnt];
}
/** @return description of the repository. */
return i < sizeMap.length ? sizeMap[i] : 0;
}
+ /**
+ * @param ext
+ * the file extension.
+ * @return blockSize of the file, in bytes. If 0 the blockSize size is not
+ * yet known and may be discovered when opening the file.
+ */
+ public int getBlockSize(PackExt ext) {
+ int i = ext.getPosition();
+ return i < blockSizeMap.length ? blockSizeMap[i] : 0;
+ }
+
+ /**
+ * @param ext
+ * the file extension.
+ * @param blockSize
+ * blockSize of the file, in bytes. If 0 the blockSize is not
+ * known and will be determined on first read.
+ * @return {@code this}
+ */
+ public DfsPackDescription setBlockSize(PackExt ext, int blockSize) {
+ int i = ext.getPosition();
+ if (i >= blockSizeMap.length) {
+ blockSizeMap = Arrays.copyOf(blockSizeMap, i + 1);
+ }
+ blockSizeMap[i] = Math.max(0, blockSize);
+ return this;
+ }
+
/**
* @param estimatedPackSize
* estimated size of the .pack file in bytes. If 0 the pack file
*/
DfsPackFile(DfsBlockCache cache, DfsPackDescription desc) {
super(cache, desc, PACK);
- length = desc.getFileSize(PACK);
- if (length <= 0)
- length = -1;
+
+ int bs = desc.getBlockSize(PACK);
+ if (bs > 0) {
+ setBlockSize(bs);
+ }
+
+ long sz = desc.getFileSize(PACK);
+ length = sz > 0 ? sz : -1;
}
/** @return description that was originally used to configure this pack file. */
readBlock = null;
packDsc.addFileExt(PACK);
packDsc.setFileSize(PACK, packEnd);
+ packDsc.setBlockSize(PACK, blockSize);
writePackIndex();
objdb.commitPack(Collections.singletonList(packDsc), null);