Search in sources :

Example 11 with TagName

use of org.projectnessie.versioned.TagName 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);
    }
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) RefType(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType) TagName(org.projectnessie.versioned.TagName) 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 12 with TagName

use of org.projectnessie.versioned.TagName in project nessie by projectnessie.

the class AbstractGetNamedReferences method fromNoAncestor.

@Test
public void fromNoAncestor() throws Exception {
    BranchName main = BranchName.of(MAIN_BRANCH);
    BranchName branch = BranchName.of("fromNoAncestorBranch");
    BranchName branch2 = BranchName.of("fromNoAncestorBranch2");
    BranchName branch3 = BranchName.of("fromNoAncestorBranch3");
    TagName tag = TagName.of("fromNoAncestorTag");
    TagName tag2 = TagName.of("fromNoAncestorTag2");
    TagName tag3 = TagName.of("fromNoAncestorTag3");
    Hash hash = databaseAdapter.noAncestorHash();
    Hash mainHash = hash;
    Hash branchHash = hash;
    assertThat(databaseAdapter.hashOnReference(main, Optional.empty())).isEqualTo(hash);
    // Have 'main' + a branch + a tag
    // all point to the "no ancestor" hash (aka "beginning of time")
    databaseAdapter.create(branch, hash);
    databaseAdapter.create(tag, hash);
    verifyReferences(new ExpectedNamedReference(main, 0L, mainHash, 0, 0, hash, null), new ExpectedNamedReference(branch, 0L, branchHash, 0, 0, hash, null), new ExpectedNamedReference(tag, 0L, hash, 0, 0, hash, null));
    for (int i = 0; i < 100; i++) {
        mainHash = dummyCommit(main, mainHash, i + 1);
    }
    // Expect a commit-metadata for 'main', branch+tag are then 100 commits behind.
    verifyReferences(new ExpectedNamedReference(main, 100, mainHash, 0, 0, hash, commitMetaFor(main, 100)), new ExpectedNamedReference(branch, 0, branchHash, 0, 100, hash, null), new ExpectedNamedReference(tag, 0, hash, 0, 100, hash, null));
    for (int i = 0; i < 42; i++) {
        branchHash = dummyCommit(branch, branchHash, i + 1);
    }
    // same expectations as above, but branch is now also 42 commits ahead
    verifyReferences(new ExpectedNamedReference(main, 100, mainHash, 0, 0, hash, commitMetaFor(main, 100)), new ExpectedNamedReference(branch, 42, branchHash, 42, 100, hash, commitMetaFor(branch, 42)), new ExpectedNamedReference(tag, 0, hash, 0, 100, hash, null));
    // create a branch2 + tag2 from 'main'
    Hash main100 = mainHash;
    Hash branch2Hash = databaseAdapter.create(branch2, main100);
    Hash tag2Hash = databaseAdapter.create(tag2, main100);
    // same expectations as above, but include branch2 + tag2
    // - common ancestor of branch2 + tag2 is the 100th commit on 'main'
    verifyReferences(new ExpectedNamedReference(main, 100, mainHash, 0, 0, hash, commitMetaFor(main, 100)), new ExpectedNamedReference(branch, 42, branchHash, 42, 100, hash, commitMetaFor(branch, 42)), new ExpectedNamedReference(tag, 0, hash, 0, 100, hash, null), new ExpectedNamedReference(branch2, 100, branch2Hash, 0, 0, main100, commitMetaFor(main, 100)), new ExpectedNamedReference(tag2, 100, tag2Hash, 0, 0, main100, commitMetaFor(main, 100)));
    for (int i = 100; i < 1000; i++) {
        mainHash = dummyCommit(main, mainHash, i + 1);
    }
    // similar to the above, but:
    // - branch + tag are now 100+900 = 1000 commits behind
    verifyReferences(new ExpectedNamedReference(main, 1000, mainHash, 0, 0, hash, commitMetaFor(main, 1000)), new ExpectedNamedReference(branch, 42, branchHash, 42, 1000, hash, commitMetaFor(branch, 42)), new ExpectedNamedReference(tag, 0, hash, 0, 1000, hash, null), new ExpectedNamedReference(branch2, 100, branch2Hash, 0, 900, main100, commitMetaFor(main, 100)), new ExpectedNamedReference(tag2, 100, tag2Hash, 0, 900, main100, commitMetaFor(main, 100)));
    for (int i = 0; i < 42; i++) {
        branch2Hash = dummyCommit(branch2, branch2Hash, i + 1);
    }
    // similar to the above, but:
    // - branch2 is now also 42 commits ahead
    verifyReferences(new ExpectedNamedReference(main, 1000, mainHash, 0, 0, hash, commitMetaFor(main, 1000)), new ExpectedNamedReference(branch, 42, branchHash, 42, 1000, hash, commitMetaFor(branch, 42)), new ExpectedNamedReference(tag, 0, hash, 0, 1000, hash, null), new ExpectedNamedReference(branch2, 142, branch2Hash, 42, 900, main100, commitMetaFor(branch2, 42)), new ExpectedNamedReference(tag2, 100, tag2Hash, 0, 900, main100, commitMetaFor(main, 100)));
    // Create branch2+tag3 at branch2
    Hash branch2plus42 = branch2Hash;
    Hash branch3Hash = databaseAdapter.create(branch3, branch2plus42);
    Hash tag3Hash = databaseAdapter.create(tag3, branch2plus42);
    for (int i = 0; i < 42; i++) {
        branch3Hash = dummyCommit(branch3, branch3Hash, i + 1);
    }
    // similar to the above, but:
    // - tag3 is 42 commits ahead
    // - branch3 is 84 commits ahead
    verifyReferences(new ExpectedNamedReference(main, 1000, mainHash, 0, 0, hash, commitMetaFor(main, 1000)), new ExpectedNamedReference(branch, 42, branchHash, 42, 1000, hash, commitMetaFor(branch, 42)), new ExpectedNamedReference(tag, 0, hash, 0, 1000, hash, null), new ExpectedNamedReference(branch2, 142, branch2Hash, 42, 900, main100, commitMetaFor(branch2, 42)), new ExpectedNamedReference(tag2, 100, tag2Hash, 0, 900, main100, commitMetaFor(main, 100)), new ExpectedNamedReference(branch3, 184, branch3Hash, 84, 900, main100, commitMetaFor(branch3, 42)), new ExpectedNamedReference(tag3, 142, tag3Hash, 42, 900, main100, commitMetaFor(branch2, 42)));
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Aggregations

TagName (org.projectnessie.versioned.TagName)12 Hash (org.projectnessie.versioned.Hash)11 Test (org.junit.jupiter.api.Test)8 BranchName (org.projectnessie.versioned.BranchName)7 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)4 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)4 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)4 VersionStoreException (org.projectnessie.versioned.VersionStoreException)4 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)4 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)4 RefLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)4 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)3 GlobalStateLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry)3 RefType (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType)3 ReferenceInfo (org.projectnessie.versioned.ReferenceInfo)2 ByteString (com.google.protobuf.ByteString)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1