Class DfsReftableDatabase
- Direct Known Subclasses:
InMemoryRepository.MemRefDatabase
DfsRefDatabase that uses
reftable for storage.
A DfsRefDatabase instance is thread-safe.
Implementors may wish to use
DfsPackDescription.getMaxUpdateIndex()
as the primary key identifier for a
PackExt.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
FieldsModifier and TypeFieldDescriptionprivate DfsReader(package private) final ReftableDatabaseprivate DfsReftableStackFields inherited from class org.eclipse.jgit.lib.RefDatabase
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInitialize the reference database for a repository. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcachePeeledState(Ref oldLeaf, Ref newLeaf) Update the cached peeled state of a reference(package private) voidprotected booleanWhether 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.Read a single reference.(package private) booleanexists()protected ReentrantLockgetLock()Get the lock protecting this instance's state.Get a section of the reference namespace.getRefsByPrefix(String prefix) Returns refs whose names start with a given prefix.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.Get configuration to write new reftables with.Returns all refs that resolve directly to the givenObjectId.booleanIf 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.booleanWith 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.Create a new batch update to attempt on this database.Peel a possibly unpeeled reference by traversing the annotated tags.booleanWhether the database is capable of performing batch updates as atomic transactions.(package private) voidprotected DfsRefDatabase.RefCacheRead all known references in the repository.protected DfsReftableStackstack()Obtain a handle to the stack of reftables.(package private) voidMethods inherited from class org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase
close, create, doPeel, getAdditionalRefs, getRepository, newRename, newUpdate, recreate, refreshMethods inherited from class org.eclipse.jgit.lib.RefDatabase
exactRef, findRef, findRef, firstExactRef, getConflictingNames, getRef, getRefs, getRefsByPrefix, hasRefs
-
Field Details
-
reftableDatabase
-
ctx
-
stack
-
-
Constructor Details
-
DfsReftableDatabase
Initialize the reference database for a repository.- Parameters:
repo- the repository this database instance manages references for.
-
-
Method Details
-
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
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
Get configuration to write new reftables with.- Returns:
- configuration to write new reftables with.
-
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
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
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:
-
exactRef
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
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
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
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
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:
hasFastTipsWithSha1in classRefDatabase- Returns:
- whether this RefDatabase supports fast inverse ref queries.
- Throws:
IOException- on I/O problems.
-
peel
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.
-
exists
- Overrides:
existsin classDfsRefDatabase- Throws:
IOException
-
clearCache
void clearCache()- Overrides:
clearCachein classDfsRefDatabase
-
compareAndPut
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
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
Read all known references in the repository.- Specified by:
scanAllRefsin classDfsRefDatabase- Returns:
- all current references of the repository.
- Throws:
IOException- references cannot be accessed.
-
stored
- Overrides:
storedin classDfsRefDatabase
-
removed
- Overrides:
removedin classDfsRefDatabase
-
cachePeeledState
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.
-