use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class CommitBench method doCommit.
private void doCommit(BenchmarkParam bp, BranchName branch, List<Key> keys, Map<Key, String> contentIds) throws Exception {
Map<Key, BaseContent> contentByKey = bp.versionStore.getValues(branch, keys);
try {
List<Operation<BaseContent>> operations = new ArrayList<>(bp.tablesPerCommit);
for (int i = 0; i < bp.tablesPerCommit; i++) {
Key key = keys.get(i);
BaseContent value = contentByKey.get(key);
if (value == null) {
throw new RuntimeException("no value for key " + key + " in " + branch);
}
String currentState = ((WithGlobalStateContent) value).getGlobal();
String newGlobalState = Integer.toString(Integer.parseInt(currentState) + 1);
String contentId = contentIds.get(key);
operations.add(Put.of(key, // hashes, because parent, "content", key are all the same.
withGlobal(newGlobalState, "commit value " + ThreadLocalRandom.current().nextLong(), contentId), withGlobal(currentState, "foo", contentId)));
}
bp.versionStore.commit(branch, Optional.empty(), commitMessage("commit meta data"), operations);
bp.success.incrementAndGet();
} catch (ReferenceRetryFailureException e) {
bp.retryFailures.incrementAndGet();
} catch (ReferenceConflictException e) {
bp.conflictsFailures.incrementAndGet();
}
}
use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class AbstractDatabaseAdapter method commitAttempt.
/**
* Logic implementation of a commit-attempt.
*
* @param ctx technical operation-context
* @param commitAttempt commit parameters
* @param branchHead current HEAD of {@code branch}
* @param newKeyLists consumer for optimistically written {@link KeyListEntity}s
* @return optimistically written commit-log-entry
*/
protected CommitLogEntry commitAttempt(OP_CONTEXT ctx, long timeInMicros, Hash branchHead, CommitAttempt commitAttempt, Consumer<Hash> newKeyLists) throws ReferenceNotFoundException, ReferenceConflictException {
List<String> mismatches = new ArrayList<>();
Callable<Void> validator = commitAttempt.getValidator();
if (validator != null) {
try {
validator.call();
} catch (RuntimeException e) {
// just propagate the RuntimeException up
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// verify expected global-states
checkExpectedGlobalStates(ctx, commitAttempt, mismatches::add);
checkForModifiedKeysBetweenExpectedAndCurrentCommit(ctx, commitAttempt, branchHead, mismatches);
if (!mismatches.isEmpty()) {
throw new ReferenceConflictException(String.join("\n", mismatches));
}
CommitLogEntry currentBranchEntry = fetchFromCommitLog(ctx, branchHead);
int parentsPerCommit = config.getParentsPerCommit();
List<Hash> newParents = new ArrayList<>(parentsPerCommit);
newParents.add(branchHead);
long commitSeq;
if (currentBranchEntry != null) {
List<Hash> p = currentBranchEntry.getParents();
newParents.addAll(p.subList(0, Math.min(p.size(), parentsPerCommit - 1)));
commitSeq = currentBranchEntry.getCommitSeq() + 1;
} else {
commitSeq = 1;
}
CommitLogEntry newBranchCommit = buildIndividualCommit(ctx, timeInMicros, newParents, commitSeq, commitAttempt.getCommitMetaSerialized(), commitAttempt.getPuts(), commitAttempt.getDeletes(), currentBranchEntry != null ? currentBranchEntry.getKeyListDistance() : 0, newKeyLists, NO_IN_MEMORY_COMMITS);
writeIndividualCommit(ctx, newBranchCommit);
return newBranchCommit;
}
Aggregations