Search in sources :

Example 1 with PrimaryStorage

use of com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage in project gerrit by GerritCodeReview.

the class ChangeRebuilderImpl method rebuildReviewDb.

@Override
public void rebuildReviewDb(ReviewDb db, Project.NameKey project, Change.Id changeId) throws OrmException {
    // TODO(dborowitz): Fail fast if changes tables are disabled in ReviewDb.
    ChangeNotes notes = notesFactory.create(db, project, changeId);
    ChangeBundle bundle = ChangeBundle.fromNotes(commentsUtil, notes);
    db = ReviewDbUtil.unwrapDb(db);
    db.changes().beginTransaction(changeId);
    try {
        Change c = db.changes().get(changeId);
        PrimaryStorage ps = PrimaryStorage.of(c);
        if (ps != PrimaryStorage.NOTE_DB) {
            throw new OrmException("primary storage of " + changeId + " is " + ps);
        }
        db.changes().upsert(Collections.singleton(c));
        putExactlyEntities(db.changeMessages(), db.changeMessages().byChange(c.getId()), bundle.getChangeMessages());
        putExactlyEntities(db.patchSets(), db.patchSets().byChange(c.getId()), bundle.getPatchSets());
        putExactlyEntities(db.patchSetApprovals(), db.patchSetApprovals().byChange(c.getId()), bundle.getPatchSetApprovals());
        putExactlyEntities(db.patchComments(), db.patchComments().byChange(c.getId()), bundle.getPatchLineComments());
        db.commit();
    } finally {
        db.rollback();
    }
}
Also used : PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) OrmException(com.google.gwtorm.server.OrmException) ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.reviewdb.client.Change)

Example 2 with PrimaryStorage

use of com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage in project gerrit by GerritCodeReview.

the class StalenessChecker method reviewDbChangeIsStale.

@VisibleForTesting
static boolean reviewDbChangeIsStale(Change indexChange, @Nullable Change reviewDbChange) {
    checkNotNull(indexChange);
    PrimaryStorage storageFromIndex = PrimaryStorage.of(indexChange);
    PrimaryStorage storageFromReviewDb = PrimaryStorage.of(reviewDbChange);
    if (reviewDbChange == null) {
        if (storageFromIndex == PrimaryStorage.REVIEW_DB) {
            // Index says it should have been in ReviewDb, but it wasn't.
            return true;
        }
        // Not in ReviewDb, but that's ok.
        return false;
    }
    checkArgument(indexChange.getId().equals(reviewDbChange.getId()), "mismatched change ID: %s != %s", indexChange.getId(), reviewDbChange.getId());
    if (storageFromIndex != storageFromReviewDb) {
        // Primary storage differs, definitely stale.
        return true;
    }
    if (storageFromReviewDb != PrimaryStorage.REVIEW_DB) {
        // Not a ReviewDb change, don't check rowVersion.
        return false;
    }
    return reviewDbChange.getRowVersion() != indexChange.getRowVersion();
}
Also used : PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with PrimaryStorage

use of com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage in project gerrit by GerritCodeReview.

the class DeleteReviewerOp method approvals.

private Iterable<PatchSetApproval> approvals(ChangeContext ctx, Account.Id accountId) throws OrmException {
    Change.Id changeId = ctx.getNotes().getChangeId();
    Iterable<PatchSetApproval> approvals;
    PrimaryStorage r = PrimaryStorage.of(ctx.getChange());
    if (migration.readChanges() && r == PrimaryStorage.REVIEW_DB) {
        // Because NoteDb and ReviewDb have different semantics for zero-value
        // approvals, we must fall back to ReviewDb as the source of truth here.
        ReviewDb db = ctx.getDb();
        if (db instanceof BatchUpdateReviewDb) {
            db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
        }
        db = ReviewDbUtil.unwrapDb(db);
        approvals = db.patchSetApprovals().byChange(changeId);
    } else {
        approvals = approvalsUtil.byChange(ctx.getDb(), ctx.getNotes()).values();
    }
    return Iterables.filter(approvals, psa -> accountId.equals(psa.getAccountId()));
}
Also used : PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb)

Aggregations

PrimaryStorage (com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage)3 Change (com.google.gerrit.reviewdb.client.Change)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 ChangeBundle (com.google.gerrit.server.notedb.ChangeBundle)1 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)1 BatchUpdateReviewDb (com.google.gerrit.server.update.BatchUpdateReviewDb)1 OrmException (com.google.gwtorm.server.OrmException)1