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();
}
}
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();
}
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()));
}
Aggregations