public class DfsGarbageCollector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Set<ObjectId> |
allHeadsAndTags |
private java.util.Set<ObjectId> |
allTags |
private long |
coalesceGarbageLimit |
private boolean |
convertToReftable |
private DfsReader |
ctx |
private java.util.List<DfsPackFile> |
expiredGarbagePacks |
private long |
garbageTtlMillis |
private boolean |
includeDeletes |
private java.util.List<DfsPackDescription> |
newPackDesc |
private java.util.List<ObjectIdSet> |
newPackObj |
private java.util.List<PackStatistics> |
newPackStats |
private java.util.Set<ObjectId> |
nonHeads |
private DfsObjDatabase |
objdb |
private PackConfig |
packConfig |
private java.util.List<DfsPackFile> |
packsBefore |
private RefDatabase |
refdb |
private java.util.Collection<Ref> |
refsBefore |
private ReftableConfig |
reftableConfig |
private long |
reftableInitialMaxUpdateIndex |
private long |
reftableInitialMinUpdateIndex |
private java.util.List<DfsReftable> |
reftablesBefore |
private DfsRepository |
repo |
private long |
startTimeMillis |
private java.util.Set<ObjectId> |
tagTargets |
private java.util.Set<ObjectId> |
txnHeads |
Constructor and Description |
---|
DfsGarbageCollector(DfsRepository repository)
Initialize a garbage collector.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
anyPackHas(AnyObjectId id) |
private void |
compactReftable(DfsPackDescription pack,
ReftableCompactor compact) |
private static long |
dayStartInMillis(long timeInMillis) |
private long |
estimateGcPackSize(DfsObjDatabase.PackSource first,
DfsObjDatabase.PackSource... rest) |
private java.util.Collection<Ref> |
getAllRefs() |
long |
getCoalesceGarbageLimit()
Get coalesce garbage limit
|
long |
getGarbageTtlMillis()
Get time to live for garbage packs.
|
java.util.List<DfsPackDescription> |
getNewPacks()
Get new packs created by this compaction.
|
java.util.List<PackStatistics> |
getNewPackStatistics()
Get statistics corresponding to the
getNewPacks() . |
PackConfig |
getPackConfig()
Get configuration used to generate the new pack file.
|
java.util.Set<DfsPackDescription> |
getSourcePacks()
Get all of the source packs that fed into this compaction.
|
private boolean |
hasGcReftable() |
private static boolean |
isHead(Ref ref) |
private static boolean |
isTag(Ref ref) |
private PackWriter |
newPackWriter() |
private int |
objectsBefore() |
boolean |
pack(ProgressMonitor pm)
Create a single new pack file containing all of the live objects.
|
private void |
packGarbage(ProgressMonitor pm) |
private void |
packHeads(ProgressMonitor pm) |
private boolean |
packIsCoalesceableGarbage(DfsPackDescription d,
long now) |
private boolean |
packIsExpiredGarbage(DfsPackDescription d,
long now) |
private void |
packRefTreeGraph(ProgressMonitor pm) |
private void |
packRest(ProgressMonitor pm) |
private void |
readPacksBefore() |
private void |
readReftablesBefore() |
DfsGarbageCollector |
setCoalesceGarbageLimit(long limit)
Set the byte size limit for garbage packs to be repacked.
|
DfsGarbageCollector |
setConvertToReftable(boolean convert)
Whether the garbage collector should convert references to reftable.
|
DfsGarbageCollector |
setGarbageTtl(long ttl,
java.util.concurrent.TimeUnit unit)
Set the time to live for garbage objects.
|
DfsGarbageCollector |
setIncludeDeletes(boolean include)
Whether the garbage collector will include tombstones for deleted
references in the reftable.
|
DfsGarbageCollector |
setPackConfig(PackConfig newConfig)
Set the new configuration to use when creating the pack file.
|
DfsGarbageCollector |
setReftableConfig(ReftableConfig cfg)
Set configuration to write a reftable.
|
DfsGarbageCollector |
setReftableInitialMaxUpdateIndex(long u)
Set maxUpdateIndex for the initial reftable created during conversion.
|
DfsGarbageCollector |
setReftableInitialMinUpdateIndex(long u)
Set minUpdateIndex for the initial reftable created during conversion.
|
private java.util.Set<DfsPackDescription> |
toPrune() |
private DfsPackDescription |
writePack(DfsObjDatabase.PackSource source,
PackWriter pw,
ProgressMonitor pm,
long estimatedPackSize) |
private void |
writeReftable() |
private void |
writeReftable(DfsPackDescription pack) |
private void |
writeReftable(DfsPackDescription pack,
java.util.Collection<Ref> refs) |
private final DfsRepository repo
private final RefDatabase refdb
private final DfsObjDatabase objdb
private final java.util.List<DfsPackDescription> newPackDesc
private final java.util.List<PackStatistics> newPackStats
private final java.util.List<ObjectIdSet> newPackObj
private DfsReader ctx
private PackConfig packConfig
private ReftableConfig reftableConfig
private boolean convertToReftable
private boolean includeDeletes
private long reftableInitialMinUpdateIndex
private long reftableInitialMaxUpdateIndex
private long coalesceGarbageLimit
private long garbageTtlMillis
private long startTimeMillis
private java.util.List<DfsPackFile> packsBefore
private java.util.List<DfsReftable> reftablesBefore
private java.util.List<DfsPackFile> expiredGarbagePacks
private java.util.Collection<Ref> refsBefore
private java.util.Set<ObjectId> allHeadsAndTags
private java.util.Set<ObjectId> allTags
private java.util.Set<ObjectId> nonHeads
private java.util.Set<ObjectId> txnHeads
private java.util.Set<ObjectId> tagTargets
public DfsGarbageCollector(DfsRepository repository)
repository
- repository objects to be packed will be read from.public PackConfig getPackConfig()
public DfsGarbageCollector setPackConfig(PackConfig newConfig)
newConfig
- the new configuration to use when creating the pack file.this
public DfsGarbageCollector setReftableConfig(ReftableConfig cfg)
cfg
- configuration to write a reftable. Reftable writing is
disabled (default) when cfg
is null
.this
public DfsGarbageCollector setConvertToReftable(boolean convert)
convert
- if true
, setReftableConfig(ReftableConfig)
has been set non-null, and a GC reftable doesn't yet exist,
the garbage collector will make one by scanning the existing
references, and writing a new reftable. Default is
true
.this
public DfsGarbageCollector setIncludeDeletes(boolean include)
include
- if true
, the garbage collector will include tombstones
for deleted references in the reftable. Default is
false
.this
public DfsGarbageCollector setReftableInitialMinUpdateIndex(long u)
u
- minUpdateIndex for the initial reftable created by scanning
DfsRefDatabase.getRefs(String)
.
Ignored unless caller has also set
setReftableConfig(ReftableConfig)
. Defaults to
1
. Must be u >= 0
.this
public DfsGarbageCollector setReftableInitialMaxUpdateIndex(long u)
u
- maxUpdateIndex for the initial reftable created by scanning
DfsRefDatabase.getRefs(String)
.
Ignored unless caller has also set
setReftableConfig(ReftableConfig)
. Defaults to
1
. Must be u >= 0
.this
public long getCoalesceGarbageLimit()
public DfsGarbageCollector setCoalesceGarbageLimit(long limit)
Any UNREACHABLE_GARBAGE pack smaller than this limit will be repacked at the end of the run. This allows the garbage collector to coalesce unreachable objects into a single file.
If an UNREACHABLE_GARBAGE pack is already larger than this limit it will be left alone by the garbage collector. This avoids unnecessary disk IO reading and copying the objects.
If limit is set to 0 the UNREACHABLE_GARBAGE coalesce is disabled.
If limit is set to Long.MAX_VALUE
, everything is
coalesced.
Keeping unreachable garbage prevents race conditions with repository changes that may suddenly need an object whose only copy was stored in the UNREACHABLE_GARBAGE pack.
limit
- size in bytes.this
public long getGarbageTtlMillis()
public DfsGarbageCollector setGarbageTtl(long ttl, java.util.concurrent.TimeUnit unit)
Any UNREACHABLE_GARBAGE older than this limit will be pruned at the end of the run.
If timeToLiveMillis is set to 0, UNREACHABLE_GARBAGE purging is disabled.
ttl
- Time to live whatever unit is specified.unit
- The specified time unit.this
public boolean pack(ProgressMonitor pm) throws java.io.IOException
This method safely decides which packs can be expired after the new pack is created by validating the references have not been modified in an incompatible way.
pm
- progress monitor to receive updates on as packing may take a
while, depending on the size of the repository.java.io.IOException
- a new pack cannot be created.private java.util.Collection<Ref> getAllRefs() throws java.io.IOException
java.io.IOException
private void readPacksBefore() throws java.io.IOException
java.io.IOException
private void readReftablesBefore() throws java.io.IOException
java.io.IOException
private boolean packIsExpiredGarbage(DfsPackDescription d, long now)
private boolean packIsCoalesceableGarbage(DfsPackDescription d, long now)
private static long dayStartInMillis(long timeInMillis)
public java.util.Set<DfsPackDescription> getSourcePacks()
public java.util.List<DfsPackDescription> getNewPacks()
public java.util.List<PackStatistics> getNewPackStatistics()
getNewPacks()
.
The elements can be null if the stat is not available for the pack file.
getNewPacks()
.private java.util.Set<DfsPackDescription> toPrune()
private void packHeads(ProgressMonitor pm) throws java.io.IOException
java.io.IOException
private void packRest(ProgressMonitor pm) throws java.io.IOException
java.io.IOException
private void packRefTreeGraph(ProgressMonitor pm) throws java.io.IOException
java.io.IOException
private void packGarbage(ProgressMonitor pm) throws java.io.IOException
java.io.IOException
private boolean anyPackHas(AnyObjectId id)
private static boolean isHead(Ref ref)
private static boolean isTag(Ref ref)
private int objectsBefore()
private PackWriter newPackWriter()
private long estimateGcPackSize(DfsObjDatabase.PackSource first, DfsObjDatabase.PackSource... rest)
private DfsPackDescription writePack(DfsObjDatabase.PackSource source, PackWriter pw, ProgressMonitor pm, long estimatedPackSize) throws java.io.IOException
java.io.IOException
private void writeReftable() throws java.io.IOException
java.io.IOException
private void writeReftable(DfsPackDescription pack) throws java.io.IOException
java.io.IOException
private boolean hasGcReftable()
private void writeReftable(DfsPackDescription pack, java.util.Collection<Ref> refs) throws java.io.IOException
java.io.IOException
private void compactReftable(DfsPackDescription pack, ReftableCompactor compact) throws java.io.IOException
java.io.IOException