use of com.google.gerrit.server.notedb.rebuild.ChangeRebuilder in project gerrit by GerritCodeReview.
the class ChangeNotes method rebuildAndOpen.
private LoadHandle rebuildAndOpen(Repository repo, ObjectId oldId) throws IOException {
Timer1.Context timer = args.metrics.autoRebuildLatency.start(CHANGES);
try {
Change.Id cid = getChangeId();
ReviewDb db = args.db.get();
ChangeRebuilder rebuilder = args.rebuilder.get();
NoteDbUpdateManager.Result r;
try (NoteDbUpdateManager manager = rebuilder.stage(db, cid)) {
if (manager == null) {
// May be null in tests.
return super.openHandle(repo, oldId);
}
manager.setRefLogMessage("Auto-rebuilding change");
r = manager.stageAndApplyDelta(change);
try {
rebuilder.execute(db, cid, manager);
repo.scanForRepoChanges();
} catch (OrmException | IOException e) {
// Rebuilding failed. Most likely cause is contention on one or more
// change refs; there are other types of errors that can happen during
// rebuilding, but generally speaking they should happen during stage(),
// not execute(). Assume that some other worker is going to successfully
// store the rebuilt state, which is deterministic given an input
// ChangeBundle.
//
// Parse notes from the staged result so we can return something useful
// to the caller instead of throwing.
log.debug("Rebuilding change {} failed: {}", getChangeId(), e.getMessage());
args.metrics.autoRebuildFailureCount.increment(CHANGES);
rebuildResult = checkNotNull(r);
checkNotNull(r.newState());
checkNotNull(r.staged());
return LoadHandle.create(ChangeNotesCommit.newStagedRevWalk(repo, r.staged().changeObjects()), r.newState().getChangeMetaId());
}
}
return LoadHandle.create(ChangeNotesCommit.newRevWalk(repo), r.newState().getChangeMetaId());
} catch (NoSuchChangeException e) {
return super.openHandle(repo, oldId);
} catch (OrmException e) {
throw new IOException(e);
} finally {
log.debug("Rebuilt change {} in project {} in {} ms", getChangeId(), getProjectName(), TimeUnit.MILLISECONDS.convert(timer.stop(), TimeUnit.NANOSECONDS));
}
}
use of com.google.gerrit.server.notedb.rebuild.ChangeRebuilder in project gerrit by GerritCodeReview.
the class DraftCommentNotes method rebuildAndOpen.
private LoadHandle rebuildAndOpen(Repository repo) throws NoSuchChangeException, IOException {
Timer1.Context timer = args.metrics.autoRebuildLatency.start(CHANGES);
try {
Change.Id cid = getChangeId();
ReviewDb db = args.db.get();
ChangeRebuilder rebuilder = args.rebuilder.get();
NoteDbUpdateManager.Result r;
try (NoteDbUpdateManager manager = rebuilder.stage(db, cid)) {
if (manager == null) {
// May be null in tests.
return super.openHandle(repo);
}
r = manager.stageAndApplyDelta(change);
try {
rebuilder.execute(db, cid, manager);
repo.scanForRepoChanges();
} catch (OrmException | IOException e) {
// See ChangeNotes#rebuildAndOpen.
log.debug("Rebuilding change {} via drafts failed: {}", getChangeId(), e.getMessage());
args.metrics.autoRebuildFailureCount.increment(CHANGES);
checkNotNull(r.staged());
return LoadHandle.create(ChangeNotesCommit.newStagedRevWalk(repo, r.staged().allUsersObjects()), draftsId(r));
}
}
return LoadHandle.create(ChangeNotesCommit.newRevWalk(repo), draftsId(r));
} catch (NoSuchChangeException e) {
return super.openHandle(repo);
} catch (OrmException e) {
throw new IOException(e);
} finally {
log.debug("Rebuilt change {} in {} in {} ms via drafts", getChangeId(), change != null ? "project " + change.getProject() : "unknown project", TimeUnit.MILLISECONDS.convert(timer.stop(), TimeUnit.NANOSECONDS));
}
}
use of com.google.gerrit.server.notedb.rebuild.ChangeRebuilder in project gerrit by GerritCodeReview.
the class NoteDbModule method configure.
@Override
public void configure() {
factory(ChangeUpdate.Factory.class);
factory(ChangeDraftUpdate.Factory.class);
factory(DeleteCommentRewriter.Factory.class);
factory(DraftCommentNotes.Factory.class);
factory(RobotCommentUpdate.Factory.class);
factory(RobotCommentNotes.Factory.class);
factory(NoteDbUpdateManager.Factory.class);
if (!useTestBindings) {
install(ChangeNotesCache.module());
if (cfg.getBoolean("noteDb", null, "testRebuilderWrapper", false)) {
// Yes, another variety of test bindings with a different way of
// configuring it.
bind(ChangeRebuilder.class).to(TestChangeRebuilderWrapper.class);
} else {
bind(ChangeRebuilder.class).to(ChangeRebuilderImpl.class);
}
} else {
bind(ChangeRebuilder.class).toInstance(new ChangeRebuilder(null) {
@Override
public Result rebuild(ReviewDb db, Change.Id changeId) {
return null;
}
@Override
public Result rebuildEvenIfReadOnly(ReviewDb db, Id changeId) {
return null;
}
@Override
public Result rebuild(NoteDbUpdateManager manager, ChangeBundle bundle) {
return null;
}
@Override
public NoteDbUpdateManager stage(ReviewDb db, Change.Id changeId) {
return null;
}
@Override
public Result execute(ReviewDb db, Change.Id changeId, NoteDbUpdateManager manager) {
return null;
}
@Override
public void buildUpdates(NoteDbUpdateManager manager, ChangeBundle bundle) {
// Do nothing.
}
@Override
public void rebuildReviewDb(ReviewDb db, Project.NameKey project, Id changeId) {
// Do nothing.
}
});
bind(new TypeLiteral<Cache<ChangeNotesCache.Key, ChangeNotesState>>() {
}).annotatedWith(Names.named(ChangeNotesCache.CACHE_NAME)).toInstance(CacheBuilder.newBuilder().<ChangeNotesCache.Key, ChangeNotesState>build());
}
}
Aggregations