Search in sources :

Example 26 with ReferenceConflictException

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();
    }
}
Also used : BaseContent(org.projectnessie.versioned.testworker.BaseContent) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) ArrayList(java.util.ArrayList) Operation(org.projectnessie.versioned.Operation) ReferenceRetryFailureException(org.projectnessie.versioned.ReferenceRetryFailureException) Key(org.projectnessie.versioned.Key) WithGlobalStateContent(org.projectnessie.versioned.testworker.WithGlobalStateContent)

Example 27 with ReferenceConflictException

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;
}
Also used : ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) ImmutableCommitLogEntry(org.projectnessie.versioned.persist.adapter.ImmutableCommitLogEntry)

Aggregations

ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)27 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)22 Hash (org.projectnessie.versioned.Hash)21 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)16 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)15 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)12 VersionStoreException (org.projectnessie.versioned.VersionStoreException)12 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)11 ArrayList (java.util.ArrayList)8 BranchName (org.projectnessie.versioned.BranchName)8 Key (org.projectnessie.versioned.Key)7 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)7 GlobalStateLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry)7 ByteString (com.google.protobuf.ByteString)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)6 Optional (java.util.Optional)6 TagName (org.projectnessie.versioned.TagName)6 RefLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)6 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5