]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5614 Fix bug when synchronizing a lof of issues
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Sep 2014 10:00:54 +0000 (12:00 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Sep 2014 10:00:54 +0000 (12:00 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java

index 92f053e637064bbed1e5fe4799bd911bbe0fa5e2..3c0d2f90b1b4881bfce3c68245004100dc6a24ba 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.core.component.AuthorizedComponentDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
@@ -79,24 +78,30 @@ public class UploadReportAction implements RequestHandler {
 
     // Switch Issue search
     if (settings.getString("sonar.issues.use_es_backend") != null) {
+      String projectKey = request.mandatoryParam(PARAM_PROJECT);
+
       DbSession session = dbClient.openSession(false);
       try {
-        String projectKey = request.mandatoryParam(PARAM_PROJECT);
-        AuthorizedComponentDto project = dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
-
+        dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
         computationService.create(projectKey);
 
+      } finally {
+        MyBatis.closeQuietly(session);
+      }
+
+      // Synchronization of lot of data can only be done with a batch session for the moment
+      session = dbClient.openSession(true);
+      try {
         // Synchronize project permission indexes if no permission found on it
-        if (index.get(IssueAuthorizationIndex.class).getNullableByKey(project.key()) == null) {
-          permissionService.synchronizePermissions(session, project.key());
+        if (index.get(IssueAuthorizationIndex.class).getNullableByKey(projectKey) == null) {
+          permissionService.synchronizePermissions(session, projectKey);
           session.commit();
         }
 
         // Index project's issues
         dbClient.issueDao().synchronizeAfter(session,
           index.get(IssueIndex.class).getLastSynchronization(),
-          ImmutableMap.of("project", project.key()));
-
+          ImmutableMap.of("project", projectKey));
         session.commit();
       } finally {
         MyBatis.closeQuietly(session);
index 1ffcb84bf468227893895d4c904c0cbb97c5c396..c881df181f93e9d155fadef09878e5f170a3ce1e 100644 (file)
@@ -78,7 +78,6 @@ public class IndexSynchronizer {
     } else {
       LOG.info("Synchronizing {} records for updates after {}", index.getIndexType(), lastSynch);
     }
-    dao.synchronizeAfter(session,
-      index.getLastSynchronization());
+    dao.synchronizeAfter(session, lastSynch);
   }
 }
index e854da588b694ab70b4b700d8a48a771983da26d..9c29f6ed39c24ce44780a2f0870dc7e0a7e83e8d 100644 (file)
@@ -647,17 +647,27 @@ public class IssueIndexMediumTest {
 
     // Clear issue index in order to simulate these issues have been inserted without being indexed in E/S (from a previous version of SQ or from batch)
     tester.get(BackendCleanup.class).clearIndex(IndexDefinition.ISSUES);
+    tester.clearIndexes();
+    session.commit();
+    session.clearCache();
 
-    DbSession newSession = db.openSession(false);
+    DbSession newSession = db.openSession(true);
     newSession.setImplicitCommitSize(10);
     try {
-      db.issueDao().synchronizeAfter(newSession, new Date(0));
+      db.issueDao().synchronizeAfter(newSession, index.getLastSynchronization());
       newSession.commit();
 
-      assertThat(index.search(IssueQuery.builder().build(), new QueryContext().setMaxLimit()).getHits()).hasSize(10);
     } finally {
       newSession.close();
+      newSession.clearCache();
     }
+    session.commit();
+    session.clearCache();
+
+    // This test is working with executeStartupTasks !
+//    tester.get(Platform.class).executeStartupTasks();
+
+    assertThat(index.search(IssueQuery.builder().build(), new QueryContext().setMaxLimit()).getHits()).hasSize(11);
   }
 
 }