From: Stephane Gamard Date: Fri, 4 Jul 2014 13:53:19 +0000 (+0200) Subject: fix quality flaw (Throw exception when ES fails within timeout) X-Git-Tag: 4.5-RC1~703 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cbadf0e71e2b64dc519b5ea33cd6022014920713;p=sonarqube.git fix quality flaw (Throw exception when ES fails within timeout) --- 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 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 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 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 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 */