Interface DatabaseAdapter
-
- All Known Implementing Classes:
AbstractDatabaseAdapter,TracingDatabaseAdapter
public interface DatabaseAdapterDatabase-Adapter interface that encapsulates all database related logic, an abstraction between aVersionStoreimplementation and a variety of different databases that share common core implementations for example for the commit/merge/transplant operations.One or more adapter instances may use the same storage (database instance / schema). In this case adapter instances usually differ by their
repository IDconfiguration parameters.Database-adapters treat the actual "Nessie content" and "Nessie commit metadata" as an opaque value ("BLOB") without interpreting the content. Database-adapter must persist serialized values for commit-metadata and content as is and must return those in the exact same representation on read.
Actual implementation usually extend either
org.projectnessie.versioned.persist.nontx.NonTxDatabaseAdapter(NoSQL databases) ororg.projectnessie.versioned.persist.tx.TxDatabaseAdapter(JDBC/transactional). Both in turn extendAbstractDatabaseAdapter.All returned
Streams must be closed.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidassertCleanStateForTests()voidassign(org.projectnessie.versioned.NamedRef assignee, java.util.Optional<org.projectnessie.versioned.Hash> expectedHead, org.projectnessie.versioned.Hash assignTo)Updatesassignee's HEAD toassignTo.org.projectnessie.versioned.Hashcommit(CommitParams commitParams)Commit operation, seeCommitParamsfor a description of the parameters.java.util.stream.Stream<CommitLogEntry>commitLog(org.projectnessie.versioned.Hash offset)Retrieve the commit-log starting at the commit referenced byoffset.booleanconsistentPutAttachment(org.projectnessie.versioned.ContentAttachment attachment, java.util.Optional<java.lang.String> expectedVersion)Consistent put-attachment operation.org.projectnessie.versioned.Hashcreate(org.projectnessie.versioned.NamedRef ref, org.projectnessie.versioned.Hash target)Create a new named reference.org.projectnessie.versioned.Hashdelete(org.projectnessie.versioned.NamedRef reference, java.util.Optional<org.projectnessie.versioned.Hash> expectedHead)Delete the given reference.voiddeleteAttachments(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey> keys)Unconditionally delete the content attachments identified viakeys.java.util.stream.Stream<Difference>diff(org.projectnessie.versioned.Hash from, org.projectnessie.versioned.Hash to, KeyFilterPredicate keyFilter)Compute the difference of the content for the two commits identified byfromandto.voideraseRepo()Forces all repository data managed by this adapter instance to be deleted.java.util.stream.Stream<CommitLogEntry>fetchCommitLogEntries(java.util.stream.Stream<org.projectnessie.versioned.Hash> hashes)Loads commit log entries.RepoDescriptionfetchRepositoryDescription()Fetches the current version and descriptive attributes of the repository.java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey>getAttachmentKeys(java.lang.String contentId)Retrieve the known attachment keys for a content ID.DatabaseAdapterConfiggetConfig()java.util.Optional<ContentIdAndBytes>globalContent(ContentId contentId)Retrieves the global content for the given contents-id.org.projectnessie.versioned.HashhashOnReference(org.projectnessie.versioned.NamedRef namedReference, java.util.Optional<org.projectnessie.versioned.Hash> hashOnReference)Verifies that the givennamedReferenceexists and thathashOnReference, if present, is reachable via that reference.voidinitializeRepo(java.lang.String defaultBranchName)Ensures that mandatory data is present in the repository, does not change an existing repo.java.util.stream.Stream<KeyListEntry>keys(org.projectnessie.versioned.Hash commit, KeyFilterPredicate keyFilter)Retrieve the content-keys that are "present" for the specified commit.java.util.stream.Stream<org.projectnessie.versioned.ContentAttachment>mapToAttachment(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey> keys)Retrieve the content attachments identified viakeys.org.projectnessie.versioned.MergeResult<CommitLogEntry>merge(MergeParams mergeParams)Merge all commits onfromsince the common ancestor offromandtoand commit those ontoto.org.projectnessie.versioned.ReferenceInfo<com.google.protobuf.ByteString>namedRef(java.lang.String ref, org.projectnessie.versioned.GetNamedRefsParams params)Resolve the current HEAD of the given named-reference and optionally additional information.java.util.stream.Stream<org.projectnessie.versioned.ReferenceInfo<com.google.protobuf.ByteString>>namedRefs(org.projectnessie.versioned.GetNamedRefsParams params)Get all named references including their current HEAD.org.projectnessie.versioned.HashnoAncestorHash()Get theHashfor "beginning of time".voidputAttachments(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachment> attachments)Bulk-write the given content attachments.CommitLogEntryrebuildKeyList(CommitLogEntry entry, java.util.function.Function<org.projectnessie.versioned.Hash,CommitLogEntry> inMemoryCommits)Populates the aggregated key-list for the givenentryand returns it.java.util.stream.Stream<RefLog>refLog(org.projectnessie.versioned.Hash offset)Retrieve the refLog starting at the refLog referenced byoffset.java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>repoMaintenance(RepoMaintenanceParams repoMaintenanceParams)java.util.stream.Stream<CommitLogEntry>scanAllCommitLogEntries()Scan all commit log entries, no guarantees about order nor about the behavior when commits happen while the returnedStreamis consumed.org.projectnessie.versioned.MergeResult<CommitLogEntry>transplant(TransplantParams transplantParams)Cherry-pick the commits with the hashessequenceToTransplantfrom named referencesourceonto the referencetargetBranch.voidupdateMultipleCommits(java.util.List<CommitLogEntry> commitLogEntries)Updates multiple commit-entries, the given commit entries are to be persisted as is.voidupdateRepositoryDescription(java.util.function.Function<RepoDescription,RepoDescription> updater)Updates the repository description.java.util.Map<org.projectnessie.versioned.Key,ContentAndState>values(org.projectnessie.versioned.Hash commit, java.util.Collection<org.projectnessie.versioned.Key> keys, KeyFilterPredicate keyFilter)Retrieve the reference-local and global state for the given keys for the specified commit.voidwriteMultipleCommits(java.util.List<CommitLogEntry> commitLogEntries)Write multiple new commit-entries, the given commit entries are to be persisted as is.
-
-
-
Method Detail
-
getConfig
DatabaseAdapterConfig getConfig()
-
initializeRepo
void initializeRepo(java.lang.String defaultBranchName)
Ensures that mandatory data is present in the repository, does not change an existing repo.
-
eraseRepo
void eraseRepo()
Forces all repository data managed by this adapter instance to be deleted.This includes all data for the configured
repository ID.After erasing a repository
initializeRepo(String)may be called to reinitialize the minimal required data structures for the same repository ID.
-
noAncestorHash
org.projectnessie.versioned.Hash noAncestorHash()
Get theHashfor "beginning of time".
-
hashOnReference
org.projectnessie.versioned.Hash hashOnReference(org.projectnessie.versioned.NamedRef namedReference, java.util.Optional<org.projectnessie.versioned.Hash> hashOnReference) throws org.projectnessie.versioned.ReferenceNotFoundExceptionVerifies that the givennamedReferenceexists and thathashOnReference, if present, is reachable via that reference.- Returns:
- verified
hashOnReferenceor, ifhashOnReferenceis not present, the current HEAD ofnamedReference - Throws:
org.projectnessie.versioned.ReferenceNotFoundException- ifnamedReferencedoes not exist orhashOnReference, if present, is not reachable from that reference
-
values
java.util.Map<org.projectnessie.versioned.Key,ContentAndState> values(org.projectnessie.versioned.Hash commit, java.util.Collection<org.projectnessie.versioned.Key> keys, KeyFilterPredicate keyFilter) throws org.projectnessie.versioned.ReferenceNotFoundException
Retrieve the reference-local and global state for the given keys for the specified commit.- Parameters:
commit- commit to retrieve the values for.keys- keys to retrieve the values (reference-local and global) forkeyFilter- predicate to optionally skip specific keys in the result and return those as"not present", for example to implement a security policy.- Returns:
- Ordered stream
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- ifcommitdoes not exist.
-
commitLog
@MustBeClosed java.util.stream.Stream<CommitLogEntry> commitLog(org.projectnessie.versioned.Hash offset) throws org.projectnessie.versioned.ReferenceNotFoundException
Retrieve the commit-log starting at the commit referenced byoffset.- Parameters:
offset- hash to start at- Returns:
- stream of
CommitLogEntrys - Throws:
org.projectnessie.versioned.ReferenceNotFoundException- ifoffsetdoes not exist.
-
fetchCommitLogEntries
@MustBeClosed java.util.stream.Stream<CommitLogEntry> fetchCommitLogEntries(java.util.stream.Stream<org.projectnessie.versioned.Hash> hashes)
Loads commit log entries.- Returns:
- the loaded
CommitLogEntrys, non-existing entries will not be returned.
-
keys
@MustBeClosed java.util.stream.Stream<KeyListEntry> keys(org.projectnessie.versioned.Hash commit, KeyFilterPredicate keyFilter) throws org.projectnessie.versioned.ReferenceNotFoundException
Retrieve the content-keys that are "present" for the specified commit.- Parameters:
commit- commit to retrieve the values for.keyFilter- predicate to optionally skip specific keys in the result and return those as"not present", for example to implement a security policy.- Returns:
- Ordered stream with content-keys, content-ids and content-types
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- ifcommitdoes not exist.
-
commit
org.projectnessie.versioned.Hash commit(CommitParams commitParams) throws org.projectnessie.versioned.ReferenceConflictException, org.projectnessie.versioned.ReferenceNotFoundException
Commit operation, seeCommitParamsfor a description of the parameters.- Parameters:
commitParams- parameters for the commit- Returns:
- optimistically written commit-log-entry
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if either the named reference inToBranchParams.getToBranch()or the commit on that reference, if specified, does not exist.org.projectnessie.versioned.ReferenceConflictException- if any of the commits could not be committed onto the target branch due to a conflicting change or if the expected hash inToBranchParams.getToBranch()is not its expected hEAD
-
transplant
org.projectnessie.versioned.MergeResult<CommitLogEntry> transplant(TransplantParams transplantParams) throws org.projectnessie.versioned.ReferenceNotFoundException, org.projectnessie.versioned.ReferenceConflictException
Cherry-pick the commits with the hashessequenceToTransplantfrom named referencesourceonto the referencetargetBranch.- Returns:
- the hash of the last cherry-picked commit, in other words the new HEAD of the target branch
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if either the named reference incommitOnReferenceor the commit on that reference, if specified, does not exist.org.projectnessie.versioned.ReferenceConflictException- if any of the commits could not be committed onto the target branch due to a conflicting change or if the expected hash oftoBranchis not its expected hEAD
-
merge
org.projectnessie.versioned.MergeResult<CommitLogEntry> merge(MergeParams mergeParams) throws org.projectnessie.versioned.ReferenceNotFoundException, org.projectnessie.versioned.ReferenceConflictException
Merge all commits onfromsince the common ancestor offromandtoand commit those ontoto.The implementation first identifies the common-ancestor (the most-recent commit that is both reachable via
fromandto).- Returns:
- the hash of the last cherry-picked commit, in other words the new HEAD of the target branch
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if either the named reference intoBranchor the commit on that reference, if specified, does not exist.org.projectnessie.versioned.ReferenceConflictException- if any of the commits could not be committed onto the target branch due to a conflicting change or if the expected hash oftoBranchis not its expected hEAD
-
namedRef
org.projectnessie.versioned.ReferenceInfo<com.google.protobuf.ByteString> namedRef(java.lang.String ref, org.projectnessie.versioned.GetNamedRefsParams params) throws org.projectnessie.versioned.ReferenceNotFoundExceptionResolve the current HEAD of the given named-reference and optionally additional information.This is actually a convenience for
hashOnReference(ref, Optional.empty().- Parameters:
ref- named reference to resolveparams- options that control which information shall be returned inReferenceInfo, seeGetNamedRefsParamsfor details.- Returns:
- current HEAD of
ref - Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if the named referencerefdoes not exist.
-
namedRefs
@MustBeClosed java.util.stream.Stream<org.projectnessie.versioned.ReferenceInfo<com.google.protobuf.ByteString>> namedRefs(org.projectnessie.versioned.GetNamedRefsParams params) throws org.projectnessie.versioned.ReferenceNotFoundExceptionGet all named references including their current HEAD.- Parameters:
params- options that control which information shall be returned in eachReferenceInfo, seeReferenceInfofor details.- Returns:
- stream with all named references.
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException
-
create
org.projectnessie.versioned.Hash create(org.projectnessie.versioned.NamedRef ref, org.projectnessie.versioned.Hash target) throws org.projectnessie.versioned.ReferenceAlreadyExistsException, org.projectnessie.versioned.ReferenceNotFoundExceptionCreate a new named reference.- Parameters:
ref- Named reference to create - either aBranchNameorTagName.target- The already existing named reference with an optional hash on that branch. This parameter can benullfor the edge case when the default branch is re-created after it has been dropped.- Returns:
- the current HEAD of the created branch or tag
- Throws:
org.projectnessie.versioned.ReferenceAlreadyExistsException- if the referencerefalready exists.org.projectnessie.versioned.ReferenceNotFoundException- iftargetdoes not exist.
-
delete
org.projectnessie.versioned.Hash delete(org.projectnessie.versioned.NamedRef reference, java.util.Optional<org.projectnessie.versioned.Hash> expectedHead) throws org.projectnessie.versioned.ReferenceNotFoundException, org.projectnessie.versioned.ReferenceConflictExceptionDelete the given reference.- Parameters:
reference- named-reference to delete. If a value for the hash is specified, it must be equal to the current HEAD.expectedHead- if present,reference's current HEAD must be equal to this value- Returns:
- head of deleted reference
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if the named reference inreferencedoes not exist.org.projectnessie.versioned.ReferenceConflictException- if the named reference's HEAD is not equal to the expected HEAD
-
assign
void assign(org.projectnessie.versioned.NamedRef assignee, java.util.Optional<org.projectnessie.versioned.Hash> expectedHead, org.projectnessie.versioned.Hash assignTo) throws org.projectnessie.versioned.ReferenceNotFoundException, org.projectnessie.versioned.ReferenceConflictExceptionUpdatesassignee's HEAD toassignTo.- Parameters:
assignee- named reference to re-assignexpectedHead- if present,assignee's current HEAD must be equal to this valueassignTo- commit to updateassignee's HEAD to- Throws:
org.projectnessie.versioned.ReferenceNotFoundException- if either the named reference inassignToor the commit on that reference, if specified, does not exist or if the named reference specified inassigneedoes not exist.org.projectnessie.versioned.ReferenceConflictException- if the HEAD of the named referenceassigneeis not equal to the expected HEAD
-
diff
@MustBeClosed java.util.stream.Stream<Difference> diff(org.projectnessie.versioned.Hash from, org.projectnessie.versioned.Hash to, KeyFilterPredicate keyFilter) throws org.projectnessie.versioned.ReferenceNotFoundException
Compute the difference of the content for the two commits identified byfromandto.- Parameters:
from-"From"side of the diffto-"To" sideof the diffkeyFilter- predicate to optionally skip specific keys in the diff result and not return those, for example to implement a security policy.- Returns:
- stream containing the difference of the content, excluding both equal values and values
that were excluded via
keyFilter - Throws:
org.projectnessie.versioned.ReferenceNotFoundException- iffromortodoes not exist.
-
fetchRepositoryDescription
RepoDescription fetchRepositoryDescription()
Fetches the current version and descriptive attributes of the repository.
-
updateRepositoryDescription
void updateRepositoryDescription(java.util.function.Function<RepoDescription,RepoDescription> updater) throws org.projectnessie.versioned.ReferenceConflictException
Updates the repository description. Takes a function that receives the current repository description and returns the updated description.- Parameters:
updater- updater function, the input argument is nevernull, ifupdaterreturnnull, the update will be aborted- Throws:
org.projectnessie.versioned.ReferenceConflictException- thrown if the repository description could not be updated due to other concurrent updates
-
globalContent
java.util.Optional<ContentIdAndBytes> globalContent(ContentId contentId)
Retrieves the global content for the given contents-id.- Parameters:
contentId- contents-id to retrieve the global content for- Returns:
- global content, if present or an empty optional, never
null.
-
repoMaintenance
java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> repoMaintenance(RepoMaintenanceParams repoMaintenanceParams)
-
refLog
@MustBeClosed java.util.stream.Stream<RefLog> refLog(org.projectnessie.versioned.Hash offset) throws org.projectnessie.versioned.RefLogNotFoundException
Retrieve the refLog starting at the refLog referenced byoffset.- Parameters:
offset- initial reflog id to read from- Returns:
- stream of
RefLogs - Throws:
org.projectnessie.versioned.RefLogNotFoundException
-
scanAllCommitLogEntries
@MustBeClosed java.util.stream.Stream<CommitLogEntry> scanAllCommitLogEntries()
Scan all commit log entries, no guarantees about order nor about the behavior when commits happen while the returnedStreamis consumed.
-
getAttachmentKeys
@MustBeClosed java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey> getAttachmentKeys(java.lang.String contentId)
Retrieve the known attachment keys for a content ID.Implementations may return keys that do not or no longer exist. Especially non-transactional database adapter implementations allow this as a compromise. See
mapToAttachment(Stream), which only returns existing content attachments.
-
mapToAttachment
@MustBeClosed java.util.stream.Stream<org.projectnessie.versioned.ContentAttachment> mapToAttachment(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey> keys)
Retrieve the content attachments identified viakeys. Attachments that do not exist are not returned.Whether the input stream is "terminated" or "fluently" mapped, can vary between implementations.
-
consistentPutAttachment
boolean consistentPutAttachment(org.projectnessie.versioned.ContentAttachment attachment, java.util.Optional<java.lang.String> expectedVersion)Consistent put-attachment operation.Either a "put-if-absent", if
expectedVersionis empty or a compare-and-swap based on the value ofexpectedVersion.Note: this method uses conditional put operations, unlike
putAttachments(Stream). Users should not use this method andputAttachments(Stream)for the same keys.- Parameters:
attachment- the attachment to writeexpectedVersion- indicator for put-if-absent or the expected value on an existing item
-
putAttachments
void putAttachments(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachment> attachments)
Bulk-write the given content attachments. The values of attachments written with this method should be immutable and deterministic for the respective attachment keys.The behavior of the implementation whether an already existing attachment will be overwritten or not is undefined.
The outcome of this method is undefined when an error occurred.
Note: this method uses unconditional put operations, unlike
consistentPutAttachment(ContentAttachment, Optional). Should not use this method andconsistentPutAttachment(ContentAttachment, Optional)for the same keys.
-
deleteAttachments
void deleteAttachments(java.util.stream.Stream<org.projectnessie.versioned.ContentAttachmentKey> keys)
Unconditionally delete the content attachments identified viakeys.
-
assertCleanStateForTests
void assertCleanStateForTests()
-
writeMultipleCommits
void writeMultipleCommits(java.util.List<CommitLogEntry> commitLogEntries) throws org.projectnessie.versioned.ReferenceConflictException
Write multiple new commit-entries, the given commit entries are to be persisted as is. All values of the givenCommitLogEntrycan be considered valid and consistent.Callers must call
updateMultipleCommits(List)for already existingCommitLogEntrys andwriteMultipleCommits(List)for newCommitLogEntrys. Implementations can rely on this assumption (think: SQLINSERT+UPDATEcompared to a "simple put" for NoSQL databases).Implementations however can enforce strict consistency checks/guarantees, like a best-effort approach to prevent hash-collisions but without any other consistency checks/guarantees.
- Throws:
org.projectnessie.versioned.ReferenceConflictException
-
updateMultipleCommits
void updateMultipleCommits(java.util.List<CommitLogEntry> commitLogEntries) throws org.projectnessie.versioned.ReferenceNotFoundException
Updates multiple commit-entries, the given commit entries are to be persisted as is. All values of the givenCommitLogEntrycan be considered valid and consistent.Callers must call
updateMultipleCommits(List)for already existingCommitLogEntrys andwriteMultipleCommits(List)for newCommitLogEntrys. Implementations can rely on this assumption (think: SQLINSERT+UPDATEcompared to a "simple put" for NoSQL databases).Implementations however can enforce strict consistency checks/guarantees.
- Throws:
org.projectnessie.versioned.ReferenceNotFoundException
-
rebuildKeyList
CommitLogEntry rebuildKeyList(CommitLogEntry entry, @Nonnull @Nonnull java.util.function.Function<org.projectnessie.versioned.Hash,CommitLogEntry> inMemoryCommits) throws org.projectnessie.versioned.ReferenceNotFoundException
Populates the aggregated key-list for the givenentryand returns it.- Parameters:
entry- theCommitLogEntryto build the aggregated key list forinMemoryCommits- function to retrieve not-yet-written commit-log-entries- Returns:
- commit-log-entry with the aggregated key-list. The returned
CommitLogEntryhas not been persisted. - Throws:
org.projectnessie.versioned.ReferenceNotFoundException
-
-