Only allow BatchUpdateListener with REPO_BEFORE_DB
The listener interface is currently only used by MergeOp, which is REPO_BEFORE_DB. Reasoning about the order in which listeners are called is going to be more difficult if we fuse the repo and change meta ref update phases; sidestep the problem by just removing support for listeners in the odd DB_BEFORE_REPO case. Change-Id: Ia2a1c1f827247602eab1f8527f3cd3118f740f23
This commit is contained in:
@@ -127,6 +127,7 @@ public abstract class BatchUpdate implements AutoCloseable {
|
|||||||
@Nullable RequestId requestId,
|
@Nullable RequestId requestId,
|
||||||
boolean dryRun)
|
boolean dryRun)
|
||||||
throws UpdateException, RestApiException {
|
throws UpdateException, RestApiException {
|
||||||
|
checkNotNull(listener);
|
||||||
// It's safe to downcast all members of the input collection in this case, because the only
|
// It's safe to downcast all members of the input collection in this case, because the only
|
||||||
// way a caller could have gotten any BatchUpdates in the first place is to call the create
|
// way a caller could have gotten any BatchUpdates in the first place is to call the create
|
||||||
// method above, which always returns instances of the type we expect. Just to be safe,
|
// method above, which always returns instances of the type we expect. Just to be safe,
|
||||||
@@ -158,7 +159,7 @@ public abstract class BatchUpdate implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Order getOrder(Collection<? extends BatchUpdate> updates) {
|
static Order getOrder(Collection<? extends BatchUpdate> updates, BatchUpdateListener listener) {
|
||||||
Order o = null;
|
Order o = null;
|
||||||
for (BatchUpdate u : updates) {
|
for (BatchUpdate u : updates) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
@@ -167,6 +168,12 @@ public abstract class BatchUpdate implements AutoCloseable {
|
|||||||
throw new IllegalArgumentException("cannot mix execution orders");
|
throw new IllegalArgumentException("cannot mix execution orders");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (o != Order.REPO_BEFORE_DB) {
|
||||||
|
checkArgument(
|
||||||
|
listener == BatchUpdateListener.NONE,
|
||||||
|
"BatchUpdateListener not supported for order %s",
|
||||||
|
o);
|
||||||
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package com.google.gerrit.server.update;
|
|||||||
*
|
*
|
||||||
* <p>When used during execution of multiple batch updates, the {@code after*} methods are called
|
* <p>When used during execution of multiple batch updates, the {@code after*} methods are called
|
||||||
* after that phase has been completed for <em>all</em> updates.
|
* after that phase has been completed for <em>all</em> updates.
|
||||||
|
*
|
||||||
|
* <p>Listeners are only supported for the {@link Order#REPO_BEFORE_DB} order.
|
||||||
*/
|
*/
|
||||||
public interface BatchUpdateListener {
|
public interface BatchUpdateListener {
|
||||||
public static final BatchUpdateListener NONE = new BatchUpdateListener() {};
|
public static final BatchUpdateListener NONE = new BatchUpdateListener() {};
|
||||||
|
|||||||
@@ -82,11 +82,10 @@ class NoteDbBatchUpdate extends BatchUpdate {
|
|||||||
setRequestIds(updates, requestId);
|
setRequestIds(updates, requestId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Order order = getOrder(updates);
|
Order order = getOrder(updates, listener);
|
||||||
// TODO(dborowitz): Fuse implementations to use a single BatchRefUpdate between phases. Note
|
// TODO(dborowitz): Fuse implementations to use a single BatchRefUpdate between phases. Note
|
||||||
// that we will still need to respect the order, since it also dictates the order in which
|
// that we may still need to respect the order, since op implementations may make assumptions
|
||||||
// listener methods are called. We can revisit this later, particularly since the only user of
|
// about the order in which their methods are called.
|
||||||
// BatchUpdateListener is MergeOp, which only uses one order.
|
|
||||||
switch (order) {
|
switch (order) {
|
||||||
case REPO_BEFORE_DB:
|
case REPO_BEFORE_DB:
|
||||||
for (NoteDbBatchUpdate u : updates) {
|
for (NoteDbBatchUpdate u : updates) {
|
||||||
@@ -106,15 +105,12 @@ class NoteDbBatchUpdate extends BatchUpdate {
|
|||||||
for (NoteDbBatchUpdate u : updates) {
|
for (NoteDbBatchUpdate u : updates) {
|
||||||
u.reindexChanges(u.executeChangeOps(dryrun), dryrun);
|
u.reindexChanges(u.executeChangeOps(dryrun), dryrun);
|
||||||
}
|
}
|
||||||
listener.afterUpdateChanges();
|
|
||||||
for (NoteDbBatchUpdate u : updates) {
|
for (NoteDbBatchUpdate u : updates) {
|
||||||
u.executeUpdateRepo();
|
u.executeUpdateRepo();
|
||||||
}
|
}
|
||||||
listener.afterUpdateRepos();
|
|
||||||
for (NoteDbBatchUpdate u : updates) {
|
for (NoteDbBatchUpdate u : updates) {
|
||||||
u.executeRefUpdates(dryrun);
|
u.executeRefUpdates(dryrun);
|
||||||
}
|
}
|
||||||
listener.afterUpdateRefs();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("invalid execution order: " + order);
|
throw new IllegalStateException("invalid execution order: " + order);
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ class ReviewDbBatchUpdate extends BatchUpdate {
|
|||||||
}
|
}
|
||||||
setRequestIds(updates, requestId);
|
setRequestIds(updates, requestId);
|
||||||
try {
|
try {
|
||||||
Order order = getOrder(updates);
|
Order order = getOrder(updates, listener);
|
||||||
boolean updateChangesInParallel = getUpdateChangesInParallel(updates);
|
boolean updateChangesInParallel = getUpdateChangesInParallel(updates);
|
||||||
switch (order) {
|
switch (order) {
|
||||||
case REPO_BEFORE_DB:
|
case REPO_BEFORE_DB:
|
||||||
@@ -290,15 +290,12 @@ class ReviewDbBatchUpdate extends BatchUpdate {
|
|||||||
for (ReviewDbBatchUpdate u : updates) {
|
for (ReviewDbBatchUpdate u : updates) {
|
||||||
u.reindexChanges(u.executeChangeOps(updateChangesInParallel, dryrun));
|
u.reindexChanges(u.executeChangeOps(updateChangesInParallel, dryrun));
|
||||||
}
|
}
|
||||||
listener.afterUpdateChanges();
|
|
||||||
for (ReviewDbBatchUpdate u : updates) {
|
for (ReviewDbBatchUpdate u : updates) {
|
||||||
u.executeUpdateRepo();
|
u.executeUpdateRepo();
|
||||||
}
|
}
|
||||||
listener.afterUpdateRepos();
|
|
||||||
for (ReviewDbBatchUpdate u : updates) {
|
for (ReviewDbBatchUpdate u : updates) {
|
||||||
u.executeRefUpdates(dryrun);
|
u.executeRefUpdates(dryrun);
|
||||||
}
|
}
|
||||||
listener.afterUpdateRefs();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("invalid execution order: " + order);
|
throw new IllegalStateException("invalid execution order: " + order);
|
||||||
|
|||||||
Reference in New Issue
Block a user