public class ReftableWriter
extends java.lang.Object
A reftable can be written in a streaming fashion, provided the caller sorts
all references. A
ReftableWriter
is
single-use, and not thread-safe.
Modifier and Type | Class and Description |
---|---|
private class |
ReftableWriter.IndexBuilder |
private static class |
ReftableWriter.RefList |
private class |
ReftableWriter.Section |
static class |
ReftableWriter.Stats
Statistics about a written reftable.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
alignBlocks |
private ReftableConfig |
config |
private BlockWriter |
cur |
private boolean |
indexObjects |
private int |
logBlockSize |
private ReftableWriter.Section |
logs |
private int |
maxIndexLevels |
private long |
maxUpdateIndex |
private long |
minUpdateIndex |
private ObjectIdSubclassMap<ReftableWriter.RefList> |
obj2ref |
private int |
objIdLen |
private ReftableWriter.Section |
objs |
private ReftableOutputStream |
out |
private int |
refBlockSize |
private ReftableWriter.Section |
refs |
private int |
restartInterval |
private ReftableWriter.Stats |
stats |
Constructor and Description |
---|
ReftableWriter()
Initialize a writer with a default configuration.
|
ReftableWriter(ReftableConfig cfg)
Initialize a writer with a specific configuration.
|
Modifier and Type | Method and Description |
---|---|
ReftableWriter |
begin(java.io.OutputStream os)
Begin writing the reftable.
|
private void |
beginLog() |
void |
deleteLog(java.lang.String ref,
long updateIndex)
Record deletion of one reflog entry in this reftable.
|
private void |
encodeHeader(byte[] hdr) |
long |
estimateTotalBytes()
Get an estimate of the current size in bytes of the reftable
|
ReftableWriter |
finish()
Finish writing the reftable by writing its trailer.
|
private void |
finishLogSection() |
private void |
finishRefAndObjSections() |
private static long |
firstBlockPosition(ReftableWriter.Section s) |
ReftableWriter.Stats |
getStats()
Get statistics of the last written reftable.
|
private void |
indexId(ObjectId id,
long blockPos) |
private static long |
indexPosition(ReftableWriter.Section s) |
private void |
indexRef(Ref ref,
long blockPos) |
ReftableWriter |
setConfig(ReftableConfig cfg)
Set configuration for the writer.
|
ReftableWriter |
setMaxUpdateIndex(long max)
Set the maximum update index for log entries that appear in this
reftable.
|
ReftableWriter |
setMinUpdateIndex(long min)
Set the minimum update index for log entries that appear in this
reftable.
|
private static int |
shortestUniqueAbbreviation(java.util.List<ReftableWriter.RefList> in) |
private boolean |
shouldHaveIndex(ReftableWriter.IndexBuilder idx) |
ReftableWriter |
sortAndWriteRefs(java.util.Collection<Ref> refsToPack)
Sort a collection of references and write them to the reftable.
|
private static java.util.List<ReftableWriter.RefList> |
sortById(ObjectIdSubclassMap<ReftableWriter.RefList> m) |
private void |
writeFileFooter() |
private void |
writeFileHeader() |
void |
writeLog(java.lang.String ref,
long updateIndex,
PersonIdent who,
ObjectId oldId,
ObjectId newId,
java.lang.String message)
Write one reflog entry to the reftable.
|
private void |
writeObjBlocks() |
void |
writeRef(Ref ref)
Write one reference to the reftable.
|
void |
writeRef(Ref ref,
long updateIndex)
Write one reference to the reftable.
|
private ReftableConfig config
private int refBlockSize
private int logBlockSize
private int restartInterval
private int maxIndexLevels
private boolean alignBlocks
private boolean indexObjects
private long minUpdateIndex
private long maxUpdateIndex
private ReftableOutputStream out
private ObjectIdSubclassMap<ReftableWriter.RefList> obj2ref
private BlockWriter cur
private ReftableWriter.Section refs
private ReftableWriter.Section objs
private ReftableWriter.Section logs
private int objIdLen
private ReftableWriter.Stats stats
public ReftableWriter()
public ReftableWriter(ReftableConfig cfg)
cfg
- configuration for the writer.public ReftableWriter setConfig(ReftableConfig cfg)
cfg
- configuration for the writer.this
public ReftableWriter setMinUpdateIndex(long min)
min
- the minimum update index for log entries that appear in this
reftable. This should be 1 higher than the prior reftable's
maxUpdateIndex
if this table will be used in a stack.this
public ReftableWriter setMaxUpdateIndex(long max)
max
- the maximum update index for log entries that appear in this
reftable. This should be at least 1 higher than the prior
reftable's maxUpdateIndex
if this table will be used
in a stack.this
public ReftableWriter begin(java.io.OutputStream os) throws java.io.IOException
os
- stream to write the table to. Caller is responsible for
closing the stream after invoking finish()
.this
java.io.IOException
- if reftable header cannot be written.public ReftableWriter sortAndWriteRefs(java.util.Collection<Ref> refsToPack) throws java.io.IOException
refsToPack
- references to sort and write.this
java.io.IOException
- if reftable cannot be written.public void writeRef(Ref ref) throws java.io.IOException
References must be passed in sorted order.
ref
- the reference to store.java.io.IOException
- if reftable cannot be written.public void writeRef(Ref ref, long updateIndex) throws java.io.IOException
References must be passed in sorted order.
ref
- the reference to store.updateIndex
- the updateIndex that modified this reference. Must be
>= minUpdateIndex
for this file.java.io.IOException
- if reftable cannot be written.private void indexRef(Ref ref, long blockPos)
private void indexId(ObjectId id, long blockPos)
public void writeLog(java.lang.String ref, long updateIndex, PersonIdent who, ObjectId oldId, ObjectId newId, @Nullable java.lang.String message) throws java.io.IOException
Reflog entries must be written in reference name and descending
updateIndex
(highest first) order.
ref
- name of the reference.updateIndex
- identifier of the transaction that created the log record. The
updateIndex
must be unique within the scope of
ref
, and must be within the bounds defined by
minUpdateIndex <= updateIndex <= maxUpdateIndex
.who
- committer of the reflog entry.oldId
- prior id; pass ObjectId.zeroId()
for creations.newId
- new id; pass ObjectId.zeroId()
for deletions.message
- optional message (may be null).java.io.IOException
- if reftable cannot be written.public void deleteLog(java.lang.String ref, long updateIndex) throws java.io.IOException
The deletion can shadow an entry stored in a lower table in the stack.
This is useful for refs/stash
and dropping an entry from its
reflog.
Deletion must be properly interleaved in sorted updateIndex order with
any other logs written by
writeLog(String, long, PersonIdent, ObjectId, ObjectId, String)
.
ref
- the ref to delete (hide) a reflog entry from.updateIndex
- the update index that must be hidden.java.io.IOException
- if reftable cannot be written.private void beginLog() throws java.io.IOException
java.io.IOException
public long estimateTotalBytes()
ReftableConfig.setIndexObjects(boolean)
is false
and
ReftableConfig.setMaxIndexLevels(int)
is 1
.public ReftableWriter finish() throws java.io.IOException
this
java.io.IOException
- if reftable cannot be written.private void finishRefAndObjSections() throws java.io.IOException
java.io.IOException
private void writeObjBlocks() throws java.io.IOException
java.io.IOException
private void finishLogSection() throws java.io.IOException
java.io.IOException
private boolean shouldHaveIndex(ReftableWriter.IndexBuilder idx)
private void writeFileHeader()
private void encodeHeader(byte[] hdr)
private void writeFileFooter()
private static long firstBlockPosition(@Nullable ReftableWriter.Section s)
private static long indexPosition(@Nullable ReftableWriter.Section s)
public ReftableWriter.Stats getStats()
private static java.util.List<ReftableWriter.RefList> sortById(ObjectIdSubclassMap<ReftableWriter.RefList> m)
private static int shortestUniqueAbbreviation(java.util.List<ReftableWriter.RefList> in)