Search in sources :

Example 26 with ReferenceNotFoundException

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) ReferenceRetryFailureException(org.projectnessie.versioned.ReferenceRetryFailureException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SQLException(java.sql.SQLException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException)

Example 27 with ReferenceNotFoundException

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) Traced(org.projectnessie.versioned.persist.adapter.spi.Traced) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) PreparedStatement(java.sql.PreparedStatement) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) ReferenceRetryFailureException(org.projectnessie.versioned.ReferenceRetryFailureException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SQLException(java.sql.SQLException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException)

Example 28 with ReferenceNotFoundException

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) ReferenceRetryFailureException(org.projectnessie.versioned.ReferenceRetryFailureException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SQLException(java.sql.SQLException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException)

Example 29 with ReferenceNotFoundException

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException)

Example 30 with ReferenceNotFoundException

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);
}
Also used : Type(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefPointer.Type) DatabaseAdapterUtil.referenceNotFound(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.referenceNotFound) KeyListEntity(org.projectnessie.versioned.persist.adapter.KeyListEntity) DatabaseAdapterUtil.deleteConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.deleteConflictMessage) DatabaseAdapterUtil.takeUntilExcludeLast(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.takeUntilExcludeLast) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) CommitAttempt(org.projectnessie.versioned.persist.adapter.CommitAttempt) Map(java.util.Map) Traced(org.projectnessie.versioned.persist.adapter.spi.Traced) ContentIdWithBytes(org.projectnessie.versioned.persist.serialize.AdapterTypes.ContentIdWithBytes) AdapterTypes(org.projectnessie.versioned.persist.serialize.AdapterTypes) DatabaseAdapterUtil.mergeConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.mergeConflictMessage) NamedRef(org.projectnessie.versioned.NamedRef) ProtoSerialization(org.projectnessie.versioned.persist.serialize.ProtoSerialization) DatabaseAdapterUtil.createConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.createConflictMessage) ImmutableMap(com.google.common.collect.ImmutableMap) RefType(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Collection(java.util.Collection) Set(java.util.Set) DatabaseAdapterUtil.takeUntilIncludeLast(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.takeUntilIncludeLast) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Stream(java.util.stream.Stream) Difference(org.projectnessie.versioned.persist.adapter.Difference) NamedReference(org.projectnessie.versioned.persist.serialize.AdapterTypes.NamedReference) DatabaseAdapterUtil.hashCollisionDetected(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.hashCollisionDetected) TryLoopState.newTryLoopState(org.projectnessie.versioned.persist.adapter.spi.TryLoopState.newTryLoopState) Optional(java.util.Optional) Spliterator(java.util.Spliterator) TryLoopState(org.projectnessie.versioned.persist.adapter.spi.TryLoopState) DatabaseAdapterUtil.referenceAlreadyExists(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.referenceAlreadyExists) NON_TRANSACTIONAL_OPERATION_CONTEXT(org.projectnessie.versioned.persist.nontx.NonTransactionalOperationContext.NON_TRANSACTIONAL_OPERATION_CONTEXT) DatabaseAdapterUtil.commitConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.commitConflictMessage) RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription) DatabaseAdapterUtil.repoDescUpdateConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.repoDescUpdateConflictMessage) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) DatabaseAdapterUtil.assignConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.assignConflictMessage) TagName(org.projectnessie.versioned.TagName) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AbstractDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.AbstractDatabaseAdapter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RepoMaintenanceParams(org.projectnessie.versioned.persist.adapter.RepoMaintenanceParams) KeyFilterPredicate(org.projectnessie.versioned.persist.adapter.KeyFilterPredicate) DatabaseAdapterUtil.transplantConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.transplantConflictMessage) RefLog(org.projectnessie.versioned.persist.adapter.RefLog) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) Builder(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry.Builder) StreamSupport(java.util.stream.StreamSupport) ContentVariantSupplier(org.projectnessie.versioned.persist.adapter.ContentVariantSupplier) Nullable(javax.annotation.Nullable) RefPointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefPointer) Operation(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.Operation) ContentIdAndBytes(org.projectnessie.versioned.persist.adapter.ContentIdAndBytes) Hash(org.projectnessie.versioned.Hash) Traced.trace(org.projectnessie.versioned.persist.adapter.spi.Traced.trace) VersionStoreException(org.projectnessie.versioned.VersionStoreException) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) Key(org.projectnessie.versioned.Key) GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ContentAndState(org.projectnessie.versioned.persist.adapter.ContentAndState) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) GlobalLogCompactionParams(org.projectnessie.versioned.persist.adapter.GlobalLogCompactionParams) Collections(java.util.Collections) ContentId(org.projectnessie.versioned.persist.adapter.ContentId) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)

Aggregations

ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)33 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)25 Hash (org.projectnessie.versioned.Hash)24 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)17 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)17 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)16 VersionStoreException (org.projectnessie.versioned.VersionStoreException)14 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)13 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)12 BranchName (org.projectnessie.versioned.BranchName)11 Key (org.projectnessie.versioned.Key)10 NamedRef (org.projectnessie.versioned.NamedRef)9 TagName (org.projectnessie.versioned.TagName)9 List (java.util.List)8 Map (java.util.Map)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)8 Stream (java.util.stream.Stream)8 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)8 ByteString (com.google.protobuf.ByteString)7