Search in sources :

Example 1 with OrmConcurrencyException

use of com.google.gwtorm.server.OrmConcurrencyException in project gerrit by GerritCodeReview.

the class NoteDbUpdateManager method checkExpectedState.

private void checkExpectedState() throws OrmException, IOException {
    if (!checkExpectedState) {
        return;
    }
    // that got passed into the ChangeUpdate.
    for (Collection<ChangeUpdate> us : changeUpdates.asMap().values()) {
        ChangeUpdate u = us.iterator().next();
        NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
        if (expectedState == null) {
            // MismatchedStateException.
            continue;
        }
        if (expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
            // NoteDb is primary, no need to compare state to ReviewDb.
            continue;
        }
        if (!expectedState.isChangeUpToDate(changeRepo.cmds.getRepoRefCache())) {
            throw new MismatchedStateException(u.getId(), expectedState);
        }
    }
    for (Collection<ChangeDraftUpdate> us : draftUpdates.asMap().values()) {
        ChangeDraftUpdate u = us.iterator().next();
        NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
        if (expectedState == null || expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
            // See above.
            continue;
        }
        Account.Id accountId = u.getAccountId();
        if (!expectedState.areDraftsUpToDate(allUsersRepo.cmds.getRepoRefCache(), accountId)) {
            ObjectId expectedDraftId = firstNonNull(expectedState.getDraftIds().get(accountId), ObjectId.zeroId());
            throw new OrmConcurrencyException(String.format("cannot apply NoteDb updates for change %s;" + " draft ref for account %s does not match %s", u.getId(), accountId, expectedDraftId.name()));
        }
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ObjectId(org.eclipse.jgit.lib.ObjectId) OrmConcurrencyException(com.google.gwtorm.server.OrmConcurrencyException)

Aggregations

Account (com.google.gerrit.reviewdb.client.Account)1 OrmConcurrencyException (com.google.gwtorm.server.OrmConcurrencyException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1