public class DfsPackCompactor
extends java.lang.Object
The compactor combines several pack files together by including all objects contained in each pack file into the same output pack. If an object appears multiple times, it is only included once in the result. Because the new pack is constructed by enumerating the indexes of the source packs, it is quicker than doing a full repack of the repository, however the result is not nearly as space efficient as new delta compression is disabled.
This method is suitable for quickly combining several packs together after receiving a number of small fetch or push operations into a repository, allowing the system to maintain reasonable read performance without expending a lot of time repacking the entire repository.
Modifier and Type | Class and Description |
---|---|
private static class |
DfsPackCompactor.ObjectIdWithOffset |
Modifier and Type | Field and Description |
---|---|
private RevFlag |
added |
private int |
autoAddSize |
private java.util.List<ObjectIdSet> |
exclude |
private RevFlag |
isBase |
private PackStatistics |
newStats |
private DfsPackDescription |
outDesc |
private ReftableConfig |
reftableConfig |
private DfsRepository |
repo |
private RevWalk |
rw |
private java.util.List<DfsPackFile> |
srcPacks |
private java.util.List<DfsReftable> |
srcReftables |
Constructor and Description |
---|
DfsPackCompactor(DfsRepository repository)
Initialize a pack compactor.
|
Modifier and Type | Method and Description |
---|---|
DfsPackCompactor |
add(DfsPackFile pack)
Add a pack to be compacted.
|
DfsPackCompactor |
add(DfsReftable table)
Add a reftable to be compacted.
|
private void |
addObjectsToPack(PackWriter pw,
DfsReader ctx,
ProgressMonitor pm) |
DfsPackCompactor |
autoAdd()
Automatically select pack and reftables to be included, and add them.
|
void |
compact(ProgressMonitor pm)
Compact the pack files together.
|
private void |
compactPacks(DfsReader ctx,
ProgressMonitor pm) |
private void |
compactReftables(DfsReader ctx) |
(package private) static ReftableConfig |
configureReftable(ReftableConfig cfg,
DfsOutputStream out) |
private long |
estimatePackSize() |
DfsPackCompactor |
exclude(DfsPackFile pack)
Exclude objects from the compacted pack.
|
DfsPackCompactor |
exclude(ObjectIdSet set)
Exclude objects from the compacted pack.
|
java.util.List<DfsPackDescription> |
getNewPacks()
Get new packs created by this compaction.
|
java.util.List<PackStatistics> |
getNewPackStatistics()
Get statistics corresponding to the
getNewPacks() . |
java.util.Collection<DfsPackDescription> |
getSourcePacks()
Get all of the source packs that fed into this compaction.
|
private void |
initOutDesc(DfsObjDatabase objdb) |
DfsPackCompactor |
setReftableConfig(ReftableConfig cfg)
Set configuration to write a reftable.
|
private java.util.List<DfsPackCompactor.ObjectIdWithOffset> |
toInclude(DfsPackFile src,
DfsReader ctx) |
private java.util.Collection<DfsPackDescription> |
toPrune() |
private static void |
writeIndex(DfsObjDatabase objdb,
DfsPackDescription pack,
PackWriter pw) |
private static void |
writePack(DfsObjDatabase objdb,
DfsPackDescription pack,
PackWriter pw,
ProgressMonitor pm) |
private void |
writeReftable(DfsObjDatabase objdb,
DfsPackDescription pack,
ReftableCompactor compact) |
private final DfsRepository repo
private final java.util.List<DfsPackFile> srcPacks
private final java.util.List<DfsReftable> srcReftables
private final java.util.List<ObjectIdSet> exclude
private PackStatistics newStats
private DfsPackDescription outDesc
private int autoAddSize
private ReftableConfig reftableConfig
private RevWalk rw
private RevFlag added
private RevFlag isBase
public DfsPackCompactor(DfsRepository repository)
repository
- repository objects to be packed will be read from.public DfsPackCompactor setReftableConfig(ReftableConfig cfg)
cfg
- configuration to write a reftable. Reftable compacting is
disabled (default) when cfg
is null
.this
public DfsPackCompactor add(DfsPackFile pack)
All of the objects in this pack will be copied into the resulting pack. The resulting pack will order objects according to the source pack's own description ordering (which is based on creation date), and then by the order the objects appear in the source pack.
pack
- a pack to combine into the resulting pack.this
public DfsPackCompactor add(DfsReftable table)
table
- a reftable to combine.this
public DfsPackCompactor autoAdd() throws java.io.IOException
Packs are selected based on size, smaller packs get included while bigger ones are omitted.
this
java.io.IOException
- existing packs cannot be read.public DfsPackCompactor exclude(ObjectIdSet set)
set
- objects to not include.this
.public DfsPackCompactor exclude(DfsPackFile pack) throws java.io.IOException
pack
- objects to not include.this
.java.io.IOException
- pack index cannot be loaded.public void compact(ProgressMonitor pm) throws java.io.IOException
pm
- progress monitor to receive updates on as packing may take a
while, depending on the size of the repository.java.io.IOException
- the packs cannot be compacted.private void compactPacks(DfsReader ctx, ProgressMonitor pm) throws java.io.IOException, IncorrectObjectTypeException
java.io.IOException
IncorrectObjectTypeException
private long estimatePackSize()
private void compactReftables(DfsReader ctx) throws java.io.IOException
java.io.IOException
private void initOutDesc(DfsObjDatabase objdb) throws java.io.IOException
java.io.IOException
public java.util.Collection<DfsPackDescription> getSourcePacks()
public java.util.List<DfsPackDescription> getNewPacks()
public java.util.List<PackStatistics> getNewPackStatistics()
getNewPacks()
.
May be null if statistics are not available.getNewPacks()
.private java.util.Collection<DfsPackDescription> toPrune()
private void addObjectsToPack(PackWriter pw, DfsReader ctx, ProgressMonitor pm) throws java.io.IOException, IncorrectObjectTypeException
java.io.IOException
IncorrectObjectTypeException
private java.util.List<DfsPackCompactor.ObjectIdWithOffset> toInclude(DfsPackFile src, DfsReader ctx) throws java.io.IOException
java.io.IOException
private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws java.io.IOException
java.io.IOException
private static void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws java.io.IOException
java.io.IOException
private void writeReftable(DfsObjDatabase objdb, DfsPackDescription pack, ReftableCompactor compact) throws java.io.IOException
java.io.IOException
static ReftableConfig configureReftable(ReftableConfig cfg, DfsOutputStream out)