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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations