Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.file

public Class FileReftableStack

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Static Imports
java.nio.charset.StandardCharsets.UTF_8

A mutable stack of reftables on local filesystem storage. Not thread-safe. This is an AutoCloseable because this object owns the file handles to the open reftables.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
FileReftableStack.Segment

A segment is a consecutive list of reftables of the same approximate size.

private static class
public static interface
FileReftableStack.Writer

Writer is a callable that writes data to a reftable under construction.

Field Summary

Modifier and TypeField and Description
private final Supplier<Config>
private long
private MergedReftable
private final Runnable
private static long
private final SecureRandom
private final File
private AtomicReference<FileSnapshot>
private List<FileReftableStack.StackEntry>
private final File
private final FileReftableStack.CompactionStats
private final CoreConfig.TrustStat

Constructor Summary

AccessConstructor and Description
public
FileReftableStack(File
the filename for the stack.
stackPath
,
File
the dir holding the tables.
reftableDir
,
Runnable
hook to call if we notice a new write
onChange
,
Supplier<Config>
Config supplier
configSupplier
)

Creates a stack corresponding to the list of reftables in the argument

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the transaction was successful.
addReftable
(FileReftableStack.Writer
writer to write data to a reftable under construction
w
)

Tries to add a new reftable to the stack.

private void
autoCompact()

Heuristically tries to compact the stack if the stack has a suitable shape.

private static Optional<FileReftableStack.Segment>
autoCompactCandidate(long[] sizes)

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

pack-priv void
private File

Returns:

the file holding the replacement table.
compactLocked
(int
index of first stack entry to be written
first
,
int
index of last stack entry to be written
last
)

Write the reftable for the given range into a temp file.

pack-priv boolean

Returns:

true if a compaction was successfully applied.
compactRange
(int
index of first stack entry to be considered in compaction
first
,
int
index of last stack entry to be considered in compaction
last
)

Compacts a range of the stack, following the file locking protocol documented in the spec.

private String
filename(long low, long high)

public MergedReftable

Returns:

the merged reftable
getMergedReftable
()

Get merged reftable

pack-priv FileReftableStack.CompactionStats
pack-priv boolean

Returns:

true if the on-disk file corresponds to the in-memory data.
isUpToDate
()

pack-priv static int

Returns:

log2
log
(long
the number to compute an approximate log2 for
sz
)

Calculate an approximate log2.

private long
private List<String>
private ReftableConfig
pack-priv void
private void
reloadOnce(List<String>
holds the names of the tables to load.
names
)

Reloads the stack, potentially reusing opened reftableReaders.

pack-priv static List<FileReftableStack.Segment>
segmentSizes(long[] sizes)

private long[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configSupplierback to summary
private final Supplier<Config> configSupplier
lastNextUpdateIndexback to summary
private long lastNextUpdateIndex
mergedReftableback to summary
private MergedReftable mergedReftable
onChangeback to summary
private final Runnable onChange
OVERHEADback to summary
private static long OVERHEAD
randomback to summary
private final SecureRandom random
reftableDirback to summary
private final File reftableDir
snapshotback to summary
private AtomicReference<FileSnapshot> snapshot
stackback to summary
private List<FileReftableStack.StackEntry> stack
stackPathback to summary
private final File stackPath
statsback to summary
private final FileReftableStack.CompactionStats stats
trustTablesListStatback to summary
private final CoreConfig.TrustStat trustTablesListStat

Constructor Detail

FileReftableStackback to summary
public FileReftableStack(File stackPath, File reftableDir, Runnable onChange, Supplier<Config> configSupplier) throws IOException

Creates a stack corresponding to the list of reftables in the argument

Parameters
stackPath:File

the filename for the stack.

reftableDir:File

the dir holding the tables.

onChange:Runnable

hook to call if we notice a new write

configSupplier:Supplier<Config>

Config supplier

Exceptions
IOException:
on I/O problems

Method Detail

addReftableback to summary
public boolean addReftable(FileReftableStack.Writer w) throws IOException

Tries to add a new reftable to the stack. Returns true if it succeeded, or false if there was a lock failure, due to races with other processes. This is package private so FileReftableDatabase can call into here.

Parameters
w:FileReftableStack.Writer

writer to write data to a reftable under construction

Returns:boolean

true if the transaction was successful.

Annotations
@SuppressWarnings:nls
Exceptions
IOException:
on I/O problems
autoCompactback to summary
private void autoCompact() throws IOException

Heuristically tries to compact the stack if the stack has a suitable shape.

Exceptions
IOException:
if an IO error occurred
autoCompactCandidateback to summary
private static Optional<FileReftableStack.Segment> autoCompactCandidate(long[] sizes)
closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
compactFullyback to summary
pack-priv void compactFully() throws IOException
compactLockedback to summary
private File compactLocked(int first, int last) throws IOException

Write the reftable for the given range into a temp file.

Parameters
first:int

index of first stack entry to be written

last:int

index of last stack entry to be written

Returns:File

the file holding the replacement table.

Exceptions
IOException:
on I/O problem
compactRangeback to summary
pack-priv boolean compactRange(int first, int last) throws IOException

Compacts a range of the stack, following the file locking protocol documented in the spec.

Parameters
first:int

index of first stack entry to be considered in compaction

last:int

index of last stack entry to be considered in compaction

Returns:boolean

true if a compaction was successfully applied.

Exceptions
IOException:
on I/O problem
filenameback to summary
private String filename(long low, long high)
getMergedReftableback to summary
public MergedReftable getMergedReftable()

Get merged reftable

Returns:MergedReftable

the merged reftable

getStatsback to summary
pack-priv FileReftableStack.CompactionStats getStats()
isUpToDateback to summary
pack-priv boolean isUpToDate() throws IOException
Returns:boolean

true if the on-disk file corresponds to the in-memory data.

Exceptions
IOException:
on IO problem
logback to summary
pack-priv static int log(long sz)

Calculate an approximate log2.

Parameters
sz:long

the number to compute an approximate log2 for

Returns:int

log2

nextUpdateIndexback to summary
private long nextUpdateIndex() throws IOException
readTableNamesback to summary
private List<String> readTableNames() throws IOException
reftableConfigback to summary
private ReftableConfig reftableConfig()
reloadback to summary
pack-priv void reload() throws IOException
reloadOnceback to summary
private void reloadOnce(List<String> names) throws IOException, FileNotFoundException

Reloads the stack, potentially reusing opened reftableReaders.

Parameters
names:List<String>

holds the names of the tables to load.

Exceptions
IOException:
on other IO errors.
FileNotFoundException:
load must be retried.
segmentSizesback to summary
pack-priv static List<FileReftableStack.Segment> segmentSizes(long[] sizes)
tableSizesback to summary
private long[] tableSizes() throws IOException
org.eclipse.jgit.internal.storage.file back to summary

pack-priv Class FileReftableStack.CompactionStats

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.FileReftableStack.CompactionStats

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv long
pack-priv int
pack-priv long
pack-priv long
pack-priv long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attemptedback to summary
pack-priv int attempted
bytesback to summary
pack-priv long bytes
failedback to summary
pack-priv int failed
logCountback to summary
pack-priv long logCount
refCountback to summary
pack-priv long refCount
tablesback to summary
pack-priv long tables

Constructor Detail

CompactionStatsback to summary
pack-priv CompactionStats()
org.eclipse.jgit.internal.storage.file back to summary

pack-priv Class FileReftableStack.Segment

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.FileReftableStack.Segment

A segment is a consecutive list of reftables of the same approximate size.

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv int
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Segment(int start, int end, int log, long bytes)

pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv int
size()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

bytesback to summary
pack-priv long bytes
endback to summary
pack-priv int end
logback to summary
pack-priv int log
startback to summary
pack-priv int start

Constructor Detail

Segmentback to summary
pack-priv Segment(int start, int end, int log, long bytes)
Segmentback to summary
pack-priv Segment()

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
sizeback to summary
pack-priv int size()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:boxing
@Override
org.eclipse.jgit.internal.storage.file back to summary

private Class FileReftableStack.StackEntry

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.FileReftableStack.StackEntry

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv ReftableReader

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
pack-priv String name
reftableReaderback to summary
pack-priv ReftableReader reftableReader

Constructor Detail

StackEntryback to summary
private StackEntry()
org.eclipse.jgit.internal.storage.file back to summary

public Interface FileReftableStack.Writer


Writer is a callable that writes data to a reftable under construction. It should set the min/max update index, and then write refs and/or logs. It should not call finish() on the writer.

Method Summary

Modifier and TypeMethod and Description
public void
call(ReftableWriter
writer to use
w
)

Write data to reftable

Method Detail

callback to summary
public void call(ReftableWriter w) throws IOException

Write data to reftable

Parameters
w:ReftableWriter

writer to use

Exceptions
IOException:
if an IO error occurred