Browse Source

dfs: optionally store blockSize in DfsPackDescription

Allow a DFS implementation to report blockSize to DfsPackFile,
bypassing alignment errors and corrections in the DfsBlockCache when
the blockSize of a specific file differs from the cache's configured
blockSize.

Change-Id: Ic376314d4a86a0bd528c033e169d93eef035b233
tags/v4.9.0.201710071750-r
Shawn Pearce 7 years ago
parent
commit
d4cfa95ba3

+ 7
- 4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java View File

@@ -563,22 +563,25 @@ public class DfsGarbageCollector {
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());
}
}


+ 6
- 3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java View File

@@ -281,7 +281,9 @@ public class DfsInserter extends ObjectInserter {

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.
@@ -312,13 +314,14 @@ public class DfsInserter extends ObjectInserter {
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) {

+ 4
- 8
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java View File

@@ -370,27 +370,23 @@ public class DfsPackCompactor {
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();
}
}


+ 33
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java View File

@@ -65,6 +65,7 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
private PackSource packSource;
private long lastModified;
private long[] sizeMap;
private int[] blockSizeMap;
private long objectCount;
private long deltaCount;
private PackStatistics stats;
@@ -91,7 +92,10 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
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. */
@@ -193,6 +197,34 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
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

+ 8
- 3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java View File

@@ -123,9 +123,14 @@ public final class DfsPackFile extends BlockBasedFile {
*/
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. */

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java View File

@@ -150,6 +150,7 @@ public class DfsPackParser extends PackParser {
readBlock = null;
packDsc.addFileExt(PACK);
packDsc.setFileSize(PACK, packEnd);
packDsc.setBlockSize(PACK, blockSize);

writePackIndex();
objdb.commitPack(Collections.singletonList(packDsc), null);

Loading…
Cancel
Save