use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method create.
@Override
public Hash create(NamedRef ref, Hash target) throws ReferenceAlreadyExistsException, ReferenceNotFoundException {
try {
return casOpLoop("createRef", ref, CasOpVariant.REF_UPDATE, (ctx, pointer, branchCommits, newKeyLists) -> {
if (refFromGlobalState(pointer, ref.getName()) != null) {
throw referenceAlreadyExists(ref);
}
Hash hash = target;
if (hash == null) {
// Special case: Don't validate, if the 'target' parameter is null.
// This is mostly used for tests that re-create the default-branch.
hash = NO_ANCESTOR;
}
validateHashExists(ctx, hash);
// Need a new empty global-log entry to be able to CAS
GlobalStateLogEntry newGlobalHead = noopGlobalLogEntry(ctx, pointer);
RefLogEntry.RefType refType = ref instanceof TagName ? RefLogEntry.RefType.Tag : RefLogEntry.RefType.Branch;
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, ref.getName(), refType, hash, RefLogEntry.Operation.CREATE_REFERENCE, commitTimeInMicros(), Collections.emptyList());
return updateGlobalStatePointer(ref, pointer, hash, newGlobalHead, newRefLog);
}, () -> createConflictMessage("Retry-Failure", ref, target));
} catch (ReferenceAlreadyExistsException | ReferenceNotFoundException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method assign.
@Override
public void assign(NamedRef assignee, Optional<Hash> expectedHead, Hash assignTo) throws ReferenceNotFoundException, ReferenceConflictException {
try {
casOpLoop("assignRef", assignee, CasOpVariant.REF_UPDATE, (ctx, pointer, branchCommits, newKeyLists) -> {
Hash beforeAssign = branchHead(pointer, assignee);
verifyExpectedHash(beforeAssign, assignee, expectedHead);
validateHashExists(ctx, assignTo);
GlobalStateLogEntry newGlobalHead = noopGlobalLogEntry(ctx, pointer);
RefLogEntry.RefType refType = assignee instanceof TagName ? RefLogEntry.RefType.Tag : RefLogEntry.RefType.Branch;
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, assignee.getName(), refType, assignTo, RefLogEntry.Operation.ASSIGN_REFERENCE, commitTimeInMicros(), Collections.singletonList(beforeAssign));
return updateGlobalStatePointer(assignee, pointer, assignTo, newGlobalHead, newRefLog);
}, () -> 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.persist.serialize.AdapterTypes.RefLogEntry.RefType in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method delete.
@Override
public void delete(NamedRef reference, Optional<Hash> expectedHead) throws ReferenceNotFoundException, ReferenceConflictException {
try {
casOpLoop("deleteRef", reference, CasOpVariant.DELETE_REF, (ctx, pointer, branchCommits, newKeyLists) -> {
Hash branchHead = branchHead(pointer, reference);
verifyExpectedHash(branchHead, reference, expectedHead);
GlobalStateLogEntry newGlobalHead = noopGlobalLogEntry(ctx, pointer);
RefLogEntry.RefType refType = reference instanceof TagName ? RefLogEntry.RefType.Tag : RefLogEntry.RefType.Branch;
RefLogEntry newRefLog = writeRefLogEntry(ctx, pointer, reference.getName(), refType, branchHead, RefLogEntry.Operation.DELETE_REFERENCE, commitTimeInMicros(), Collections.emptyList());
return updateGlobalStatePointer(reference, pointer, null, newGlobalHead, newRefLog);
}, () -> deleteConflictMessage("Retry-Failure", reference, expectedHead));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations