Skip to content

Commit 03bb0e4

Browse files
ahornaceVladimir Kotal
authored andcommitted
Remove active waiting for suggester tasks after timeout
1 parent 6a141c9 commit 03bb0e4

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

src/org/opensolaris/opengrok/web/api/v1/controller/SuggesterController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private boolean satisfiesConfiguration(final SuggesterData data, final Suggester
160160
@Path("/config")
161161
@Produces(MediaType.APPLICATION_JSON)
162162
public SuggesterConfig getConfig() {
163-
return RuntimeEnvironment.getInstance().getConfiguration().getSuggesterConfig();
163+
return env.getConfiguration().getSuggesterConfig();
164164
}
165165

166166
/**

suggester/src/main/java/org/opengrok/suggest/Suggester.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,18 @@ private Suggestions complexLookup(
368368
if (!searchTask.started) {
369369
continue;
370370
}
371-
// "spin lock" – should be fast since all the tasks either finished or were interrupted
372-
while (!searchTask.finished) {
371+
372+
if (!searchTask.finished) {
373+
synchronized (searchTask) {
374+
while (!searchTask.finished) {
375+
try {
376+
searchTask.wait();
377+
} catch (InterruptedException e) {
378+
logger.log(Level.WARNING, "Interrupted while waiting for task: {0}", searchTask);
379+
Thread.currentThread().interrupt();
380+
}
381+
}
382+
}
373383
}
374384
}
375385
return new Suggestions(results, partialResult);
@@ -541,7 +551,10 @@ public Void call() {
541551
data.unlock();
542552
}
543553
} finally {
544-
finished = true;
554+
synchronized (this) {
555+
finished = true;
556+
this.notifyAll();
557+
}
545558
}
546559
return null;
547560
}

suggester/src/main/java/org/opengrok/suggest/SuggesterSearcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public List<LookupResultItem> suggest(
127127
private List<LookupResultItem> suggest(
128128
final Query query,
129129
final LeafReaderContext leafReaderContext,
130-
final String suggester,
130+
final String project,
131131
final SuggesterQuery suggesterQuery,
132132
final PopularityCounter searchCounts
133133
) throws IOException {
@@ -189,7 +189,7 @@ private List<LookupResultItem> suggest(
189189
score += searchCounts.get(term) * TERM_ALREADY_SEARCHED_MULTIPLIER;
190190

191191
if (queue.canInsert(score)) {
192-
queue.insertWithOverflow(new LookupResultItem(term.utf8ToString(), suggester, score));
192+
queue.insertWithOverflow(new LookupResultItem(term.utf8ToString(), project, score));
193193
}
194194
}
195195
}

suggester/src/main/java/org/opengrok/suggest/popular/impl/chronicle/ChronicleMapAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void increment(final BytesRef key, final int value) {
6868
if (value < 0) {
6969
throw new IllegalArgumentException("Cannot increment by negative value " + value);
7070
}
71-
map.merge(key, value, (a, b) -> a + b);
71+
map.merge(key, value, Integer::sum);
7272
}
7373

7474
/** {@inheritDoc} */

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomSloppyPhraseScorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class CustomSloppyPhraseScorer extends Scorer implements PhraseScorer {
6161

6262
private int offset;
6363

64-
public Map<Integer, IntsHolder> map = new HashMap<>();
64+
private Map<Integer, IntsHolder> map = new HashMap<>();
6565

6666
CustomSloppyPhraseScorer(Weight weight, CustomPhraseQuery.PostingsAndFreq[] postings, int slop, int offset) {
6767
super(weight);

0 commit comments

Comments
 (0)