Class DfsObjDatabase
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
InMemoryRepository.MemObjDatabase
DfsPackFile
on a storage
system.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Snapshot of packs scanned in a single pass.private static final class
static enum
Sources for a pack file. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DfsObjDatabase.PackList
private Comparator<DfsPackDescription>
private final AtomicReference<DfsObjDatabase.PackList>
private DfsReaderOptions
private final DfsRepository
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DfsObjDatabase
(DfsRepository repository, DfsReaderOptions options) Initialize an object database for our repository. -
Method Summary
Modifier and TypeMethodDescription(package private) void
addPack
(DfsPackFile newPack) (package private) void
addReftable
(DfsPackDescription add, Set<DfsPackDescription> remove) protected void
Clears the cached list of packs, forcing them to be scanned again.void
close()
Close any resources held by this database.protected void
commitPack
(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) Commit a pack and index pair that was written to the DFS.protected abstract void
commitPackImpl
(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) Implementation of pack commit.List currently known pack files in the repository, without scanning.List currently known pack files in the repository, without scanning.List currently known reftable files in the repository, without scanning.Scan and list all available pack files in the repository.getPacks()
Scan and list all available pack files in the repository.Get configured reader options, such as read-ahead.Scan and list all available reftable files in the repository.protected DfsRepository
Get repository owning this object database.boolean
has
(AnyObjectId objectId, boolean avoidUnreachableObjects) Does the requested object exist in this database?protected abstract List<DfsPackDescription>
List the available pack files.Create a newObjectInserter
to insert new objects.protected abstract DfsPackDescription
newPack
(DfsObjDatabase.PackSource source) Generate a new unique name for a pack file.protected DfsPackDescription
newPack
(DfsObjDatabase.PackSource source, long estimatedPackSize) Generate a new unique name for a pack file.Create a newObjectReader
to read existing objects.protected abstract ReadableChannel
openFile
(DfsPackDescription desc, PackExt ext) Open a pack, pack index, or other related file for reading.private static Map<DfsPackDescription,
DfsPackFile> protected Comparator<DfsReftable>
Get comparator to sortDfsReftable
by priority.private static Map<DfsPackDescription,
DfsReftable> protected abstract void
Try to rollback a pack creation.(package private) DfsObjDatabase.PackList
scanPacks
(DfsObjDatabase.PackList original) private DfsObjDatabase.PackList
void
setPackComparator
(Comparator<DfsPackDescription> packComparator) Set the comparator used when searching for objects across packs.protected abstract DfsOutputStream
writeFile
(DfsPackDescription desc, PackExt ext) Open a pack, pack index, or other related file for writing.Methods inherited from class org.eclipse.jgit.lib.ObjectDatabase
create, exists, getApproximateObjectCount, has, newCachedDatabase, open, open
-
Field Details
-
NO_PACKS
-
packList
-
repository
-
readerOptions
-
packComparator
-
-
Constructor Details
-
DfsObjDatabase
Initialize an object database for our repository.- Parameters:
repository
- repository owning this object database.options
- how readers should access the object database.
-
-
Method Details
-
getReaderOptions
Get configured reader options, such as read-ahead.- Returns:
- configured reader options, such as read-ahead.
-
setPackComparator
Set the comparator used when searching for objects across packs.An optimal comparator will find more objects without having to load large idx files from storage only to find that they don't contain the object. See
DfsPackDescription.objectLookupComparator()
for the default heuristics.- Parameters:
packComparator
- comparator.
-
newReader
Create a newObjectReader
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 classObjectDatabase
- Returns:
- reader the caller can use to load objects from this database.
-
newInserter
Create a newObjectInserter
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 classObjectDatabase
- Returns:
- writer the caller can use to create objects in this database.
-
getPacks
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:
IOException
- the pack list cannot be initialized.
-
getReftables
Scan and list all available reftable files in the repository.- Returns:
- list of available reftables. The returned array is shared with the implementation and must not be modified by the caller.
- Throws:
IOException
- the pack list cannot be initialized.
-
getPackList
Scan and list all available pack files in the repository.- Returns:
- list of available packs, with some additional metadata. The returned array is shared with the implementation and must not be modified by the caller.
- Throws:
IOException
- the pack list cannot be initialized.
-
getRepository
Get repository owning this object database.- Returns:
- repository owning this object database.
-
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.
-
getCurrentReftables
List currently known reftable files in the repository, without scanning.- Returns:
- list of available reftables. The returned array is shared with the implementation and must not be modified by the caller.
-
getCurrentPackList
List currently known pack files in the repository, without scanning.- Returns:
- list of available packs, with some additional metadata. The returned array is shared with the implementation and must not be modified by the caller.
-
has
Does the requested object exist in this database?This differs from ObjectDatabase's implementation in that we can selectively ignore unreachable (garbage) objects.
- Parameters:
objectId
- identity of the object to test for existence of.avoidUnreachableObjects
- if true, ignore objects that are unreachable.- Returns:
- true if the specified object is stored in this database.
- Throws:
IOException
- the object store cannot be accessed.
-
newPack
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:
IOException
- a new unique pack description cannot be generated.
-
newPack
protected DfsPackDescription newPack(DfsObjDatabase.PackSource source, long estimatedPackSize) throws IOException Generate a new unique name for a pack file.Default implementation of this method would be equivalent to
newPack(source).setEstimatedPackSize(estimatedPackSize)
. But the clients can override this method to use the givenestomatedPackSize
value more efficiently in the process of creating a newDfsPackDescription
object.- Parameters:
source
- where the pack stream is created.estimatedPackSize
- the estimated size of the pack.- Returns:
- a unique name for the pack file. Must not collide with any other pack file name in the same DFS.
- Throws:
IOException
- a new unique pack description cannot be generated.
-
commitPack
protected void commitPack(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) throws 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:
IOException
- the packs cannot be committed. On failure a rollback must also be attempted by the caller.
-
commitPackImpl
protected abstract void commitPackImpl(Collection<DfsPackDescription> desc, Collection<DfsPackDescription> replaces) throws IOException Implementation of pack commit.- Parameters:
desc
- description of the new packs.replaces
- if not null, list of packs to remove.- Throws:
IOException
- the packs cannot be committed.- See Also:
-
rollbackPack
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
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:
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 FileNotFoundException, 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 fromlistPacks()
, 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:
FileNotFoundException
- the file does not exist.IOException
- the file cannot be opened.
-
writeFile
protected abstract DfsOutputStream writeFile(DfsPackDescription desc, PackExt ext) throws 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 fromnewPack(PackSource)
.ext
- file extension that will be written i.e "pack" or "idx".- Returns:
- channel to write the file.
- Throws:
IOException
- the file cannot be opened.
-
addPack
- Throws:
IOException
-
addReftable
- Throws:
IOException
-
scanPacks
- Throws:
IOException
-
scanPacksImpl
- Throws:
IOException
-
packMap
-
reftableMap
-
reftableComparator
Get comparator to sortDfsReftable
by priority.- Returns:
- comparator to sort
DfsReftable
by priority.
-
clearCache
protected void clearCache()Clears the cached list of packs, forcing them to be scanned again. -
close
public void close()Close any resources held by this database.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classObjectDatabase
-