public class ObjectDirectory extends FileObjectDatabase
ObjectDatabase.
This is the classical object database representation for a Git repository,
where objects are stored loose by hashing them into directories by their
ObjectId, or are stored in compressed containers
known as PackFiles.
Optionally an object database can reference one or more alternates; other ObjectDatabase instances that are searched in addition to the current database.
Databases are divided into two halves: a half that is considered to be fast
to search (the PackFiles), and a half that is considered to be slow
to search (loose objects). When alternates are present the fast half is fully
searched (recursively through all alternates) before the slow half is
considered.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ObjectDirectory.AlternateHandle |
(package private) static class |
ObjectDirectory.AlternateRepository |
private static class |
ObjectDirectory.PackList |
FileObjectDatabase.InsertLooseObjectResult| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicReference<ObjectDirectory.AlternateHandle[]> |
alternates |
private java.io.File |
alternatesFile |
private Config |
config |
private FS |
fs |
private ObjectDirectory.AlternateHandle |
handle |
private java.io.File |
infoDirectory |
private static org.slf4j.Logger |
LOG |
private static ObjectDirectory.PackList |
NO_PACKS |
private java.io.File |
objects |
private java.io.File |
packDirectory |
private java.util.concurrent.atomic.AtomicReference<ObjectDirectory.PackList> |
packList |
private java.io.File |
preservedDirectory |
private static int |
RESOLVE_ABBREV_LIMIT
Maximum number of candidates offered as resolutions of abbreviation.
|
private java.util.Set<ObjectId> |
shallowCommitsIds |
private java.io.File |
shallowFile |
private FileSnapshot |
shallowFileSnapshot |
private UnpackedObjectCache |
unpackedObjectCache |
| Constructor and Description |
|---|
ObjectDirectory(Config cfg,
java.io.File dir,
java.io.File[] alternatePaths,
FS fs,
java.io.File shallowFile)
Initialize a reference to an on-disk object directory.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) java.util.Set<ObjectDirectory.AlternateHandle.Id> |
addMe(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
void |
close()
Close any resources held by this database.
|
(package private) void |
closeAllPackHandles(java.io.File packFile) |
void |
create()
Initialize a new object database at this location.
|
private boolean |
doLogExponentialBackoff(int n) |
boolean |
exists()
Does this database exist yet?
|
java.io.File |
fileFor(AnyObjectId objectId) |
(package private) ObjectDirectory.AlternateHandle.Id |
getAlternateId() |
(package private) Config |
getConfig() |
java.io.File |
getDirectory() |
(package private) FS |
getFS() |
private long |
getLooseObjectSize(WindowCursor curs,
AnyObjectId id) |
private long |
getLooseSizeFromSelfOrAlternate(WindowCursor curs,
AnyObjectId id,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
(package private) long |
getObjectSize(WindowCursor curs,
AnyObjectId id) |
java.io.File |
getPackDirectory()
Getter for the field
packDirectory. |
private long |
getPackedObjectSize(WindowCursor curs,
AnyObjectId id) |
private long |
getPackedSizeFromSelfOrAlternate(WindowCursor curs,
AnyObjectId id,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
java.util.Collection<PackFile> |
getPacks() |
java.io.File |
getPreservedDirectory()
Getter for the field
preservedDirectory. |
(package private) java.util.Set<ObjectId> |
getShallowCommits() |
private void |
handlePackError(java.io.IOException e,
PackFile p) |
boolean |
has(AnyObjectId objectId)
Does the requested object exist in this database?
|
private boolean |
hasLooseInSelfOrAlternate(AnyObjectId objectId,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
private boolean |
hasPackedInSelfOrAlternate(AnyObjectId objectId,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
(package private) boolean |
hasPackedObject(AnyObjectId objectId) |
private static int |
indexOf(PackFile[] list,
PackFile pack) |
private void |
insertPack(PackFile pf) |
(package private) FileObjectDatabase.InsertLooseObjectResult |
insertUnpackedObject(java.io.File tmp,
ObjectId id,
boolean createDuplicate) |
private java.util.Set<java.lang.String> |
listPackDirectory() |
private ObjectDirectory.AlternateHandle[] |
loadAlternates() |
(package private) ObjectDirectory.AlternateHandle[] |
myAlternates() |
ObjectDatabase |
newCachedDatabase()
Create a new cached database instance over this database.
|
(package private) CachedObjectDirectory |
newCachedFileObjectDatabase() |
ObjectDirectoryInserter |
newInserter()
Create a new
ObjectInserter to insert new objects. |
PackInserter |
newPackInserter()
Create a new inserter that inserts all objects as pack files, not loose
objects.
|
private static java.io.BufferedReader |
open(java.io.File f) |
private ObjectDirectory.AlternateHandle |
openAlternate(java.io.File objdir) |
private ObjectDirectory.AlternateHandle |
openAlternate(java.lang.String location) |
private ObjectLoader |
openLooseFromSelfOrAlternate(WindowCursor curs,
AnyObjectId objectId,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
(package private) ObjectLoader |
openLooseObject(WindowCursor curs,
AnyObjectId id) |
(package private) ObjectLoader |
openObject(WindowCursor curs,
AnyObjectId objectId) |
PackFile |
openPack(java.io.File pack) |
private ObjectLoader |
openPackedFromSelfOrAlternate(WindowCursor curs,
AnyObjectId objectId,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
(package private) ObjectLoader |
openPackedObject(WindowCursor curs,
AnyObjectId objectId) |
private void |
removePack(PackFile deadPack) |
(package private) void |
resolve(java.util.Set<ObjectId> matches,
AbbreviatedObjectId id) |
private void |
resolve(java.util.Set<ObjectId> matches,
AbbreviatedObjectId id,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
private static java.util.Map<java.lang.String,PackFile> |
reuseMap(ObjectDirectory.PackList old) |
private ObjectDirectory.PackList |
scanPacks(ObjectDirectory.PackList original) |
private ObjectDirectory.PackList |
scanPacksImpl(ObjectDirectory.PackList old) |
private boolean |
searchPacksAgain(ObjectDirectory.PackList old) |
(package private) void |
selectObjectRepresentation(PackWriter packer,
ObjectToPack otp,
WindowCursor curs) |
private void |
selectObjectRepresentation(PackWriter packer,
ObjectToPack otp,
WindowCursor curs,
java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) |
java.lang.String |
toString() |
newReaderopen, openprivate static final org.slf4j.Logger LOG
private static final ObjectDirectory.PackList NO_PACKS
private static final int RESOLVE_ABBREV_LIMIT
private final ObjectDirectory.AlternateHandle handle
private final Config config
private final java.io.File objects
private final java.io.File infoDirectory
private final java.io.File packDirectory
private final java.io.File preservedDirectory
private final java.io.File alternatesFile
private final java.util.concurrent.atomic.AtomicReference<ObjectDirectory.PackList> packList
private final FS fs
private final java.util.concurrent.atomic.AtomicReference<ObjectDirectory.AlternateHandle[]> alternates
private final UnpackedObjectCache unpackedObjectCache
private final java.io.File shallowFile
private FileSnapshot shallowFileSnapshot
private java.util.Set<ObjectId> shallowCommitsIds
public ObjectDirectory(Config cfg, java.io.File dir, java.io.File[] alternatePaths, FS fs, java.io.File shallowFile) throws java.io.IOException
cfg - configuration this directory consults for write settings.dir - the location of the objects directory.alternatePaths - a list of alternate object directoriesfs - the file system abstraction which will be necessary to perform
certain file system operations.shallowFile - file which contains IDs of shallow commits, null if shallow
commits handling should be turned offjava.io.IOException - an alternate object cannot be opened.public final java.io.File getDirectory()
getDirectory in class FileObjectDatabasepublic final java.io.File getPackDirectory()
Getter for the field packDirectory.
pack directory.public final java.io.File getPreservedDirectory()
Getter for the field preservedDirectory.
preserved directory.public boolean exists()
exists in class ObjectDatabaseObjectDatabase.create() to create this database location.public void create()
throws java.io.IOException
create in class ObjectDatabasejava.io.IOException - the database could not be created.public ObjectDirectoryInserter newInserter()
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.
newInserter in class FileObjectDatabasepublic PackInserter newPackInserter()
public void close()
close in class ObjectDatabasepublic java.util.Collection<PackFile> getPacks()
getPacks in class FileObjectDatabasepublic PackFile openPack(java.io.File pack) throws java.io.IOException
Add a single existing pack to the list of available pack files.
openPack in class FileObjectDatabasejava.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean has(AnyObjectId objectId)
This is a one-shot call interface which may be faster than allocating a
ObjectDatabase.newReader() to perform the lookup.
has in class ObjectDatabaseobjectId - identity of the object to test for existence of.private boolean hasPackedInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
private boolean hasLooseInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
boolean hasPackedObject(AnyObjectId objectId)
void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id) throws java.io.IOException
resolve in class FileObjectDatabasejava.io.IOExceptionprivate void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
java.io.IOExceptionObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) throws java.io.IOException
openObject in class FileObjectDatabasejava.io.IOExceptionprivate ObjectLoader openPackedFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
private ObjectLoader openLooseFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
java.io.IOExceptionObjectLoader openPackedObject(WindowCursor curs, AnyObjectId objectId)
ObjectLoader openLooseObject(WindowCursor curs, AnyObjectId id) throws java.io.IOException
openLooseObject in class FileObjectDatabasejava.io.IOExceptionlong getObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
getObjectSize in class FileObjectDatabasejava.io.IOExceptionprivate long getPackedSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
private long getLooseSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
java.io.IOExceptionprivate long getPackedObjectSize(WindowCursor curs, AnyObjectId id)
private long getLooseObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
java.io.IOExceptionvoid selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs) throws java.io.IOException
selectObjectRepresentation in class FileObjectDatabasejava.io.IOExceptionprivate void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
java.io.IOExceptionprivate void handlePackError(java.io.IOException e,
PackFile p)
private boolean doLogExponentialBackoff(int n)
n - count of consecutive failuresFileObjectDatabase.InsertLooseObjectResult insertUnpackedObject(java.io.File tmp, ObjectId id, boolean createDuplicate) throws java.io.IOException
insertUnpackedObject in class FileObjectDatabasejava.io.IOExceptionprivate boolean searchPacksAgain(ObjectDirectory.PackList old)
Config getConfig()
getConfig in class FileObjectDatabaseFS getFS()
getFS in class FileObjectDatabasejava.util.Set<ObjectId> getShallowCommits() throws java.io.IOException
getShallowCommits in class FileObjectDatabasejava.io.IOExceptionprivate void insertPack(PackFile pf)
private void removePack(PackFile deadPack)
private ObjectDirectory.PackList scanPacks(ObjectDirectory.PackList original)
private ObjectDirectory.PackList scanPacksImpl(ObjectDirectory.PackList old)
private static java.util.Map<java.lang.String,PackFile> reuseMap(ObjectDirectory.PackList old)
private java.util.Set<java.lang.String> listPackDirectory()
void closeAllPackHandles(java.io.File packFile)
ObjectDirectory.AlternateHandle[] myAlternates()
java.util.Set<ObjectDirectory.AlternateHandle.Id> addMe(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
private ObjectDirectory.AlternateHandle[] loadAlternates() throws java.io.IOException
java.io.IOExceptionprivate static java.io.BufferedReader open(java.io.File f)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionprivate ObjectDirectory.AlternateHandle openAlternate(java.lang.String location) throws java.io.IOException
java.io.IOExceptionprivate ObjectDirectory.AlternateHandle openAlternate(java.io.File objdir) throws java.io.IOException
java.io.IOExceptionpublic java.io.File fileFor(AnyObjectId objectId)
Compute the location of a loose object file.
fileFor in class FileObjectDatabasepublic ObjectDatabase newCachedDatabase()
newCachedDatabase in class ObjectDatabaseCachedObjectDirectory newCachedFileObjectDatabase()
ObjectDirectory.AlternateHandle.Id getAlternateId()