Search in sources :

Example 1 with RefLogEntry

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);
}
Also used : RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)

Example 2 with RefLogEntry

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);
    }
}
Also used : RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) 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 3 with RefLogEntry

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;
}
Also used : ByteString(com.google.protobuf.ByteString) 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) RefLog(org.projectnessie.versioned.persist.adapter.RefLog) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)

Example 4 with 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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) 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 5 with RefLogEntry

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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) 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)

Aggregations

RefLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)13 Hash (org.projectnessie.versioned.Hash)10 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)10 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)9 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)9 GlobalStateLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry)9 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)8 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)8 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)8 VersionStoreException (org.projectnessie.versioned.VersionStoreException)8 TagName (org.projectnessie.versioned.TagName)5 ByteString (com.google.protobuf.ByteString)4 RefType (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType)4 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)3 RefLog (org.projectnessie.versioned.persist.adapter.RefLog)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2