use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class TreeApiImpl method transplantCommitsIntoBranch.
@Override
public void transplantCommitsIntoBranch(String branchName, String hash, String message, Transplant transplant) throws NessieNotFoundException, NessieConflictException {
try {
List<Hash> transplants;
try (Stream<Hash> s = transplant.getHashesToTransplant().stream().map(Hash::of)) {
transplants = s.collect(Collectors.toList());
}
getStore().transplant(BranchName.of(branchName), toHash(hash, true), transplants, commitMetaUpdate());
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
} catch (ReferenceConflictException e) {
throw new NessieReferenceConflictException(e.getMessage(), e);
}
}
use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class AbstractSingleBranch method singleBranchManyUsers.
/**
* Use case simulation matrix: single branch, multiple users, each or all user updating a separate
* or single table.
*/
@ParameterizedTest
@MethodSource("singleBranchManyUsersCases")
void singleBranchManyUsers(SingleBranchParam param) throws Exception {
BranchName branch = BranchName.of(param.branchName);
int numUsers = 5;
int numCommits = 50;
Hash[] hashesKnownByUser = new Hash[numUsers];
Hash createHash = store().create(branch, Optional.empty());
Arrays.fill(hashesKnownByUser, createHash);
List<CommitMessage> expectedValues = new ArrayList<>();
Map<Key, String> previousState = new HashMap<>();
for (int commitNum = 0; commitNum < numCommits; commitNum++) {
for (int user = 0; user < numUsers; user++) {
Hash hashKnownByUser = hashesKnownByUser[user];
CommitMessage msg = commitMessage(String.format("user %03d/commit %03d", user, commitNum));
expectedValues.add(msg);
Key key = Key.of(param.tableNameGen.apply(user));
String contentId = param.contentIdGen.apply(user);
Operation<BaseContent> put;
if (param.globalState) {
String state = String.format("%03d_%03d", user, commitNum);
if (previousState.containsKey(key)) {
put = Put.of(key, withGlobal(state, "data_file", contentId), withGlobal(previousState.get(key), "foo", contentId));
} else {
put = Put.of(key, withGlobal(state, "data_file", contentId));
}
previousState.put(key, state);
} else {
BaseContent value = newOnRef(String.format("data_file_%03d_%03d", user, commitNum));
put = Put.of(key, value);
}
Hash commitHash;
List<Operation<BaseContent>> ops = ImmutableList.of(put);
try {
commitHash = store().commit(branch, Optional.of(hashKnownByUser), msg, ops);
} catch (ReferenceConflictException inconsistentValueException) {
if (param.allowInconsistentValueException) {
hashKnownByUser = store().hashOnReference(branch, Optional.empty());
commitHash = store().commit(branch, Optional.of(hashKnownByUser), msg, ops);
} else {
throw inconsistentValueException;
}
}
assertNotEquals(hashKnownByUser, commitHash);
hashesKnownByUser[user] = commitHash;
}
}
// Verify that all commits are there and that the order of the commits is correct
List<CommitMessage> committedValues = commitsList(branch, s -> s.map(Commit::getCommitMeta), false);
Collections.reverse(expectedValues);
assertEquals(expectedValues, committedValues);
}
use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class TxDatabaseAdapter method commit.
@Override
public Hash commit(CommitAttempt commitAttempt) throws ReferenceConflictException, ReferenceNotFoundException {
try {
return opLoop("commit", commitAttempt.getCommitToBranch(), false, (conn, branchHead) -> {
long timeInMicros = commitTimeInMicros();
CommitLogEntry newBranchCommit = commitAttempt(conn, timeInMicros, branchHead, commitAttempt, h -> {
});
upsertGlobalStates(commitAttempt, conn, newBranchCommit.getCreatedTime());
Hash resultHash = tryMoveNamedReference(conn, commitAttempt.getCommitToBranch(), branchHead, newBranchCommit.getHash());
commitRefLog(conn, timeInMicros, newBranchCommit.getHash(), commitAttempt.getCommitToBranch(), RefLogEntry.Operation.COMMIT, Collections.emptyList());
return resultHash;
}, () -> commitConflictMessage("Conflict", commitAttempt.getCommitToBranch(), commitAttempt.getExpectedHead()), () -> commitConflictMessage("Retry-Failure", commitAttempt.getCommitToBranch(), commitAttempt.getExpectedHead()));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.ReferenceConflictException 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);
}
}
use of org.projectnessie.versioned.ReferenceConflictException 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);
}
}
Aggregations