Search in sources :

Example 36 with OrmException

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

the class StreamEventsApiListener method onChangeRestored.

@Override
public void onChangeRestored(ChangeRestoredListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        ChangeRestoredEvent event = new ChangeRestoredEvent(change);
        event.change = changeAttributeSupplier(change);
        event.restorer = accountAttributeSupplier(ev.getWho());
        event.patchSet = patchSetAttributeSupplier(change, psUtil.current(db.get(), notes));
        event.reason = ev.getReason();
        dispatcher.get().postEvent(change, event);
    } catch (OrmException e) {
        log.error("Failed to dispatch event", e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.reviewdb.client.Change)

Example 37 with OrmException

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

the class StreamEventsApiListener method onTopicEdited.

@Override
public void onTopicEdited(TopicEditedListener.Event ev) {
    try {
        Change change = getChange(ev.getChange());
        TopicChangedEvent event = new TopicChangedEvent(change);
        event.change = changeAttributeSupplier(change);
        event.changer = accountAttributeSupplier(ev.getWho());
        event.oldTopic = ev.getOldTopic();
        dispatcher.get().postEvent(change, event);
    } catch (OrmException e) {
        log.error("Failed to dispatch event", e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change)

Example 38 with OrmException

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

the class ChangeRebuilderImpl method execute.

public Result execute(ReviewDb db, Change.Id changeId, NoteDbUpdateManager manager, boolean checkReadOnly) throws OrmException, IOException {
    db = ReviewDbUtil.unwrapDb(db);
    Change change = checkNoteDbState(ChangeNotes.readOneReviewDbChange(db, changeId));
    if (change == null) {
        throw new NoSuchChangeException(changeId);
    }
    final String oldNoteDbState = change.getNoteDbState();
    Result r = manager.stageAndApplyDelta(change);
    final String newNoteDbState = change.getNoteDbState();
    try {
        db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() {

            @Override
            public Change update(Change change) {
                if (checkReadOnly) {
                    NoteDbChangeState.checkNotReadOnly(change, skewMs);
                }
                String currNoteDbState = change.getNoteDbState();
                if (Objects.equals(currNoteDbState, newNoteDbState)) {
                    // Another thread completed the same rebuild we were about to.
                    throw new AbortUpdateException();
                } else if (!Objects.equals(oldNoteDbState, currNoteDbState)) {
                    // Another thread updated the state to something else.
                    throw new ConflictingUpdateException(change, oldNoteDbState);
                }
                change.setNoteDbState(newNoteDbState);
                return change;
            }
        });
    } catch (ConflictingUpdateException e) {
        // the other thread.
        throw new OrmException(e.getMessage());
    } catch (AbortUpdateException e) {
        if (NoteDbChangeState.parse(changeId, newNoteDbState).isUpToDate(manager.getChangeRepo().cmds.getRepoRefCache(), manager.getAllUsersRepo().cmds.getRepoRefCache())) {
            // Result was flushed to the repo by whatever thread won the race.
            return r;
        }
    // If the state doesn't match, that means another thread attempted this
    // rebuild, but failed. Fall through and try to update the ref again.
    }
    if (migration.failChangeWrites()) {
        // results instead of reading from the repo.
        throw new OrmException(NoteDbUpdateManager.CHANGES_READ_ONLY);
    }
    manager.execute();
    return r;
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change) Result(com.google.gerrit.server.notedb.NoteDbUpdateManager.Result)

Example 39 with OrmException

use of com.google.gwtorm.server.OrmException 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 40 with OrmException

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

the class NoteDbUpdateManager method execute.

@Nullable
public BatchRefUpdate execute(boolean dryrun) throws OrmException, IOException {
    // Check before even inspecting the list, as this is a programmer error.
    if (migration.failChangeWrites()) {
        throw new OrmException(CHANGES_READ_ONLY);
    }
    if (isEmpty()) {
        return null;
    }
    try (Timer1.Context timer = metrics.updateLatency.start(CHANGES)) {
        stage();
        // ChangeUpdates must execute before ChangeDraftUpdates.
        //
        // ChangeUpdate will automatically delete draft comments for any published
        // comments, but the updates to the two repos don't happen atomically.
        // Thus if the change meta update succeeds and the All-Users update fails,
        // we may have stale draft comments. Doing it in this order allows stale
        // comments to be filtered out by ChangeNotes, reflecting the fact that
        // comments can only go from DRAFT to PUBLISHED, not vice versa.
        BatchRefUpdate result = execute(changeRepo, dryrun, pushCert);
        execute(allUsersRepo, dryrun, null);
        return result;
    } finally {
        close();
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) Timer1(com.google.gerrit.metrics.Timer1) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) Nullable(com.google.gerrit.common.Nullable)

Aggregations

OrmException (com.google.gwtorm.server.OrmException)172 IOException (java.io.IOException)78 Change (com.google.gerrit.reviewdb.client.Change)50 Repository (org.eclipse.jgit.lib.Repository)41 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)33 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)31 ObjectId (org.eclipse.jgit.lib.ObjectId)29 Account (com.google.gerrit.reviewdb.client.Account)28 RevWalk (org.eclipse.jgit.revwalk.RevWalk)28 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 ChangeData (com.google.gerrit.server.query.change.ChangeData)24 Map (java.util.Map)22 ArrayList (java.util.ArrayList)21 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)20 Inject (com.google.inject.Inject)18 Provider (com.google.inject.Provider)17 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)16 Set (java.util.Set)16 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)15 CurrentUser (com.google.gerrit.server.CurrentUser)14