From 9b6a8ecd0475b2f4035ce29c04387b7fff9970b6 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 11 Feb 2015 11:17:31 +0100 Subject: [PATCH] SONAR-6130 fix deadlock during purge --- .../java/org/sonar/core/purge/PurgeDao.java | 19 +++++++++++-------- .../org/sonar/core/purge/PurgeDaoTest.java | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java index 2e9b914d605..7a9a796516e 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java @@ -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 componentIdUuids = new ArrayList(); 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(); } diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java index 421b5362283..0e2f7b0ba61 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java @@ -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 -- 2.39.5