use of org.projectnessie.versioned.ReferenceNotFoundException in project nessie by projectnessie.
the class TxDatabaseAdapter method transplant.
@SuppressWarnings("RedundantThrows")
@Override
public Hash transplant(BranchName targetBranch, Optional<Hash> expectedHead, List<Hash> commits, Function<ByteString, ByteString> updateCommitMetadata) throws ReferenceNotFoundException, ReferenceConflictException {
try {
return opLoop("transplant", targetBranch, false, (conn, currentHead) -> {
long timeInMicros = commitTimeInMicros();
Hash targetHead = transplantAttempt(conn, timeInMicros, targetBranch, expectedHead, currentHead, commits, h -> {
}, h -> {
}, updateCommitMetadata);
Hash resultHash = tryMoveNamedReference(conn, targetBranch, currentHead, targetHead);
commitRefLog(conn, timeInMicros, targetHead, targetBranch, RefLogEntry.Operation.TRANSPLANT, commits);
return resultHash;
}, () -> transplantConflictMessage("Conflict", targetBranch, expectedHead, commits), () -> transplantConflictMessage("Retry-failure", targetBranch, expectedHead, commits));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.ReferenceNotFoundException in project nessie by projectnessie.
the class TxDatabaseAdapter method delete.
@Override
public void delete(NamedRef reference, Optional<Hash> expectedHead) throws ReferenceNotFoundException, ReferenceConflictException {
try {
opLoop("deleteRef", reference, false, (conn, pointer) -> {
verifyExpectedHash(pointer, reference, expectedHead);
Hash commitHash = fetchNamedRefHead(conn, reference);
try (Traced ignore = trace("deleteRefInDb");
PreparedStatement ps = conn.conn().prepareStatement(SqlStatements.DELETE_NAMED_REFERENCE)) {
ps.setString(1, config.getRepositoryId());
ps.setString(2, reference.getName());
ps.setString(3, pointer.asString());
if (ps.executeUpdate() != 1) {
return null;
}
}
commitRefLog(conn, commitTimeInMicros(), commitHash, reference, RefLogEntry.Operation.DELETE_REFERENCE, Collections.emptyList());
return pointer;
}, () -> deleteConflictMessage("Conflict", reference, expectedHead), () -> deleteConflictMessage("Retry-Failure", reference, expectedHead));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.ReferenceNotFoundException in project nessie by projectnessie.
the class TxDatabaseAdapter method assign.
@Override
public void assign(NamedRef assignee, Optional<Hash> expectedHead, Hash assignTo) throws ReferenceNotFoundException, ReferenceConflictException {
try {
opLoop("assignRef", assignee, true, (conn, assigneeHead) -> {
assigneeHead = fetchNamedRefHead(conn, assignee);
verifyExpectedHash(assigneeHead, assignee, expectedHead);
if (!NO_ANCESTOR.equals(assignTo) && fetchFromCommitLog(conn, assignTo) == null) {
throw referenceNotFound(assignTo);
}
Hash resultHash = tryMoveNamedReference(conn, assignee, assigneeHead, assignTo);
commitRefLog(conn, commitTimeInMicros(), assignTo, assignee, RefLogEntry.Operation.ASSIGN_REFERENCE, Collections.singletonList(assigneeHead));
return resultHash;
}, () -> assignConflictMessage("Conflict", assignee, expectedHead, assignTo), () -> assignConflictMessage("Retry-Failure", assignee, expectedHead, assignTo));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.ReferenceNotFoundException in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method commit.
@Override
public Hash commit(CommitAttempt commitAttempt) throws ReferenceConflictException, ReferenceNotFoundException {
try {
return casOpLoop("commit", commitAttempt.getCommitToBranch(), CasOpVariant.COMMIT, (ctx, pointer, x, newKeyLists) -> {
Hash branchHead = branchHead(pointer, commitAttempt.getCommitToBranch());
long timeInMicros = commitTimeInMicros();
CommitLogEntry newBranchCommit = commitAttempt(ctx, timeInMicros, branchHead, commitAttempt, newKeyLists);
GlobalStateLogEntry newGlobalHead = writeGlobalCommit(ctx, timeInMicros, pointer, commitAttempt.getGlobal().entrySet().stream().map(e -> ContentIdAndBytes.of(e.getKey(), e.getValue())).collect(Collectors.toList()));
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, commitAttempt.getCommitToBranch().getName(), RefLogEntry.RefType.Branch, newBranchCommit.getHash(), RefLogEntry.Operation.COMMIT, timeInMicros, Collections.emptyList());
return updateGlobalStatePointer(commitAttempt.getCommitToBranch(), pointer, newBranchCommit.getHash(), newGlobalHead, newRefLog);
}, () -> commitConflictMessage("Retry-Failure", commitAttempt.getCommitToBranch(), commitAttempt.getExpectedHead()));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.ReferenceNotFoundException in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method globalLogFetcher.
private Stream<GlobalStateLogEntry> globalLogFetcher(NonTransactionalOperationContext ctx, GlobalStatePointer pointer) {
if (pointer == null) {
return Stream.empty();
}
// Before Nessie 0.21.0: the global-state-pointer contains the "heads" for the ref-log and
// global-log, so it has to read the head ref-log & global-log to get the IDs of all the
// previous parents to fill the parents in the new global-log-entry & ref-log-entry.
//
// Since Nessie 0.21.0: the global-state-pointer contains the "heads" for the ref-log and
// global-log PLUS the parents of those, so Nessie no longer need to read the head entries
// from the ref-log + global-log.
//
// The check of the first entry is there to ensure backwards compatibility and also
// rolling-upgrades work.
Spliterator<GlobalStateLogEntry> split;
if (pointer.getGlobalParentsInclHeadCount() == 0 || !pointer.getGlobalId().equals(pointer.getGlobalParentsInclHead(0))) {
// Before Nessie 0.21.0
Hash initialId = Hash.of(pointer.getGlobalId());
GlobalStateLogEntry initial = fetchFromGlobalLog(ctx, initialId);
if (initial == null) {
throw new RuntimeException(new ReferenceNotFoundException(String.format("Global log entry '%s' not does not exist.", initialId.asString())));
}
split = logFetcher(ctx, initial, this::fetchPageFromGlobalLog, e -> e.getParentsList().stream().map(Hash::of).collect(Collectors.toList()));
} else {
// Since Nessie 0.21.0
List<Hash> hashes = pointer.getGlobalParentsInclHeadList().stream().map(Hash::of).collect(Collectors.toList());
split = logFetcherWithPage(ctx, hashes, this::fetchPageFromGlobalLog, e -> e.getParentsList().stream().map(Hash::of).collect(Collectors.toList()));
}
return StreamSupport.stream(split, false);
}
Aggregations