]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10502 Fix concurrency error during initial indexing
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 Mar 2018 08:53:14 +0000 (09:53 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 20 Mar 2018 16:18:37 +0000 (17:18 +0100)
server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java
server/sonar-server/src/main/java/org/sonar/server/es/IndexingResult.java

index aa5cd895b2b3b0d170ce68901809a3046fef5021..6d21ab38aded2541999224811995d015606ca04c 100644 (file)
@@ -36,7 +36,7 @@ public interface IndexingListener {
     @Override
     public void onFinish(IndexingResult result) {
       if (result.getFailures() > 0) {
-        throw new IllegalStateException("Unrecoverable indexation failures");
+        throw new IllegalStateException(String.format("Unrecoverable indexation failures: %d errors among %d requests", result.getFailures(), result.getTotal()));
       }
     }
   };
index b178ddc50777eff3fababa30dc6c26cfee0e2977..3c318f49aca82d16b53e5e9008a1cffc04ec51eb 100644 (file)
@@ -25,12 +25,12 @@ import java.util.concurrent.atomic.AtomicLong;
 public class IndexingResult {
 
   // FIXME should be private
-  AtomicLong total = new AtomicLong(0L);
-  private long successes = 0L;
+  final AtomicLong total = new AtomicLong(0L);
+  private final AtomicLong successes = new AtomicLong(0L);
 
   IndexingResult clear() {
     total.set(0L);
-    successes = 0L;
+    successes.set(0L);
     return this;
   }
 
@@ -39,17 +39,17 @@ public class IndexingResult {
   }
 
   public IndexingResult incrementSuccess() {
-    successes += 1;
+    successes.incrementAndGet();
     return this;
   }
 
   public void add(IndexingResult other) {
     total.addAndGet(other.total.get());
-    successes += other.successes;
+    successes.addAndGet(other.successes.get());
   }
 
   public long getFailures() {
-    return total.get() - successes;
+    return total.get() - successes.get();
   }
 
   public long getTotal() {
@@ -57,14 +57,14 @@ public class IndexingResult {
   }
 
   public long getSuccess() {
-    return successes;
+    return successes.get();
   }
 
   public double getSuccessRatio() {
-    return total.get() == 0 ? 1.0 : ((1.0 * successes) / total.get());
+    return total.get() == 0 ? 1.0 : ((1.0 * successes.get()) / total.get());
   }
 
   public boolean isSuccess() {
-    return total.get() == successes;
+    return total.get() == successes.get();
   }
 }