From 5137e0c06b2357c01cd5aa95062d98e4f3a56028 Mon Sep 17 00:00:00 2001 From: Hongkai Liu Date: Mon, 29 Aug 2016 16:59:07 -0400 Subject: [PATCH 1/3] Double-check change data in cleaning up task Originally, the change clean up task abandons one change after another in a list. As a result of potentially long list of changes to abandon, a change could be updated by the user again after the list is collected and before we reach it. Double-check if the change still satisfies the abandon criterion right before abandoning it. Change-Id: I09f012d3f4ee1f96535e15523010d02b9a881123 --- .../google/gerrit/server/change/AbandonUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java index 8fbeda4f71..b14d4ba5ef 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java @@ -78,6 +78,11 @@ public class AbandonUtil { int count = 0; for (ChangeData cd : changesToAbandon) { try { + if (noNeedToAbandon(cd, query)){ + log.debug("Change data \"{}\" does not satisfy the query \"{}\" any" + + " more, hence skipping it in clean up", cd, query); + continue; + } abandon.abandon(changeControl(cd), cfg.getAbandonMessage(), null); count++; } catch (ResourceConflictException e) { @@ -95,6 +100,14 @@ public class AbandonUtil { } } + private boolean noNeedToAbandon(ChangeData cd, String query) + throws OrmException, QueryParseException { + String newQuery = query + " change:" + cd.getId(); + List changesToAbandon = queryProcessor.enforceVisibility(false) + .queryChanges(queryBuilder.parse(newQuery)).changes(); + return changesToAbandon.isEmpty(); + } + private ChangeControl changeControl(ChangeData cd) throws NoSuchChangeException, OrmException { Change c = cd.change(); From 8fea1bbd3a63542fa42c4346f87dd49286e29b73 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Tue, 5 Jul 2016 16:38:11 +0200 Subject: [PATCH 2/3] Fix NullPointerException on computing task name Some tests hit this NPE occasionally, e.g. see [1]. [1] https://gerrit-ci.gerritforge.com/job/Gerrit-verifier-notedb/6773/consoleText Change-Id: Ib31374cc957ba7ff3a43dc95739205aa34f836d3 Signed-off-by: Edwin Kempin (cherry picked from commit f44565d4ac73bc9d565525dc67dbe7bd4a23b635) --- .../java/com/google/gerrit/server/git/WorkQueue.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java index b572328f86..7d82d32459 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java @@ -397,10 +397,12 @@ public class WorkQueue { if (field.getType().isAssignableFrom(trustedFutureInterruptibleTask)) { field.setAccessible(true); Object innerObj = field.get(runnable); - for (Field innerField : innerObj.getClass().getDeclaredFields()) { - if (innerField.getType().isAssignableFrom(Callable.class)) { - innerField.setAccessible(true); - return ((Callable) innerField.get(innerObj)).toString(); + if (innerObj != null) { + for (Field innerField : innerObj.getClass().getDeclaredFields()) { + if (innerField.getType().isAssignableFrom(Callable.class)) { + innerField.setAccessible(true); + return ((Callable) innerField.get(innerObj)).toString(); + } } } } From 3d2e738991b6ef63dfd717a676f941f98aa365f8 Mon Sep 17 00:00:00 2001 From: Hongkai Liu Date: Wed, 31 Aug 2016 11:21:22 -0400 Subject: [PATCH 3/3] Prevent limit of search outbounding max int value The problem occurs when IndexConfig is created with the default value, i.e., Integer.MAX_VALUE, and the start value in the QueryOptions instance is greater than 0. Bug: Issue 4006 Change-Id: Ib746a7941505a10e0c5a2b1d0a3ca79fca11de5f --- .../main/java/com/google/gerrit/lucene/LuceneChangeIndex.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java index fe37362d09..c8099d2189 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java @@ -447,6 +447,9 @@ public class LuceneChangeIndex implements ChangeIndex { IndexSearcher[] searchers = new IndexSearcher[indexes.size()]; try { int realLimit = opts.start() + opts.limit(); + if (Integer.MAX_VALUE - opts.limit() < opts.start()) { + realLimit = Integer.MAX_VALUE; + } TopFieldDocs[] hits = new TopFieldDocs[indexes.size()]; for (int i = 0; i < indexes.size(); i++) { searchers[i] = indexes.get(i).acquire();