Class DfsReftableDatabase
- java.lang.Object
-
- org.eclipse.jgit.lib.RefDatabase
-
- org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase
-
- org.eclipse.jgit.internal.storage.dfs.DfsReftableDatabase
-
- Direct Known Subclasses:
InMemoryRepository.MemRefDatabase
public class DfsReftableDatabase extends DfsRefDatabase
ADfsRefDatabase
that uses reftable for storage.A
DfsRefDatabase
instance is thread-safe.Implementors may wish to use
DfsPackDescription.getMaxUpdateIndex()
as the primary key identifier for aPackExt.REFTABLE
only pack description, ensuring that when there are competing transactions one wins, and one will fail.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase
DfsRefDatabase.RefCache
-
-
Field Summary
-
Fields inherited from class org.eclipse.jgit.lib.RefDatabase
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DfsReftableDatabase(DfsRepository repo)
Initialize the reference database for a repository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cachePeeledState(Ref oldLeaf, Ref newLeaf)
Update the cached peeled state of a referenceprotected boolean
compactDuringCommit()
Whether to compact reftable instead of extending the stack depth.protected boolean
compareAndPut(Ref oldRef, Ref newRef)
Compare a reference, and put if it matches.protected boolean
compareAndRemove(Ref oldRef)
Compare a reference, and delete if it matches.Ref
exactRef(String name)
Read a single reference.protected ReentrantLock
getLock()
Get the lock protecting this instance's state.Map<String,Ref>
getRefs(String prefix)
Get a section of the reference namespace.List<Ref>
getRefsByPrefix(String prefix)
Returns refs whose names start with a given prefix.List<Ref>
getRefsByPrefixWithExclusions(String include, Set<String> excludes)
Returns refs whose names start with a given prefix excluding all refs that start with one of the given prefixes.ReftableConfig
getReftableConfig()
Get configuration to write new reftables with.Set<Ref>
getTipsWithSha1(ObjectId id)
Returns all refs that resolve directly to the givenObjectId
.boolean
hasFastTipsWithSha1()
If the ref database does not support fast inverse queries, it may be advantageous to build a complete SHA1 to ref map in advance for multiple uses.boolean
hasVersioning()
With versioning, each reference has a version number that increases on update.boolean
isNameConflicting(String refName)
Determine if a proposed reference name overlaps with an existing one.BatchRefUpdate
newBatchUpdate()
Create a new batch update to attempt on this database.Ref
peel(Ref ref)
Peel a possibly unpeeled reference by traversing the annotated tags.boolean
performsAtomicTransactions()
Whether the database is capable of performing batch updates as atomic transactions.protected DfsRefDatabase.RefCache
scanAllRefs()
Read all known references in the repository.protected DfsReftableStack
stack()
Obtain a handle to the stack of reftables.-
Methods inherited from class org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase
close, create, getAdditionalRefs, getRepository, newRename, newUpdate, refresh
-
Methods inherited from class org.eclipse.jgit.lib.RefDatabase
exactRef, findRef, findRef, firstExactRef, getConflictingNames, getRef, getRefs, getRefsByPrefix, hasRefs
-
-
-
-
Constructor Detail
-
DfsReftableDatabase
protected DfsReftableDatabase(DfsRepository repo)
Initialize the reference database for a repository.- Parameters:
repo
- the repository this database instance manages references for.
-
-
Method Detail
-
hasVersioning
public boolean hasVersioning()
With versioning, each reference has a version number that increases on update. SeeRef.getUpdateIndex()
.- Overrides:
hasVersioning
in classRefDatabase
- Returns:
- true if the implementation assigns update indices to references.
-
performsAtomicTransactions
public boolean performsAtomicTransactions()
Whether the database is capable of performing batch updates as atomic transactions.If true, by default
BatchRefUpdate
instances will perform updates atomically, meaning either all updates will succeed, or all updates will fail. It is still possible to turn off this behavior on a per-batch basis by callingupdate.setAtomic(false)
.If false,
BatchRefUpdate
instances will never perform updates atomically, and callingupdate.setAtomic(true)
will cause the entire batch to fail withREJECTED_OTHER_REASON
.This definition of atomicity is stronger than what is provided by
ReceivePack
.ReceivePack
will attempt to reject all commands if it knows in advance some commands may fail, even if the storage layer does not support atomic transactions. Here, atomicity applies even in the case of unforeseeable errors.- Overrides:
performsAtomicTransactions
in classRefDatabase
- Returns:
- whether transactions are atomic by default.
-
newBatchUpdate
public BatchRefUpdate newBatchUpdate()
Create a new batch update to attempt on this database.The default implementation performs a sequential update of each command.
- Overrides:
newBatchUpdate
in classRefDatabase
- Returns:
- a new batch update object.
-
getReftableConfig
public ReftableConfig getReftableConfig()
Get configuration to write new reftables with.- Returns:
- configuration to write new reftables with.
-
getLock
protected ReentrantLock getLock()
Get the lock protecting this instance's state.- Returns:
- the lock protecting this instance's state.
-
compactDuringCommit
protected boolean compactDuringCommit()
Whether to compact reftable instead of extending the stack depth.- Returns:
true
if commit of a new small reftable should try to replace a prior small reftable by performing a compaction, instead of extending the stack depth.
-
stack
protected DfsReftableStack stack() throws IOException
Obtain a handle to the stack of reftables. Must hold lock.- Returns:
- (possibly cached) handle to the stack.
- Throws:
IOException
- if tables cannot be opened.
-
isNameConflicting
public boolean isNameConflicting(String refName) throws IOException
Description copied from class:DfsRefDatabase
Determine if a proposed reference name overlaps with an existing one.Reference names use '/' as a component separator, and may be stored in a hierarchical storage such as a directory on the local filesystem.
If the reference "refs/heads/foo" exists then "refs/heads/foo/bar" must not exist, as a reference cannot have a value and also be a container for other references at the same time.
If the reference "refs/heads/foo/bar" exists than the reference "refs/heads/foo" cannot exist, for the same reason.
- Overrides:
isNameConflicting
in classDfsRefDatabase
- Parameters:
refName
- proposed name.- Returns:
- true if the name overlaps with an existing reference; false if using this name right now would be safe.
- Throws:
IOException
- the database could not be read to check for conflicts.- See Also:
RefDatabase.getConflictingNames(String)
-
exactRef
public Ref exactRef(String name) throws IOException
Read a single reference.Unlike
RefDatabase.findRef(java.lang.String)
, this method expects an unshortened reference name and does not search using the standardRefDatabase.SEARCH_PATH
.- Overrides:
exactRef
in classDfsRefDatabase
- Parameters:
name
- the unabbreviated name of the reference.- Returns:
- the reference (if it exists); else
null
. - Throws:
IOException
- the reference space cannot be accessed.
-
getRefs
public Map<String,Ref> getRefs(String prefix) throws IOException
Get a section of the reference namespace.- Overrides:
getRefs
in classDfsRefDatabase
- Parameters:
prefix
- prefix to search the namespace with; must end with/
. If the empty string (RefDatabase.ALL
), obtain a complete snapshot of all references.- Returns:
- modifiable map that is a complete snapshot of the current
reference namespace, with
prefix
removed from the start of each key. The map can be an unsorted map. - Throws:
IOException
- the reference space cannot be accessed.
-
getRefsByPrefix
public List<Ref> getRefsByPrefix(String prefix) throws IOException
Returns refs whose names start with a given prefix.The default implementation uses
RefDatabase.getRefs(String)
. Implementors ofRefDatabase
should override this method directly if a better implementation is possible.- Overrides:
getRefsByPrefix
in classRefDatabase
- Parameters:
prefix
- string that names of refs should start with; may be empty (to return all refs).- Returns:
- immutable list of refs whose names start with
prefix
. - Throws:
IOException
- the reference space cannot be accessed.
-
getRefsByPrefixWithExclusions
public List<Ref> getRefsByPrefixWithExclusions(String include, Set<String> excludes) throws IOException
Returns refs whose names start with a given prefix excluding all refs that start with one of the given prefixes.The default implementation is not efficient. Implementors of
RefDatabase
should override this method directly if a better implementation is possible.- Overrides:
getRefsByPrefixWithExclusions
in classRefDatabase
- Parameters:
include
- string that names of refs should start with; may be empty.excludes
- strings that names of refs can't start with; may be empty.- Returns:
- immutable list of refs whose names start with
prefix
and none of the strings inexclude
. - Throws:
IOException
- the reference space cannot be accessed.
-
getTipsWithSha1
public Set<Ref> getTipsWithSha1(ObjectId id) throws IOException
Returns all refs that resolve directly to the givenObjectId
. Includes peeledObjectId
s. This is the inverse lookup ofRefDatabase.exactRef(String...)
.The default implementation uses a linear scan. Implementors of
RefDatabase
should override this method directly if a better implementation is possible.- Overrides:
getTipsWithSha1
in classRefDatabase
- Parameters:
id
-ObjectId
to resolve- Returns:
- a
Set
ofRef
s whose tips point to the provided id. - Throws:
IOException
- the reference space cannot be accessed.
-
hasFastTipsWithSha1
public boolean hasFastTipsWithSha1() throws IOException
If the ref database does not support fast inverse queries, it may be advantageous to build a complete SHA1 to ref map in advance for multiple uses. To let applications decide on this decision, this function indicates whether the inverse map is available.- Overrides:
hasFastTipsWithSha1
in classRefDatabase
- Returns:
- whether this RefDatabase supports fast inverse ref queries.
- Throws:
IOException
- on I/O problems.
-
peel
public Ref peel(Ref ref) throws IOException
Peel a possibly unpeeled reference by traversing the annotated tags.If the reference cannot be peeled (as it does not refer to an annotated tag) the peeled id stays null, but
Ref.isPeeled()
will be true.Implementors should check
Ref.isPeeled()
before performing any additional work effort.- Overrides:
peel
in classDfsRefDatabase
- Parameters:
ref
- The reference to peel- Returns:
ref
ifref.isPeeled()
is true; otherwise a new Ref object representing the same data as Ref, but isPeeled() will be true and getPeeledObjectId() will contain the peeled object (ornull
).- Throws:
IOException
- the reference space or object space cannot be accessed.
-
compareAndPut
protected boolean compareAndPut(Ref oldRef, @Nullable Ref newRef) throws IOException
Compare a reference, and put if it matches.Two reference match if and only if they satisfy the following:
- If one reference is a symbolic ref, the other one should be a symbolic ref.
- If both are symbolic refs, the target names should be same.
- If both are object ID refs, the object IDs should be same.
- Specified by:
compareAndPut
in classDfsRefDatabase
- Parameters:
oldRef
- old value to compare to. If the reference is expected to not exist the old value has a storage ofRef.Storage.NEW
and an ObjectId value ofnull
.newRef
- new reference to store.- Returns:
- true if the put was successful; false otherwise.
- Throws:
IOException
- the reference cannot be put due to a system error.
-
compareAndRemove
protected boolean compareAndRemove(Ref oldRef) throws IOException
Compare a reference, and delete if it matches.- Specified by:
compareAndRemove
in classDfsRefDatabase
- Parameters:
oldRef
- the old reference information that was previously read.- Returns:
- true if the remove was successful; false otherwise.
- Throws:
IOException
- the reference could not be removed due to a system error.
-
scanAllRefs
protected DfsRefDatabase.RefCache scanAllRefs() throws IOException
Read all known references in the repository.- Specified by:
scanAllRefs
in classDfsRefDatabase
- Returns:
- all current references of the repository.
- Throws:
IOException
- references cannot be accessed.
-
cachePeeledState
protected void cachePeeledState(Ref oldLeaf, Ref newLeaf)
Update the cached peeled state of a referenceThe ref database invokes this method after it peels a reference that had not been peeled before. This allows the storage to cache the peel state of the reference, and if it is actually peelable, the target that it peels to, so that on-the-fly peeling doesn't have to happen on the next reference read.
- Overrides:
cachePeeledState
in classDfsRefDatabase
- Parameters:
oldLeaf
- the old reference.newLeaf
- the new reference, with peel information.
-
-