- 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
ADfsRefDatabasethat uses reftable for storage.A
DfsRefDatabaseinstance is thread-safe.Implementors may wish to use
DfsPackDescription.getMaxUpdateIndex()as the primary key identifier for aPackExt.REFTABLEonly 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 protectedDfsReftableDatabase(DfsRepository repo)Initialize the reference database for a repository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcachePeeledState(Ref oldLeaf, Ref newLeaf)Update the cached peeled state of a referenceprotected booleancompactDuringCommit()Whether to compact reftable instead of extending the stack depth.protected booleancompareAndPut(Ref oldRef, Ref newRef)Compare a reference, and put if it matches.protected booleancompareAndRemove(Ref oldRef)Compare a reference, and delete if it matches.RefexactRef(String name)Read a single reference.protected ReentrantLockgetLock()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.ReftableConfiggetReftableConfig()Get configuration to write new reftables with.Set<Ref>getTipsWithSha1(ObjectId id)Returns all refs that resolve directly to the givenObjectId.booleanhasFastTipsWithSha1()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.booleanhasVersioning()With versioning, each reference has a version number that increases on update.booleanisNameConflicting(String refName)Determine if a proposed reference name overlaps with an existing one.BatchRefUpdatenewBatchUpdate()Create a new batch update to attempt on this database.Refpeel(Ref ref)Peel a possibly unpeeled reference by traversing the annotated tags.booleanperformsAtomicTransactions()Whether the database is capable of performing batch updates as atomic transactions.protected DfsRefDatabase.RefCachescanAllRefs()Read all known references in the repository.protected DfsReftableStackstack()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:
hasVersioningin 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
BatchRefUpdateinstances 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,
BatchRefUpdateinstances 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.ReceivePackwill 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:
performsAtomicTransactionsin 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:
newBatchUpdatein 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:
trueif 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:DfsRefDatabaseDetermine 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:
isNameConflictingin 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:
exactRefin 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:
getRefsin 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
prefixremoved 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 ofRefDatabaseshould override this method directly if a better implementation is possible.- Overrides:
getRefsByPrefixin 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
RefDatabaseshould override this method directly if a better implementation is possible.- Overrides:
getRefsByPrefixWithExclusionsin 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
prefixand 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 peeledObjectIds. This is the inverse lookup ofRefDatabase.exactRef(String...).The default implementation uses a linear scan. Implementors of
RefDatabaseshould override this method directly if a better implementation is possible.- Overrides:
getTipsWithSha1in classRefDatabase- Parameters:
id-ObjectIdto resolve- Returns:
- a
SetofRefs whose tips point to the provided id. - Throws:
IOException- the reference space cannot be accessed.
-
hasFastTipsWithSha1
public boolean hasFastTipsWithSha1() throws IOExceptionIf 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:
hasFastTipsWithSha1in 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:
peelin classDfsRefDatabase- Parameters:
ref- The reference to peel- Returns:
refifref.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:
compareAndPutin classDfsRefDatabase- Parameters:
oldRef- old value to compare to. If the reference is expected to not exist the old value has a storage ofRef.Storage.NEWand 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:
compareAndRemovein 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:
scanAllRefsin 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:
cachePeeledStatein classDfsRefDatabase- Parameters:
oldLeaf- the old reference.newLeaf- the new reference, with peel information.
-
-