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 ReftableDatabase
private DfsReftableStack
Fields inherited from class org.eclipse.jgit.lib.RefDatabase
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Initialize the reference database for a repository. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cachePeeledState
(Ref oldLeaf, Ref newLeaf) Update the cached peeled state of a reference(package private) void
protected boolean
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.Read a single reference.(package private) boolean
exists()
protected ReentrantLock
getLock()
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
.boolean
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
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.Create a new batch update to attempt on this database.Peel a possibly unpeeled reference by traversing the annotated tags.boolean
Whether the database is capable of performing batch updates as atomic transactions.(package private) void
protected DfsRefDatabase.RefCache
Read all known references in the repository.protected DfsReftableStack
stack()
Obtain a handle to the stack of reftables.(package private) void
Methods inherited from class org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase
close, create, doPeel, getAdditionalRefs, getRepository, newRename, newUpdate, recreate, refresh
Methods 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:
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
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
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:
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
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: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:
-
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:
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
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
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
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
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
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.
-
exists
- Overrides:
exists
in classDfsRefDatabase
- Throws:
IOException
-
clearCache
void clearCache()- Overrides:
clearCache
in 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:
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
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
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.
-
stored
- Overrides:
stored
in classDfsRefDatabase
-
removed
- Overrides:
removed
in 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:
cachePeeledState
in classDfsRefDatabase
- Parameters:
oldLeaf
- the old reference.newLeaf
- the new reference, with peel information.
-