]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6130 fix deadlock during purge 84/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 11 Feb 2015 10:17:31 +0000 (11:17 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 11 Feb 2015 10:17:31 +0000 (11:17 +0100)
sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java

index 2e9b914d6055b6271669600ee17cae17d854fe77..7a9a796516eb7d1bd12cf04202f50f82cd633b3a 100644 (file)
@@ -32,10 +32,7 @@ import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.resource.ResourceDao;
 import org.sonar.core.resource.ResourceDto;
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @since 2.14
@@ -131,16 +128,22 @@ public class PurgeDao {
   }
 
   private void disableOrphanResources(final ResourceDto project, final SqlSession session, final PurgeMapper purgeMapper, final PurgeListener purgeListener) {
+    final List<IdUuidPair> componentIdUuids = new ArrayList<IdUuidPair>();
     session.select("org.sonar.core.purge.PurgeMapper.selectResourceIdsToDisable", project.getId(), new ResultHandler() {
       @Override
       public void handleResult(ResultContext resultContext) {
-        IdUuidPair resourceIdUuid = (IdUuidPair) resultContext.getResultObject();
-        if (resourceIdUuid.getId() != null) {
-          disableResource(resourceIdUuid, purgeMapper);
-          purgeListener.onComponentDisabling(resourceIdUuid.getUuid());
+        IdUuidPair componentIdUuid = (IdUuidPair) resultContext.getResultObject();
+        if (componentIdUuid.getId() != null) {
+          componentIdUuids.add(componentIdUuid);
         }
       }
     });
+
+    for (IdUuidPair componentIdUuid : componentIdUuids) {
+      disableResource(componentIdUuid, purgeMapper);
+      purgeListener.onComponentDisabling(componentIdUuid.getUuid());
+    }
+
     session.commit();
   }
 
index 421b536228300dba21289c45c63ef6fa092f6c72..0e2f7b0ba610033c3b3bc86ee67fb068913819b4 100644 (file)
@@ -58,6 +58,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
 
     sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), new PurgeProfiler(), system2);
   }
+
   @After
   public void after() {
     MyBatis.closeQuietly(dbSession);
@@ -95,7 +96,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
   public void disable_resources_without_last_snapshot() {
     setupData("disable_resources_without_last_snapshot");
     sut.purge(new PurgeConfiguration(1L, new String[0], 30, system2), PurgeListener.EMPTY);
-    checkTables("disable_resources_without_last_snapshot", new String[]{"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
+    checkTables("disable_resources_without_last_snapshot", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
   }
 
   @Test