public class DfsReftableDatabase extends DfsRefDatabase
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.
DfsRefDatabase.RefCache
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
Modifier | Constructor and Description |
---|---|
protected |
DfsReftableDatabase(DfsRepository repo)
Initialize the reference database for a repository.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cachePeeledState(Ref oldLeaf,
Ref newLeaf)
Update the cached peeled state of a reference
|
protected 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.
|
ReftableConfig |
getReftableConfig()
Get configuration to write new reftables with.
|
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 Reftable |
reader()
Obtain a handle to the merged reader.
|
protected DfsRefDatabase.RefCache |
scanAllRefs()
Read all known references in the repository.
|
protected ReftableStack |
stack()
Obtain a handle to the stack of reftables.
|
close, create, getAdditionalRefs, getRepository, newRename, newUpdate, refresh
exactRef, findRef, findRef, firstExactRef, getConflictingNames, getRef, getRefs, getRefsByPrefix, hasRefs
protected DfsReftableDatabase(DfsRepository repo)
repo
- the repository this database instance manages references for.public boolean hasVersioning()
Ref.getUpdateIndex()
.hasVersioning
in class RefDatabase
public boolean performsAtomicTransactions()
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 calling update.setAtomic(false)
.
If false, BatchRefUpdate
instances will
never perform updates atomically, and calling
update.setAtomic(true)
will cause the entire batch to fail with
REJECTED_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.
performsAtomicTransactions
in class RefDatabase
public BatchRefUpdate newBatchUpdate()
The default implementation performs a sequential update of each command.
newBatchUpdate
in class RefDatabase
public ReftableConfig getReftableConfig()
protected ReentrantLock getLock()
protected boolean compactDuringCommit()
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.protected Reftable reader() throws IOException
IOException
- if tables cannot be opened.protected ReftableStack stack() throws IOException
IOException
- if tables cannot be opened.public boolean isNameConflicting(String refName) throws IOException
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.
isNameConflicting
in class DfsRefDatabase
refName
- proposed name.IOException
- the database could not be read to check for conflicts.RefDatabase.getConflictingNames(String)
public Ref exactRef(String name) throws IOException
Unlike RefDatabase.findRef(java.lang.String)
, this method expects an unshortened reference
name and does not search using the standard RefDatabase.SEARCH_PATH
.
exactRef
in class DfsRefDatabase
name
- the unabbreviated name of the reference.null
.IOException
- the reference space cannot be accessed.public Map<String,Ref> getRefs(String prefix) throws IOException
getRefs
in class DfsRefDatabase
prefix
- prefix to search the namespace with; must end with /
.
If the empty string (RefDatabase.ALL
), obtain a complete snapshot
of all references.prefix
removed from the start
of each key. The map can be an unsorted map.IOException
- the reference space cannot be accessed.public List<Ref> getRefsByPrefix(String prefix) throws IOException
The default implementation uses RefDatabase.getRefs(String)
. Implementors of
RefDatabase
should override this method directly if a better
implementation is possible.
getRefsByPrefix
in class RefDatabase
prefix
- string that names of refs should start with; may be
empty (to return all refs).prefix
.IOException
- the reference space cannot be accessed.public Ref peel(Ref ref) throws IOException
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.
peel
in class DfsRefDatabase
ref
- The reference to peelref
if ref.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
(or null
).IOException
- the reference space or object space cannot be accessed.protected boolean compareAndPut(Ref oldRef, @Nullable Ref newRef) throws IOException
Two reference match if and only if they satisfy the following:
compareAndPut
in class DfsRefDatabase
oldRef
- old value to compare to. If the reference is expected to not
exist the old value has a storage of
Ref.Storage.NEW
and an ObjectId
value of null
.newRef
- new reference to store.IOException
- the reference cannot be put due to a system error.protected boolean compareAndRemove(Ref oldRef) throws IOException
compareAndRemove
in class DfsRefDatabase
oldRef
- the old reference information that was previously read.IOException
- the reference could not be removed due to a system error.protected DfsRefDatabase.RefCache scanAllRefs() throws IOException
scanAllRefs
in class DfsRefDatabase
IOException
- references cannot be accessed.protected void cachePeeledState(Ref oldLeaf, Ref newLeaf)
The 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.
cachePeeledState
in class DfsRefDatabase
oldLeaf
- the old reference.newLeaf
- the new reference, with peel information.Copyright © 2020 Eclipse JGit Project. All rights reserved.