Class FileReftableStack
java.lang.Object
org.eclipse.jgit.internal.storage.file.FileReftableStack
- All Implemented Interfaces:
AutoCloseable
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 Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static classA segment is a consecutive list of reftables of the same approximate size.private static classstatic interfaceWriter is a callable that writes data to a reftable under construction. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate MergedReftableprivate final Runnableprivate static longprivate final SecureRandomprivate final Fileprivate List<FileReftableStack.StackEntry>private final Fileprivate final FileReftableStack.CompactionStats -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTries to add a new reftable to the stack.private voidHeuristically tries to compact the stack if the stack has a suitable shape.private static Optional<FileReftableStack.Segment>autoCompactCandidate(long[] sizes) voidclose()(package private) voidprivate FilecompactLocked(int first, int last) Write the reftable for the given range into a temp file.(package private) booleancompactRange(int first, int last) Compacts a range of the stack, following the file locking protocol documented in the spec.private Stringfilename(long low, long high) (package private) FileReftableStack.CompactionStatsgetStats()(package private) boolean(package private) static intlog(long sz) Calculate an approximate log2.private longprivate ReftableConfig(package private) voidreload()private voidreloadOnce(List<String> names) Reloads the stack, potentially reusing opened reftableReaders.(package private) static List<FileReftableStack.Segment>segmentSizes(long[] sizes) private long[]
-
Field Details
-
mergedReftable
-
stack
-
lastNextUpdateIndex
private long lastNextUpdateIndex -
stackPath
-
reftableDir
-
onChange
-
random
-
configSupplier
-
stats
-
OVERHEAD
private static long OVERHEAD
-
-
Constructor Details
-
FileReftableStack
public FileReftableStack(File stackPath, File reftableDir, @Nullable Runnable onChange, Supplier<Config> configSupplier) throws IOException Creates a stack corresponding to the list of reftables in the argument- Parameters:
stackPath- the filename for the stack.reftableDir- the dir holding the tables.onChange- hook to call if we notice a new writeconfigSupplier- Config supplier- Throws:
IOException- on I/O problems
-
-
Method Details
-
getStats
FileReftableStack.CompactionStats getStats() -
reloadOnce
Reloads the stack, potentially reusing opened reftableReaders.- Parameters:
names- holds the names of the tables to load.- Throws:
FileNotFoundException- load must be retried.IOException- on other IO errors.
-
reload
- Throws:
IOException
-
getMergedReftable
- Returns:
- the merged reftable
-
readTableNames
- Throws:
IOException
-
isUpToDate
- Returns:
- true if the on-disk file corresponds to the in-memory data.
- Throws:
IOException- on IO problem
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
nextUpdateIndex
- Throws:
IOException
-
filename
-
addReftable
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- writer to write data to a reftable under construction- Returns:
- true if the transaction was successful.
- Throws:
IOException- on I/O problems
-
reftableConfig
-
compactLocked
Write the reftable for the given range into a temp file.- Parameters:
first- index of first stack entry to be writtenlast- index of last stack entry to be written- Returns:
- the file holding the replacement table.
- Throws:
IOException- on I/O problem
-
compactRange
Compacts a range of the stack, following the file locking protocol documented in the spec.- Parameters:
first- index of first stack entry to be considered in compactionlast- index of last stack entry to be considered in compaction- Returns:
- true if a compaction was successfully applied.
- Throws:
IOException- on I/O problem
-
log
static int log(long sz) Calculate an approximate log2.- Parameters:
sz-- Returns:
- log2
-
segmentSizes
-
autoCompactCandidate
-
autoCompact
Heuristically tries to compact the stack if the stack has a suitable shape.- Throws:
IOException
-
tableSizes
- Throws:
IOException
-
compactFully
- Throws:
IOException
-