Search in sources :

Example 1 with RepoDescription

use of org.projectnessie.versioned.persist.adapter.RepoDescription in project nessie by projectnessie.

the class AbstractRepoDescription method updates.

@Test
void updates() throws Exception {
    RepoDescription update1 = RepoDescription.builder().repoVersion(42).putProperties("a", "b").putProperties("c", "d").build();
    RepoDescription update2 = RepoDescription.builder().repoVersion(666).putProperties("a", "e").putProperties("c", "f").build();
    databaseAdapter.updateRepositoryDescription(d -> {
        assertThat(d).isEqualTo(RepoDescription.DEFAULT);
        return update1;
    });
    assertThat(databaseAdapter.fetchRepositoryDescription()).isEqualTo(update1);
    databaseAdapter.updateRepositoryDescription(d -> {
        assertThat(d).isEqualTo(update1);
        return update2;
    });
    assertThat(databaseAdapter.fetchRepositoryDescription()).isEqualTo(update2);
}
Also used : RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription) Test(org.junit.jupiter.api.Test)

Example 2 with RepoDescription

use of org.projectnessie.versioned.persist.adapter.RepoDescription in project nessie by projectnessie.

the class TxDatabaseAdapter method updateRepositoryDescription.

@Override
public void updateRepositoryDescription(Function<RepoDescription, RepoDescription> updater) throws ReferenceConflictException {
    try {
        opLoop("updateRepositoryDescription", null, true, (conn, x) -> {
            byte[] currentBytes = fetchRepositoryDescriptionInternal(conn);
            RepoDescription current = protoToRepoDescription(currentBytes);
            RepoDescription updated = updater.apply(current);
            if (updated != null) {
                if (currentBytes == null) {
                    try (PreparedStatement ps = conn.conn().prepareStatement(SqlStatements.INSERT_REPO_DESCRIPTION)) {
                        ps.setString(1, config.getRepositoryId());
                        ps.setBytes(2, toProto(updated).toByteArray());
                        if (ps.executeUpdate() == 0) {
                            return null;
                        }
                    }
                } else {
                    try (PreparedStatement ps = conn.conn().prepareStatement(SqlStatements.UPDATE_REPO_DESCRIPTION)) {
                        ps.setBytes(1, toProto(updated).toByteArray());
                        ps.setString(2, config.getRepositoryId());
                        ps.setBytes(3, currentBytes);
                        if (ps.executeUpdate() == 0) {
                            return null;
                        }
                    }
                }
            }
            return NO_ANCESTOR;
        }, () -> repoDescUpdateConflictMessage("Conflict"), () -> repoDescUpdateConflictMessage("Retry-failure"));
    } catch (ReferenceConflictException | RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) PreparedStatement(java.sql.PreparedStatement) ProtoSerialization.protoToRepoDescription(org.projectnessie.versioned.persist.serialize.ProtoSerialization.protoToRepoDescription) RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription) 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 RepoDescription

use of org.projectnessie.versioned.persist.adapter.RepoDescription in project nessie by projectnessie.

the class TestSerialization method stableOrderOfRepoDescProps.

@RepeatedTest(50)
public void stableOrderOfRepoDescProps() {
    ImmutableRepoDescription.Builder repoDescription = RepoDescription.builder().repoVersion(42);
    Map<String, String> props = new HashMap<>();
    for (int i = 0; i < 20; i++) {
        String key = randomString(50);
        String value = randomString(50);
        props.put(key, value);
        repoDescription.putProperties(key, value);
    }
    AdapterTypes.RepoProps repoProps = toProto(repoDescription.build());
    List<AdapterTypes.Entry> expected = props.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(e -> AdapterTypes.Entry.newBuilder().setKey(e.getKey()).setValue(e.getValue()).build()).collect(Collectors.toList());
    assertThat(repoProps.getPropertiesList()).containsExactlyElementsOf(expected);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) RepeatedTest(org.junit.jupiter.api.RepeatedTest) RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) HashMap(java.util.HashMap) ProtoSerialization.toProto(org.projectnessie.versioned.persist.serialize.ProtoSerialization.toProto) Disabled(org.junit.jupiter.api.Disabled) Function(java.util.function.Function) Supplier(java.util.function.Supplier) UnsafeByteOperations(com.google.protobuf.UnsafeByteOperations) ArrayList(java.util.ArrayList) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) ImmutableRepoDescription(org.projectnessie.versioned.persist.adapter.ImmutableRepoDescription) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RefPointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefPointer) MethodSource(org.junit.jupiter.params.provider.MethodSource) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContentIdAndBytes(org.projectnessie.versioned.persist.adapter.ContentIdAndBytes) Hash(org.projectnessie.versioned.Hash) UUID(java.util.UUID) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) Key(org.projectnessie.versioned.Key) GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) Collectors(java.util.stream.Collectors) KeyWithBytes(org.projectnessie.versioned.persist.adapter.KeyWithBytes) ByteString(com.google.protobuf.ByteString) MessageLite(com.google.protobuf.MessageLite) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) KeyList(org.projectnessie.versioned.persist.adapter.KeyList) Stream(java.util.stream.Stream) NamedReference(org.projectnessie.versioned.persist.serialize.AdapterTypes.NamedReference) ContentId(org.projectnessie.versioned.persist.adapter.ContentId) Builder(org.projectnessie.versioned.persist.adapter.ImmutableRepoDescription.Builder) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) ImmutableRepoDescription(org.projectnessie.versioned.persist.adapter.ImmutableRepoDescription) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Builder(org.projectnessie.versioned.persist.adapter.ImmutableRepoDescription.Builder) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 4 with RepoDescription

use of org.projectnessie.versioned.persist.adapter.RepoDescription in project nessie by projectnessie.

the class NonTransactionalDatabaseAdapter method fetchRepositoryDescription.

@Override
public RepoDescription fetchRepositoryDescription() {
    NonTransactionalOperationContext ctx = NON_TRANSACTIONAL_OPERATION_CONTEXT;
    RepoDescription current = fetchRepositoryDescription(ctx);
    return current == null ? RepoDescription.DEFAULT : current;
}
Also used : RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription)

Example 5 with RepoDescription

use of org.projectnessie.versioned.persist.adapter.RepoDescription in project nessie by projectnessie.

the class NessieInfo method call.

@Override
public Integer call() throws Exception {
    warnOnInMemory();
    ReferenceInfo<ByteString> refInfo = databaseAdapter.namedRef(serverConfig.getDefaultBranch(), GetNamedRefsParams.builder().branchRetrieveOptions(RetrieveOptions.COMMIT_META).tagRetrieveOptions(RetrieveOptions.COMMIT_META).build());
    RepoDescription repoDesc = databaseAdapter.fetchRepositoryDescription();
    spec.commandLine().getOut().printf("%n" + // 
    "No-ancestor hash:                  %s%n" + "Default branch head commit ID:     %s%n" + "Default branch commit count:       %s%n" + "Repository description version:    %d%n" + "Repository description properties: %s%n" + "%n" + "From configuration:%n" + "-------------------%n" + "Version-store type:                %s%n" + "Default branch:                    %s%n", databaseAdapter.noAncestorHash().asString(), refInfo.getHash().asString(), refInfo.getCommitSeq(), repoDesc.getRepoVersion(), repoDesc.getProperties().entrySet().stream().map(e -> String.format("%-30s = %s", e.getKey(), e.getValue())).collect(Collectors.joining("\n                                   ")), versionStoreConfig.getVersionStoreType(), serverConfig.getDefaultBranch());
    return 0;
}
Also used : ByteString(com.google.protobuf.ByteString) RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription)

Aggregations

RepoDescription (org.projectnessie.versioned.persist.adapter.RepoDescription)6 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 MessageLite (com.google.protobuf.MessageLite)1 UnsafeByteOperations (com.google.protobuf.UnsafeByteOperations)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1