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

public Class ReftableCompactor

extends Object
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.util.ArrayDeque, .ArrayList, .List, org.eclipse.jgit.internal.storage.reftable.ReftableWriter.Stats, org.eclipse.jgit.lib.PersonIdent, .ReflogEntry

Merges reftables and compacts them into a single output.

For a partial compaction callers should setIncludeDeletes(boolean) to true to ensure the new reftable continues to use a delete marker to shadow any lower reftable that may have the reference present.

By default all log entries within the range defined by setReflogExpireMinUpdateIndex(long) and setReflogExpireMaxUpdateIndex(long) are copied, even if no references in the output file match the log records. Callers may truncate the log to a more recent time horizon with setReflogExpireOldestReflogTimeMillis(long), or disable the log altogether with setOldestReflogTimeMillis(Long.MAX_VALUE).

Field Summary

Modifier and TypeField and Description
private boolean
private long
private long
private long
private ReftableWriter.Stats
private final ArrayDeque<ReftableReader>
private final ReftableWriter

Constructor Summary

AccessConstructor and Description
public
ReftableCompactor(OutputStream
stream to write the compacted tables to. Caller is responsible for closing out.
out
)

Creates a new compactor.

Method Summary

Modifier and TypeMethod and Description
public void
addAll(List<ReftableReader>
tables to compact. Tables should be ordered oldest first/most recent last so that the more recent tables can shadow the older results. Caller is responsible for closing the readers.
readers
)

Add all of the tables, in the specified order.

public void
compact()

Write a compaction to out.

public ReftableWriter.Stats

Returns:

statistics of the last written reftable.
getStats
()

Get statistics of the last written reftable.

private void
private void
public ReftableCompactor

Returns:

this
setConfig
(ReftableConfig
configuration for the reftable.
cfg
)

Set configuration for the reftable.

public ReftableCompactor

Returns:

this
setIncludeDeletes
(boolean
true to include deletions in the output, which may be necessary for partial compaction.
deletes
)

Whether to include deletions in the output, which may be necessary for partial compaction.

public ReftableCompactor

Returns:

this
setReflogExpireMaxUpdateIndex
(long
the maximum update index for log entries that appear in the compacted reftable. This should be at least 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
max
)

Set the maximum update index for log entries that appear in the compacted reftable.

public ReftableCompactor

Returns:

this
setReflogExpireMinUpdateIndex
(long
the minimum update index for log entries that appear in the compacted reftable. This should be 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
min
)

Set the minimum update index for log entries that appear in the compacted reftable.

public ReftableCompactor

Returns:

this
setReflogExpireOldestReflogTimeMillis
(long
oldest log time to preserve. Entries whose timestamps are >= timeMillis will be copied into the output file. Log entries that predate timeMillis will be discarded. Specified in Java standard milliseconds since the epoch.
timeMillis
)

Set oldest reflog time to preserve.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

includeDeletesback to summary
private boolean includeDeletes
reflogExpireMaxUpdateIndexback to summary
private long reflogExpireMaxUpdateIndex
reflogExpireMinUpdateIndexback to summary
private long reflogExpireMinUpdateIndex
reflogExpireOldestReflogTimeMillisback to summary
private long reflogExpireOldestReflogTimeMillis
statsback to summary
private ReftableWriter.Stats stats
tablesback to summary
private final ArrayDeque<ReftableReader> tables
writerback to summary
private final ReftableWriter writer

Constructor Detail

ReftableCompactorback to summary
public ReftableCompactor(OutputStream out)

Creates a new compactor.

Parameters
out:OutputStream

stream to write the compacted tables to. Caller is responsible for closing out.

Method Detail

addAllback to summary
public void addAll(List<ReftableReader> readers) throws IOException

Add all of the tables, in the specified order.

Parameters
readers:List<ReftableReader>

tables to compact. Tables should be ordered oldest first/most recent last so that the more recent tables can shadow the older results. Caller is responsible for closing the readers.

Exceptions
IOException:
update indexes of a reader cannot be accessed.
compactback to summary
public void compact() throws IOException

Write a compaction to out.

Exceptions
IOException:
if tables cannot be read, or cannot be written.
getStatsback to summary
public ReftableWriter.Stats getStats()

Get statistics of the last written reftable.

Returns:ReftableWriter.Stats

statistics of the last written reftable.

mergeLogsback to summary
private void mergeLogs(MergedReftable mr) throws IOException
mergeRefsback to summary
private void mergeRefs(MergedReftable mr) throws IOException
setConfigback to summary
public ReftableCompactor setConfig(ReftableConfig cfg)

Set configuration for the reftable.

Parameters
cfg:ReftableConfig

configuration for the reftable.

Returns:ReftableCompactor

this

setIncludeDeletesback to summary
public ReftableCompactor setIncludeDeletes(boolean deletes)

Whether to include deletions in the output, which may be necessary for partial compaction.

Parameters
deletes:boolean

true to include deletions in the output, which may be necessary for partial compaction.

Returns:ReftableCompactor

this

setReflogExpireMaxUpdateIndexback to summary
public ReftableCompactor setReflogExpireMaxUpdateIndex(long max)

Set the maximum update index for log entries that appear in the compacted reftable.

Parameters
max:long

the maximum update index for log entries that appear in the compacted reftable. This should be at least 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.

Returns:ReftableCompactor

this

setReflogExpireMinUpdateIndexback to summary
public ReftableCompactor setReflogExpireMinUpdateIndex(long min)

Set the minimum update index for log entries that appear in the compacted reftable.

Parameters
min:long

the minimum update index for log entries that appear in the compacted reftable. This should be 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.

Returns:ReftableCompactor

this

setReflogExpireOldestReflogTimeMillisback to summary
public ReftableCompactor setReflogExpireOldestReflogTimeMillis(long timeMillis)

Set oldest reflog time to preserve.

Parameters
timeMillis:long

oldest log time to preserve. Entries whose timestamps are >= timeMillis will be copied into the output file. Log entries that predate timeMillis will be discarded. Specified in Java standard milliseconds since the epoch.

Returns:ReftableCompactor

this