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 class
A segment is a consecutive list of reftables of the same approximate size.private static class
static interface
Writer is a callable that writes data to a reftable under construction. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private MergedReftable
private final Runnable
private static long
private final SecureRandom
private final File
private List<FileReftableStack.StackEntry>
private final File
private final FileReftableStack.CompactionStats
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Tries to add a new reftable to the stack.private void
Heuristically tries to compact the stack if the stack has a suitable shape.private static Optional<FileReftableStack.Segment>
autoCompactCandidate
(long[] sizes) void
close()
(package private) void
private File
compactLocked
(int first, int last) Write the reftable for the given range into a temp file.(package private) boolean
compactRange
(int first, int last) Compacts a range of the stack, following the file locking protocol documented in the spec.private String
filename
(long low, long high) (package private) FileReftableStack.CompactionStats
getStats()
(package private) boolean
(package private) static int
log
(long sz) Calculate an approximate log2.private long
private ReftableConfig
(package private) void
reload()
private void
reloadOnce
(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:
close
in 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
-