Class DfsObjDatabase

    • Constructor Detail

      • DfsObjDatabase

        protected DfsObjDatabase​(DfsRepository repository,
                                 DfsReaderOptions options)
        Initialize an object database for our repository.
        Parameters:
        repository - repository owning this object database.
        options - how readers should access the object database.
    • Method Detail

      • getReaderOptions

        public DfsReaderOptions getReaderOptions()
        Returns:
        configured reader options, such as read-ahead.
      • newReader

        public ObjectReader newReader()
        Description copied from class: ObjectDatabase
        Create a new ObjectReader to read existing objects.

        The returned reader is not itself thread-safe, but multiple concurrent reader instances created from the same ObjectDatabase must be thread-safe.

        Specified by:
        newReader in class ObjectDatabase
        Returns:
        reader the caller can use to load objects from this database.
      • newInserter

        public ObjectInserter newInserter()
        Description copied from class: ObjectDatabase
        Create a new ObjectInserter to insert new objects.

        The returned inserter is not itself thread-safe, but multiple concurrent inserter instances created from the same ObjectDatabase must be thread-safe.

        Specified by:
        newInserter in class ObjectDatabase
        Returns:
        writer the caller can use to create objects in this database.
      • getPacks

        public DfsPackFile[] getPacks()
                               throws java.io.IOException
        Scan and list all available pack files in the repository.
        Returns:
        list of available packs. The returned array is shared with the implementation and must not be modified by the caller.
        Throws:
        java.io.IOException - the pack list cannot be initialized.
      • getRepository

        protected DfsRepository getRepository()
        Returns:
        repository owning this object database.
      • getCurrentPacks

        public DfsPackFile[] getCurrentPacks()
        List currently known pack files in the repository, without scanning.
        Returns:
        list of available packs. The returned array is shared with the implementation and must not be modified by the caller.
      • newPack

        protected abstract DfsPackDescription newPack​(DfsObjDatabase.PackSource source)
                                               throws java.io.IOException
        Generate a new unique name for a pack file.
        Parameters:
        source - where the pack stream is created.
        Returns:
        a unique name for the pack file. Must not collide with any other pack file name in the same DFS.
        Throws:
        java.io.IOException - a new unique pack description cannot be generated.
      • commitPack

        protected void commitPack​(java.util.Collection<DfsPackDescription> desc,
                                  java.util.Collection<DfsPackDescription> replaces)
                           throws java.io.IOException
        Commit a pack and index pair that was written to the DFS.

        Committing the pack/index pair makes them visible to readers. The JGit DFS code always writes the pack, then the index. This allows a simple commit process to do nothing if readers always look for both files to exist and the DFS performs atomic creation of the file (e.g. stream to a temporary file and rename to target on close).

        During pack compaction or GC the new pack file may be replacing other older files. Implementations should remove those older files (if any) as part of the commit of the new file.

        This method is a trivial wrapper around commitPackImpl(Collection, Collection) that calls the implementation and fires events.

        Parameters:
        desc - description of the new packs.
        replaces - if not null, list of packs to remove.
        Throws:
        java.io.IOException - the packs cannot be committed. On failure a rollback must also be attempted by the caller.
      • commitPackImpl

        protected abstract void commitPackImpl​(java.util.Collection<DfsPackDescription> desc,
                                               java.util.Collection<DfsPackDescription> replaces)
                                        throws java.io.IOException
        Implementation of pack commit.
        Parameters:
        desc - description of the new packs.
        replaces - if not null, list of packs to remove.
        Throws:
        java.io.IOException - the packs cannot be committed.
        See Also:
        commitPack(Collection, Collection)
      • rollbackPack

        protected abstract void rollbackPack​(java.util.Collection<DfsPackDescription> desc)
        Try to rollback a pack creation.

        JGit DFS always writes the pack first, then the index. If the pack does not yet exist, then neither does the index. A safe DFS implementation would try to remove both files to ensure they are really gone.

        A rollback does not support failures, as it only occurs when there is already a failure in progress. A DFS implementor may wish to log warnings/error messages when a rollback fails, but should not send new exceptions up the Java callstack.

        Parameters:
        desc - pack to delete.
      • listPacks

        protected abstract java.util.List<DfsPackDescription> listPacks()
                                                                 throws java.io.IOException
        List the available pack files.

        The returned list must support random access and must be mutable by the caller. It is sorted in place using the natural sorting of the returned DfsPackDescription objects.

        Returns:
        available packs. May be empty if there are no packs.
        Throws:
        java.io.IOException - the packs cannot be listed and the object database is not functional to the caller.
      • openFile

        protected abstract ReadableChannel openFile​(DfsPackDescription desc,
                                                    PackExt ext)
                                             throws java.io.FileNotFoundException,
                                                    java.io.IOException
        Open a pack, pack index, or other related file for reading.
        Parameters:
        desc - description of pack related to the data that will be read. This is an instance previously obtained from listPacks(), but not necessarily from the same DfsObjDatabase instance.
        ext - file extension that will be read i.e "pack" or "idx".
        Returns:
        channel to read the file.
        Throws:
        java.io.FileNotFoundException - the file does not exist.
        java.io.IOException - the file cannot be opened.
      • writeFile

        protected abstract DfsOutputStream writeFile​(DfsPackDescription desc,
                                                     PackExt ext)
                                              throws java.io.IOException
        Open a pack, pack index, or other related file for writing.
        Parameters:
        desc - description of pack related to the data that will be written. This is an instance previously obtained from newPack(PackSource).
        ext - file extension that will be written i.e "pack" or "idx".
        Returns:
        channel to write the file.
        Throws:
        java.io.IOException - the file cannot be opened.
      • clearCache

        protected void clearCache()
        Clears the cached list of packs, forcing them to be scanned again.
      • close

        public void close()
        Description copied from class: ObjectDatabase
        Close any resources held by this database.
        Specified by:
        close in class ObjectDatabase