Add wait_for_commit to /review
Setting wait_for_commit to true permits callers to wait for the index commit to finish before returning to the client, allowing the client to immediately run a search and see the modifications match. Change-Id: I8db6574a340eb76e388c5bb7adc902d81ccb96be
This commit is contained in:
parent
75ac1f1b99
commit
ff5e6f60d9
@ -2731,6 +2731,10 @@ If not set, the default is `ALL`.
|
||||
link:rest-api-accounts.html#account-id[\{account-id\}] the review
|
||||
should be posted on behalf of. To use this option the caller must
|
||||
have been granted `labelAs-NAME` permission for all keys of labels.
|
||||
|`wait_for_commit`|optional|
|
||||
Whether the request should wait for commit to the index to finish.
|
||||
If `false` (default) the request returns after the data is sent to
|
||||
the index, but searches may not immediately see the update.
|
||||
|============================
|
||||
|
||||
[[reviewer-info]]
|
||||
|
@ -20,6 +20,7 @@ import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
@ -55,6 +56,7 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
private static final Logger log = LoggerFactory.getLogger(PostReview.class);
|
||||
@ -96,6 +98,8 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
* not the caller.
|
||||
*/
|
||||
public String onBehalfOf;
|
||||
|
||||
public boolean waitForCommit;
|
||||
}
|
||||
|
||||
public static enum DraftHandling {
|
||||
@ -147,7 +151,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
@Override
|
||||
public Object apply(RevisionResource revision, Input input)
|
||||
throws AuthException, BadRequestException, OrmException,
|
||||
UnprocessableEntityException {
|
||||
UnprocessableEntityException, InterruptedException, ExecutionException {
|
||||
if (input.onBehalfOf != null) {
|
||||
revision = onBehalfOf(revision, input);
|
||||
}
|
||||
@ -175,7 +179,11 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
if (dirty) {
|
||||
db.changes().update(Collections.singleton(change));
|
||||
db.commit();
|
||||
indexer.index(change);
|
||||
|
||||
ListenableFuture<?> indexWrite = indexer.index(change);
|
||||
if (input.waitForCommit) {
|
||||
indexWrite.get();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
db.rollback();
|
||||
|
@ -229,6 +229,7 @@ public class ReviewCommand extends SshCommand {
|
||||
review.labels = Maps.newTreeMap();
|
||||
review.drafts = PostReview.DraftHandling.PUBLISH;
|
||||
review.strictLabels = false;
|
||||
review.waitForCommit = true;
|
||||
for (ApproveOption ao : optionList) {
|
||||
Short v = ao.value();
|
||||
if (v != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user