summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/java
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-04 15:53:19 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-04 16:38:39 +0200
commitcbadf0e71e2b64dc519b5ea33cd6022014920713 (patch)
tree2220fd8e4d3c9ffd6854ff89c7c5ff6fc8612c56 /sonar-server/src/main/java
parentb20081bda22464b59ac9dc7280213ccb7796fa3b (diff)
downloadsonarqube-cbadf0e71e2b64dc519b5ea33cd6022014920713.tar.gz
sonarqube-cbadf0e71e2b64dc519b5ea33cd6022014920713.zip
fix quality flaw (Throw exception when ES fails within timeout)
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java b/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
index e556a6635c6..28d8210acc7 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
@@ -43,6 +43,7 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
private static final Logger LOGGER = LoggerFactory.getLogger(IndexQueue.class);
private static final Integer DEFAULT_QUEUE_SIZE = 200;
+ private static final int TIMEOUT = 3000;
public IndexQueue() {
super(DEFAULT_QUEUE_SIZE);
@@ -72,8 +73,10 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
action.setLatch(latch);
try {
indexTime = System.currentTimeMillis();
- this.offer(action, 1000, TimeUnit.SECONDS);
- latch.await(1000, TimeUnit.MILLISECONDS);
+ this.offer(action, TIMEOUT, TimeUnit.SECONDS);
+ if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+ throw new IllegalStateException("ES update could not be completed within: " + TIMEOUT + "ms");
+ }
bcount++;
indexTime = System.currentTimeMillis() - indexTime;
// refresh the index.
@@ -112,12 +115,14 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
indexTime = System.currentTimeMillis();
for (IndexAction action : itemActions) {
action.setLatch(itemLatch);
- this.offer(action, 1000, TimeUnit.SECONDS);
+ this.offer(action, TIMEOUT, TimeUnit.SECONDS);
types.add(action.getPayloadClass().getSimpleName());
bcount++;
}
- itemLatch.await(2000, TimeUnit.MILLISECONDS);
+ if (!itemLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+ throw new IllegalStateException("ES update could not be completed within: " + TIMEOUT + "ms");
+ }
indexTime = System.currentTimeMillis() - indexTime;
/* and now push the embedded */
@@ -125,11 +130,13 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
embeddedTime = System.currentTimeMillis();
for (IndexAction action : embeddedActions) {
action.setLatch(embeddedLatch);
- this.offer(action, 1000, TimeUnit.SECONDS);
+ this.offer(action, TIMEOUT, TimeUnit.SECONDS);
types.add(action.getPayloadClass().getSimpleName());
ecount++;
}
- embeddedLatch.await(1500, TimeUnit.MILLISECONDS);
+ if (!embeddedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+ throw new IllegalStateException("ES embedded update could not be completed within: " + TIMEOUT + "ms");
+ }
embeddedTime = System.currentTimeMillis() - embeddedTime;
/* Finally refresh affected indexes */