Merge "ChangeIndexer: Disable auto-rebuilding changes in all cases"

This commit is contained in:
Dave Borowitz
2016-07-08 20:17:03 +00:00
committed by Gerrit Code Review
2 changed files with 44 additions and 19 deletions

View File

@@ -203,19 +203,7 @@ public class ChangeIndexer {
*/ */
public void index(ReviewDb db, Change change) public void index(ReviewDb db, Change change)
throws IOException, OrmException { throws IOException, OrmException {
ChangeData cd; index(newChangeData(db, change));
if (notesMigration.commitChangeWrites()) {
// Auto-rebuilding when NoteDb reads are disabled just increases
// contention on the meta ref from a background indexing thread with
// little benefit. The next actual write to the entity may still incur a
// less-contentious rebuild.
ChangeNotes notes =
changeNotesFactory.createWithAutoRebuildingDisabled(change, null);
cd = changeDataFactory.create(db, notes);
} else {
cd = changeDataFactory.create(db, change);
}
index(cd);
} }
/** /**
@@ -226,8 +214,8 @@ public class ChangeIndexer {
* @param changeId ID of the change to index. * @param changeId ID of the change to index.
*/ */
public void index(ReviewDb db, Project.NameKey project, Change.Id changeId) public void index(ReviewDb db, Project.NameKey project, Change.Id changeId)
throws IOException { throws IOException, OrmException {
index(changeDataFactory.create(db, project, changeId)); index(newChangeData(db, project, changeId));
} }
/** /**
@@ -300,8 +288,8 @@ public class ChangeIndexer {
}; };
RequestContext oldCtx = context.setContext(newCtx); RequestContext oldCtx = context.setContext(newCtx);
try { try {
ChangeData cd = changeDataFactory ChangeData cd = newChangeData(
.create(newCtx.getReviewDbProvider().get(), project, id); newCtx.getReviewDbProvider().get(), project, id);
index(cd); index(cd);
return null; return null;
} finally { } finally {
@@ -342,4 +330,29 @@ public class ChangeIndexer {
return null; return null;
} }
} }
// Avoid auto-rebuilding when reindexing if reading is disabled. This just
// increases contention on the meta ref from a background indexing thread
// with little benefit. The next actual write to the entity may still incur a
// less-contentious rebuild.
private ChangeData newChangeData(ReviewDb db, Change change)
throws OrmException {
if (!notesMigration.readChanges()) {
ChangeNotes notes = changeNotesFactory.createWithAutoRebuildingDisabled(
change, null);
return changeDataFactory.create(db, notes);
}
return changeDataFactory.create(db, change);
}
private ChangeData newChangeData(ReviewDb db, Project.NameKey project,
Change.Id changeId) throws OrmException {
if (!notesMigration.readChanges()) {
ChangeNotes notes = changeNotesFactory.createWithAutoRebuildingDisabled(
db, project, changeId);
return changeDataFactory.create(db, notes);
}
return changeDataFactory.create(db, project, changeId);
}
} }

View File

@@ -149,7 +149,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
return changes.get(0).notes(); return changes.get(0).notes();
} }
public ChangeNotes create(ReviewDb db, Project.NameKey project, private Change loadChangeFromDb(ReviewDb db, Project.NameKey project,
Change.Id changeId) throws OrmException { Change.Id changeId) throws OrmException {
Change change = ReviewDbUtil.unwrapDb(db).changes().get(changeId); Change change = ReviewDbUtil.unwrapDb(db).changes().get(changeId);
checkNotNull(change, checkNotNull(change,
@@ -160,7 +160,19 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
project, changeId, change.getProject()); project, changeId, change.getProject());
// TODO: Throw NoSuchChangeException when the change is not found in the // TODO: Throw NoSuchChangeException when the change is not found in the
// database // database
return new ChangeNotes(args, change).load(); return change;
}
public ChangeNotes create(ReviewDb db, Project.NameKey project,
Change.Id changeId) throws OrmException {
return new ChangeNotes(args, loadChangeFromDb(db, project, changeId))
.load();
}
public ChangeNotes createWithAutoRebuildingDisabled(ReviewDb db,
Project.NameKey project, Change.Id changeId) throws OrmException {
return new ChangeNotes(
args, loadChangeFromDb(db, project, changeId), false, null).load();
} }
/** /**