use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry in project nessie by projectnessie.
the class TxDatabaseAdapter method commitRefLog.
private void commitRefLog(ConnectionWrapper conn, long timeInMicros, Hash commitHash, NamedRef ref, RefLogEntry.Operation operation, List<Hash> sourceHashes) throws SQLException, ReferenceConflictException {
RefLogHead refLogHead = getRefLogHead(conn);
RefLogEntry newRefLog = writeRefLogEntry(conn, ref, refLogHead, commitHash, operation, timeInMicros, sourceHashes);
updateRefLogHead(newRefLog, conn);
}
use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry in project nessie by projectnessie.
the class TxDatabaseAdapter method initializeRepo.
@Override
public void initializeRepo(String defaultBranchName) {
try (ConnectionWrapper conn = borrowConnection()) {
if (!checkNamedRefExistence(conn, BranchName.of(defaultBranchName))) {
// note: no need to initialize the repo-description
insertNewReference(conn, BranchName.of(defaultBranchName), NO_ANCESTOR);
RefLogEntry newRefLog = writeRefLogEntry(conn, BranchName.of(defaultBranchName), RefLogHead.builder().refLogHead(NO_ANCESTOR).addRefLogParentsInclHead(NO_ANCESTOR).build(), NO_ANCESTOR, RefLogEntry.Operation.CREATE_REFERENCE, commitTimeInMicros(), Collections.emptyList());
insertRefLogHead(newRefLog, conn);
conn.commit();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method writeRefLogEntry.
protected RefLogEntry writeRefLogEntry(NonTransactionalOperationContext ctx, GlobalStatePointer pointer, String refName, RefType refType, Hash commitHash, Operation operation, long timeInMicros, List<Hash> sourceHashes) throws ReferenceConflictException {
Hash parentHash = Hash.of(pointer.getRefLogId());
Hash currentRefLogId = randomHash();
Stream<ByteString> newParents;
if (pointer.getRefLogParentsInclHeadCount() == 0 || !pointer.getRefLogId().equals(pointer.getRefLogParentsInclHead(0))) {
// Before Nessie 0.21.0
newParents = Stream.of(parentHash.asBytes());
RefLog currentEntry = fetchFromRefLog(ctx, parentHash);
if (currentEntry != null) {
newParents = Stream.concat(newParents, currentEntry.getParents().stream().limit(config.getParentsPerRefLogEntry() - 1).map(Hash::asBytes));
}
} else {
// Since Nessie 0.21.0
newParents = pointer.getRefLogParentsInclHeadList().stream().limit(config.getParentsPerRefLogEntry());
}
RefLogEntry.Builder entry = RefLogEntry.newBuilder().setRefLogId(currentRefLogId.asBytes()).setRefName(ByteString.copyFromUtf8(refName)).setRefType(refType).setCommitHash(commitHash.asBytes()).setOperationTime(timeInMicros).setOperation(operation);
sourceHashes.forEach(hash -> entry.addSourceHashes(hash.asBytes()));
newParents.forEach(entry::addParents);
RefLogEntry refLogEntry = entry.build();
writeRefLog(ctx, refLogEntry);
return refLogEntry;
}
use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method transplant.
@SuppressWarnings("RedundantThrows")
@Override
public Hash transplant(BranchName targetBranch, Optional<Hash> expectedHead, List<Hash> sequenceToTransplant, Function<ByteString, ByteString> updateCommitMetadata) throws ReferenceNotFoundException, ReferenceConflictException {
try {
return casOpLoop("transplant", targetBranch, CasOpVariant.COMMIT, (ctx, pointer, branchCommits, newKeyLists) -> {
Hash targetHead = branchHead(pointer, targetBranch);
long timeInMicros = commitTimeInMicros();
targetHead = transplantAttempt(ctx, timeInMicros, targetBranch, expectedHead, targetHead, sequenceToTransplant, branchCommits, newKeyLists, updateCommitMetadata);
GlobalStateLogEntry newGlobalHead = writeGlobalCommit(ctx, timeInMicros, pointer, Collections.emptyList());
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, targetBranch.getName(), RefLogEntry.RefType.Branch, targetHead, RefLogEntry.Operation.TRANSPLANT, timeInMicros, sequenceToTransplant);
// Return hash of last commit (targetHead) added to 'targetBranch' (via the casOpLoop)
return updateGlobalStatePointer(targetBranch, pointer, targetHead, newGlobalHead, newRefLog);
}, () -> transplantConflictMessage("Retry-failure", targetBranch, expectedHead, sequenceToTransplant));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method merge.
@Override
public Hash merge(Hash from, BranchName toBranch, Optional<Hash> expectedHead, Function<ByteString, ByteString> updateCommitMetadata) throws ReferenceNotFoundException, ReferenceConflictException {
// creates a new commit-tree that is decoupled from other commit-trees.
try {
return casOpLoop("merge", toBranch, CasOpVariant.COMMIT, (ctx, pointer, branchCommits, newKeyLists) -> {
Hash toHead = branchHead(pointer, toBranch);
long timeInMicros = commitTimeInMicros();
toHead = mergeAttempt(ctx, timeInMicros, from, toBranch, expectedHead, toHead, branchCommits, newKeyLists, updateCommitMetadata);
GlobalStateLogEntry newGlobalHead = writeGlobalCommit(ctx, timeInMicros, pointer, Collections.emptyList());
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, toBranch.getName(), RefLogEntry.RefType.Branch, toHead, RefLogEntry.Operation.MERGE, timeInMicros, Collections.singletonList(from));
// Return hash of last commit (toHead) added to 'targetBranch' (via the casOpLoop)
return updateGlobalStatePointer(toBranch, pointer, toHead, newGlobalHead, newRefLog);
}, () -> mergeConflictMessage("Retry-failure", from, toBranch, expectedHead));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations