aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-29 16:32:26 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-04 15:20:30 +0200
commit2c08255d6da31d9599edc7888cb4863e6e71cb1a (patch)
treecfbf25481499bbe4bbed85dbaa3d3299cdd274e7 /sonar-db
parent3f55a9c69829198a0931f45e5a85f19960af37b5 (diff)
downloadsonarqube-2c08255d6da31d9599edc7888cb4863e6e71cb1a.tar.gz
sonarqube-2c08255d6da31d9599edc7888cb4863e6e71cb1a.zip
SONAR-7705 PurgeDao#purge: aborted analysis can be delete from root
no need to try and delete them on each node of scope PROJECT in the tree
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java25
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java20
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml12
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml18
4 files changed, 37 insertions, 38 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
index ab67bb7aa38..b8035f09342 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -160,27 +160,28 @@ class PurgeCommands {
deleteSnapshotDuplications(snapshotUuidsPartitions);
profiler.start("deleteSnapshotEvents (events)");
- for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
- purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition);
- }
+ snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshotEvents);
session.commit();
profiler.stop();
profiler.start("deleteSnapshotMeasures (project_measures)");
- for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) {
- purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition);
- }
+ snapshotIdsPartitions.forEach(purgeMapper::deleteSnapshotMeasures);
session.commit();
profiler.stop();
profiler.start("deleteSnapshot (snapshots)");
- for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
- purgeMapper.deleteSnapshot(snapshotUuidsPartition);
- }
+ snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshot);
session.commit();
profiler.stop();
}
+ void deleteAnalyses(PurgeSnapshotQuery... queries) {
+ List<IdUuidPair> snapshotIds = from(asList(queries))
+ .transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids)
+ .toList();
+ deleteAnalyses(snapshotIds);
+ }
+
@VisibleForTesting
protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
@@ -240,11 +241,9 @@ class PurgeCommands {
profiler.stop();
}
- private void deleteSnapshotDuplications(Iterable<List<String>> snapshotUuidsPartition) {
+ private void deleteSnapshotDuplications(List<List<String>> snapshotUuidsPartition) {
profiler.start("deleteSnapshotDuplications (duplications_index)");
- for (List<String> partSnapshotUuids : snapshotUuidsPartition) {
- purgeMapper.deleteSnapshotDuplications(partSnapshotUuids);
- }
+ snapshotUuidsPartition.forEach(purgeMapper::deleteSnapshotDuplications);
session.commit();
profiler.stop();
}
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
index 1df8e29cf6c..96df1ac2db1 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -57,10 +57,10 @@ public class PurgeDao implements Dao {
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) {
PurgeMapper mapper = session.getMapper(PurgeMapper.class);
PurgeCommands commands = new PurgeCommands(session, mapper, profiler);
+ deleteAbortedAnalyses(conf.rootProjectIdUuid().getUuid(), commands);
List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session);
for (ResourceDto project : projects) {
LOG.debug("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]");
- deleteAbortedBuilds(project, commands);
purge(project, conf.scopesWithoutHistoricalData(), commands);
}
for (ResourceDto project : projects) {
@@ -83,35 +83,35 @@ public class PurgeDao implements Dao {
listener.onIssuesRemoval(conf.rootProjectIdUuid().getUuid(), issueKeys);
}
- private static void deleteAbortedBuilds(ResourceDto project, PurgeCommands commands) {
+ private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) {
LOG.debug("<- Delete aborted builds");
PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
.setIslast(false)
.setStatus(UNPROCESSED_STATUS)
- .setRootComponentUuid(project.getUuid());
- commands.deleteSnapshots(query);
+ .setRootComponentUuid(rootUuid);
+ commands.deleteAnalyses(query);
}
private static void purge(ResourceDto project, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) {
- List<String> projectSnapshotIds = purgeCommands.selectSnapshotUuids(
+ List<String> projectSnapshotUuids = purgeCommands.selectSnapshotUuids(
PurgeSnapshotQuery.create()
.setComponentUuid(project.getUuid())
.setIslast(false)
.setNotPurged(true));
- for (String analysisUuid : projectSnapshotIds) {
- LOG.debug("<- Clean analysis " + analysisUuid);
+ for (String snapshotUuid : projectSnapshotUuids) {
+ LOG.debug("<- Clean analysis " + snapshotUuid);
if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) {
PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
.setIslast(false)
.setScopes(scopesWithoutHistoricalData)
- .setAnalysisUuid(analysisUuid);
+ .setAnalysisUuid(snapshotUuid);
purgeCommands.deleteSnapshots(query);
}
// must be executed at the end for reentrance
purgeCommands.purgeSnapshots(
- PurgeSnapshotQuery.create().setAnalysisUuid(analysisUuid).setNotPurged(true),
- PurgeSnapshotQuery.create().setSnapshotUuid(analysisUuid).setNotPurged(true));
+ PurgeSnapshotQuery.create().setAnalysisUuid(snapshotUuid).setNotPurged(true),
+ PurgeSnapshotQuery.create().setSnapshotUuid(snapshotUuid).setNotPurged(true));
}
}
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml
index 21a21842005..738be9fcabe 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml
@@ -6,9 +6,9 @@ Snapshot 2 has been deleted
<dataset>
<!-- the project -->
- <projects uuid="projectUUID"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="projectUUID"
+ project_uuid="P1"
long_name="[null]"
scope="PRJ"
qualifier="TRK"
@@ -26,9 +26,9 @@ Snapshot 2 has been deleted
<!-- past snapshot with status "processed" and already purged -->
<snapshots id="1"
uuid="u1"
- component_uuid="projectUUID"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="projectUUID"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
@@ -59,9 +59,9 @@ Snapshot 2 has been deleted
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
<snapshots id="3"
uuid="u3"
- component_uuid="projectUUID"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="projectUUID"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[true]"
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml
index 6a4b6ac9b03..ccb841c1541 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml
@@ -1,9 +1,9 @@
<dataset>
<!-- the project -->
- <projects uuid="projectUUID"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="projectUUID"
+ project_uuid="P1"
long_name="[null]"
scope="PRJ"
qualifier="TRK"
@@ -16,14 +16,14 @@
authorization_updated_at="[null]"
id="1"
enabled="[true]"
- root_uuid="projectUUID"/>
+ root_uuid="P1"/>
<!-- past snapshot with status "processed" and already purged -->
<snapshots id="1"
uuid="u1"
- component_uuid="projectUUID"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="projectUUID"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
@@ -54,9 +54,9 @@
<!-- snapshot with status "unprocessed" -> to be deleted -->
<snapshots id="2"
uuid="u2"
- component_uuid="projectUUID"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="projectUUID"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="U"
islast="[false]"
@@ -87,9 +87,9 @@
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
<snapshots id="3"
uuid="u3"
- component_uuid="projectUUID"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="projectUUID"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[true]"