Top Description Fields Constructors Methods
org.eclipse.jgit.internal.storage.dfs

public Class DfsGarbageCollector

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.COMPACT, .DfsObjDatabase.PackSource.GC, .DfsObjDatabase.PackSource.GC_REST, .DfsObjDatabase.PackSource.INSERT, .DfsObjDatabase.PackSource.RECEIVE, .DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE, .DfsPackCompactor.configureReftable, org.eclipse.jgit.internal.storage.pack.PackExt.COMMIT_GRAPH, .PackExt.OBJECT_SIZE_INDEX, .PackExt.PACK, .PackExt.REFTABLE, .PackWriter.NONE

Repack and garbage collect a repository.

Field Summary

Modifier and TypeField and Description
private Set<ObjectId>
private Set<ObjectId>
private long
private boolean
private DfsReader
private List<DfsPackFile>
private long
private boolean
private final List<DfsPackDescription>
private final List<ObjectIdSet>
private final List<PackStatistics>
private Set<ObjectId>
private final DfsObjDatabase
private PackConfig
private List<DfsPackFile>
private final RefDatabase
private Instant
private Collection<Ref>
private ReftableConfig
private long
private long
private List<DfsReftable>
private final DfsRepository
private Instant
private Set<ObjectId>
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
DfsGarbageCollector(DfsRepository
repository objects to be packed will be read from.
repository
)

Initialize a garbage collector.

Method Summary

Modifier and TypeMethod and Description
private boolean
private static long
dayStartInMillis(long timeInMillis)

private long
private Collection<Ref>
public long

Returns:

coalesce garbage limit, packs smaller than this size will be repacked.
getCoalesceGarbageLimit
()

Get coalesce garbage limit

public long

Returns:

garbage packs older than this limit (in milliseconds) will be pruned as part of the garbage collection process if the value is > 0, otherwise garbage packs are retained.
getGarbageTtlMillis
()

Get time to live for garbage packs.

public List<DfsPackDescription>

Returns:

new packs created by this compaction.
getNewPacks
()

Get new packs created by this compaction.

public List<PackStatistics>

Returns:

statistics corresponding to the getNewPacks().
getNewPackStatistics
()

Get statistics corresponding to the getNewPacks().

public PackConfig

Returns:

configuration used to generate the new pack file.
getPackConfig
()

Get configuration used to generate the new pack file.

public Set<DfsPackDescription>

Returns:

all of the source packs that fed into this compaction.
getSourcePacks
()

Get all of the source packs that fed into this compaction.

private boolean
private static boolean
isHead(Ref ref)

private static boolean
isTag(Ref ref)

private PackWriter
private int
public boolean

Returns:

true if the repack was successful without race conditions. False if a race condition was detected and the repack should be run again later.
pack
(ProgressMonitor
progress monitor to receive updates on as packing may take a while, depending on the size of the repository.
pm
)

Create a single new pack file containing all of the live objects.

private void
private void
private boolean
private boolean
private void
private void
private void
public DfsGarbageCollector

Returns:

this
setCoalesceGarbageLimit
(long
size in bytes.
limit
)

Set the byte size limit for garbage packs to be repacked.

public DfsGarbageCollector

Returns:

this
setConvertToReftable
(boolean
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.
convert
)

Whether the garbage collector should convert references to reftable.

public DfsGarbageCollector

Returns:

this
setGarbageTtl
(long
Time to live whatever unit is specified.
ttl
,
TimeUnit
The specified time unit.
unit
)

Set the time to live for garbage objects.

public DfsGarbageCollector

Returns:

this
setIncludeDeletes
(boolean
if true, the garbage collector will include tombstones for deleted references in the reftable. Default is false.
include
)

Whether the garbage collector will include tombstones for deleted references in the reftable.

public DfsGarbageCollector

Returns:

this
setPackConfig
(PackConfig
the new configuration to use when creating the pack file.
newConfig
)

Set the new configuration to use when creating the pack file.

public DfsGarbageCollector

Returns:

this
setRefLogExpire
(Instant
instant in time which defines refLog expiration
refLogExpire
)

Set time limit to the reflog history.

public DfsGarbageCollector

Returns:

this
setReftableConfig
(ReftableConfig
configuration to write a reftable. Reftable writing is disabled (default) when cfg is null.
cfg
)

Set configuration to write a reftable.

public DfsGarbageCollector

Returns:

this
setReftableInitialMaxUpdateIndex
(long
maxUpdateIndex for the initial reftable created by scanning org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase#getRefs(String). Ignored unless caller has also set setReftableConfig(ReftableConfig). Defaults to 1. Must be u >= 0.
u
)

Set maxUpdateIndex for the initial reftable created during conversion.

public DfsGarbageCollector

Returns:

this
setReftableInitialMinUpdateIndex
(long
minUpdateIndex for the initial reftable created by scanning org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase#getRefs(String). Ignored unless caller has also set setReftableConfig(ReftableConfig). Defaults to 1. Must be u >= 0.
u
)

Set minUpdateIndex for the initial reftable created during conversion.

public DfsGarbageCollector

Returns:

this
setWriteBloomFilter
(boolean
Whether bloom filter generation is enabled
enable
)

Toggle bloom filter generation.

public DfsGarbageCollector

Returns:

this
setWriteCommitGraph
(boolean
Allow/Disallow commit graph generation.
enable
)

Toggle commit graph generation.

private Set<DfsPackDescription>
private void
private DfsPackDescription
writePack(DfsObjDatabase.PackSource source, PackWriter pw, ProgressMonitor pm, long estimatedPackSize)

private void
private void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allHeadsAndTagsback to summary
private Set<ObjectId> allHeadsAndTags
allTagsback to summary
private Set<ObjectId> allTags
coalesceGarbageLimitback to summary
private long coalesceGarbageLimit
convertToReftableback to summary
private boolean convertToReftable
ctxback to summary
private DfsReader ctx
expiredGarbagePacksback to summary
private List<DfsPackFile> expiredGarbagePacks
garbageTtlMillisback to summary
private long garbageTtlMillis
includeDeletesback to summary
private boolean includeDeletes
newPackDescback to summary
private final List<DfsPackDescription> newPackDesc
newPackObjback to summary
private final List<ObjectIdSet> newPackObj
newPackStatsback to summary
private final List<PackStatistics> newPackStats
nonHeadsback to summary
private Set<ObjectId> nonHeads
objdbback to summary
private final DfsObjDatabase objdb
packConfigback to summary
private PackConfig packConfig
packsBeforeback to summary
private List<DfsPackFile> packsBefore
refdbback to summary
private final RefDatabase refdb
refLogExpireback to summary
private Instant refLogExpire
refsBeforeback to summary
private Collection<Ref> refsBefore
reftableConfigback to summary
private ReftableConfig reftableConfig
reftableInitialMaxUpdateIndexback to summary
private long reftableInitialMaxUpdateIndex
reftableInitialMinUpdateIndexback to summary
private long reftableInitialMinUpdateIndex
reftablesBeforeback to summary
private List<DfsReftable> reftablesBefore
repoback to summary
private final DfsRepository repo
startTimeback to summary
private Instant startTime
tagTargetsback to summary
private Set<ObjectId> tagTargets
writeBloomFilterback to summary
private boolean writeBloomFilter
writeCommitGraphback to summary
private boolean writeCommitGraph

Constructor Detail

DfsGarbageCollectorback to summary
public DfsGarbageCollector(DfsRepository repository)

Initialize a garbage collector.

Parameters
repository:DfsRepository

repository objects to be packed will be read from.

Method Detail

anyPackHasback to summary
private boolean anyPackHas(AnyObjectId id)
dayStartInMillisback to summary
private static long dayStartInMillis(long timeInMillis)
estimateGcPackSizeback to summary
private long estimateGcPackSize(DfsObjDatabase.PackSource first, DfsObjDatabase.PackSource... rest)
getAllRefsback to summary
private Collection<Ref> getAllRefs() throws IOException
getCoalesceGarbageLimitback to summary
public long getCoalesceGarbageLimit()

Get coalesce garbage limit

Returns:long

coalesce garbage limit, packs smaller than this size will be repacked.

getGarbageTtlMillisback to summary
public long getGarbageTtlMillis()

Get time to live for garbage packs.

Returns:long

garbage packs older than this limit (in milliseconds) will be pruned as part of the garbage collection process if the value is > 0, otherwise garbage packs are retained.

getNewPacksback to summary
public List<DfsPackDescription> getNewPacks()

Get new packs created by this compaction.

Returns:List<DfsPackDescription>

new packs created by this compaction.

getNewPackStatisticsback to summary
public List<PackStatistics> getNewPackStatistics()

Get statistics corresponding to the getNewPacks().

The elements can be null if the stat is not available for the pack file.

Returns:List<PackStatistics>

statistics corresponding to the getNewPacks().

getPackConfigback to summary
public PackConfig getPackConfig()

Get configuration used to generate the new pack file.

Returns:PackConfig

configuration used to generate the new pack file.

getSourcePacksback to summary
public Set<DfsPackDescription> getSourcePacks()

Get all of the source packs that fed into this compaction.

Returns:Set<DfsPackDescription>

all of the source packs that fed into this compaction.

hasGcReftableback to summary
private boolean hasGcReftable()
isHeadback to summary
private static boolean isHead(Ref ref)
isTagback to summary
private static boolean isTag(Ref ref)
newPackWriterback to summary
private PackWriter newPackWriter()
objectsBeforeback to summary
private int objectsBefore()
packback to summary
public boolean pack(ProgressMonitor pm) throws IOException

Create a single new pack file containing all of the live objects.

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.

Parameters
pm:ProgressMonitor

progress monitor to receive updates on as packing may take a while, depending on the size of the repository.

Returns:boolean

true if the repack was successful without race conditions. False if a race condition was detected and the repack should be run again later.

Exceptions
IOException:
a new pack cannot be created.
packGarbageback to summary
private void packGarbage(ProgressMonitor pm) throws IOException
packHeadsback to summary
private void packHeads(ProgressMonitor pm) throws IOException
packIsCoalesceableGarbageback to summary
private boolean packIsCoalesceableGarbage(DfsPackDescription d, long now)
packIsExpiredGarbageback to summary
private boolean packIsExpiredGarbage(DfsPackDescription d, long now)
packRestback to summary
private void packRest(ProgressMonitor pm) throws IOException
readPacksBeforeback to summary
private void readPacksBefore() throws IOException
readReftablesBeforeback to summary
private void readReftablesBefore() throws IOException
setCoalesceGarbageLimitback to summary
public DfsGarbageCollector setCoalesceGarbageLimit(long limit)

Set the byte size limit for garbage packs to be repacked.

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 java.lang.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.

Parameters
limit:long

size in bytes.

Returns:DfsGarbageCollector

this

setConvertToReftableback to summary
public DfsGarbageCollector setConvertToReftable(boolean convert)

Whether the garbage collector should convert references to reftable.

Parameters
convert:boolean

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.

Returns:DfsGarbageCollector

this

setGarbageTtlback to summary
public DfsGarbageCollector setGarbageTtl(long ttl, TimeUnit unit)

Set the time to live for garbage objects.

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.

Parameters
ttl:long

Time to live whatever unit is specified.

unit:TimeUnit

The specified time unit.

Returns:DfsGarbageCollector

this

setIncludeDeletesback to summary
public DfsGarbageCollector setIncludeDeletes(boolean include)

Whether the garbage collector will include tombstones for deleted references in the reftable.

Parameters
include:boolean

if true, the garbage collector will include tombstones for deleted references in the reftable. Default is false.

Returns:DfsGarbageCollector

this

setPackConfigback to summary
public DfsGarbageCollector setPackConfig(PackConfig newConfig)

Set the new configuration to use when creating the pack file.

Parameters
newConfig:PackConfig

the new configuration to use when creating the pack file.

Returns:DfsGarbageCollector

this

setRefLogExpireback to summary
public DfsGarbageCollector setRefLogExpire(Instant refLogExpire)

Set time limit to the reflog history.

Garbage Collector prunes entries from reflog history older than refLogExpire

Parameters
refLogExpire:Instant

instant in time which defines refLog expiration

Returns:DfsGarbageCollector

this

setReftableConfigback to summary
public DfsGarbageCollector setReftableConfig(ReftableConfig cfg)

Set configuration to write a reftable.

Parameters
cfg:ReftableConfig

configuration to write a reftable. Reftable writing is disabled (default) when cfg is null.

Returns:DfsGarbageCollector

this

setReftableInitialMaxUpdateIndexback to summary
public DfsGarbageCollector setReftableInitialMaxUpdateIndex(long u)

Set maxUpdateIndex for the initial reftable created during conversion.

Parameters
u:long

maxUpdateIndex for the initial reftable created by scanning org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase#getRefs(String). Ignored unless caller has also set setReftableConfig(ReftableConfig). Defaults to 1. Must be u >= 0.

Returns:DfsGarbageCollector

this

setReftableInitialMinUpdateIndexback to summary
public DfsGarbageCollector setReftableInitialMinUpdateIndex(long u)

Set minUpdateIndex for the initial reftable created during conversion.

Parameters
u:long

minUpdateIndex for the initial reftable created by scanning org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase#getRefs(String). Ignored unless caller has also set setReftableConfig(ReftableConfig). Defaults to 1. Must be u >= 0.

Returns:DfsGarbageCollector

this

setWriteBloomFilterback to summary
public DfsGarbageCollector setWriteBloomFilter(boolean enable)

Toggle bloom filter generation.

False by default.

Parameters
enable:boolean

Whether bloom filter generation is enabled

Returns:DfsGarbageCollector

this

setWriteCommitGraphback to summary
public DfsGarbageCollector setWriteCommitGraph(boolean enable)

Toggle commit graph generation.

False by default.

Parameters
enable:boolean

Allow/Disallow commit graph generation.

Returns:DfsGarbageCollector

this

toPruneback to summary
private Set<DfsPackDescription> toPrune()
writeCommitGraphback to summary
private void writeCommitGraph(DfsPackDescription pack, ProgressMonitor pm) throws IOException
writePackback to summary
private DfsPackDescription writePack(DfsObjDatabase.PackSource source, PackWriter pw, ProgressMonitor pm, long estimatedPackSize) throws IOException
writeReftableback to summary
private void writeReftable() throws IOException
writeReftableback to summary
private void writeReftable(DfsPackDescription pack) throws IOException
writeReftableback to summary
private void writeReftable(DfsPackDescription pack, Collection<Ref> refs) throws IOException