Class FileReftableStack

java.lang.Object
org.eclipse.jgit.internal.storage.file.FileReftableStack
All Implemented Interfaces:
AutoCloseable

public class FileReftableStack extends Object implements 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.
  • Field Details

  • 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 write
      configSupplier - Config supplier
      Throws:
      IOException - on I/O problems
  • Method Details

    • getStats

    • reloadOnce

      private void reloadOnce(List<String> names) throws IOException, FileNotFoundException
      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

      void reload() throws IOException
      Throws:
      IOException
    • getMergedReftable

      public MergedReftable getMergedReftable()
      Returns:
      the merged reftable
    • readTableNames

      private List<String> readTableNames() throws IOException
      Throws:
      IOException
    • isUpToDate

      boolean isUpToDate() throws IOException
      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 interface AutoCloseable
    • nextUpdateIndex

      private long nextUpdateIndex() throws IOException
      Throws:
      IOException
    • filename

      private String filename(long low, long high)
    • addReftable

      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 - writer to write data to a reftable under construction
      Returns:
      true if the transaction was successful.
      Throws:
      IOException - on I/O problems
    • reftableConfig

      private ReftableConfig reftableConfig()
    • compactLocked

      private File compactLocked(int first, int last) throws IOException
      Write the reftable for the given range into a temp file.
      Parameters:
      first - index of first stack entry to be written
      last - index of last stack entry to be written
      Returns:
      the file holding the replacement table.
      Throws:
      IOException - on I/O problem
    • compactRange

      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 - index of first stack entry to be considered in compaction
      last - 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

      static List<FileReftableStack.Segment> segmentSizes(long[] sizes)
    • autoCompactCandidate

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

      private void autoCompact() throws IOException
      Heuristically tries to compact the stack if the stack has a suitable shape.
      Throws:
      IOException
    • tableSizes

      private long[] tableSizes() throws IOException
      Throws:
      IOException
    • compactFully

      void compactFully() throws IOException
      Throws:
      IOException