Skip to content

Commit

Permalink
SONAR-7705 PurgeDao#purge: aborted analysis can be delete from root
Browse files Browse the repository at this point in the history
no need to try and delete them on each node of scope PROJECT in the tree
  • Loading branch information
sns-seb committed Jul 4, 2016
1 parent 3f55a9c commit 2c08255
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
25 changes: 12 additions & 13 deletions sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
Expand Up @@ -160,27 +160,28 @@ protected void deleteSnapshots(List<IdUuidPair> snapshotIds) {
deleteSnapshotDuplications(snapshotUuidsPartitions); deleteSnapshotDuplications(snapshotUuidsPartitions);


profiler.start("deleteSnapshotEvents (events)"); profiler.start("deleteSnapshotEvents (events)");
for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) { snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshotEvents);
purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition);
}
session.commit(); session.commit();
profiler.stop(); profiler.stop();


profiler.start("deleteSnapshotMeasures (project_measures)"); profiler.start("deleteSnapshotMeasures (project_measures)");
for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) { snapshotIdsPartitions.forEach(purgeMapper::deleteSnapshotMeasures);
purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition);
}
session.commit(); session.commit();
profiler.stop(); profiler.stop();


profiler.start("deleteSnapshot (snapshots)"); profiler.start("deleteSnapshot (snapshots)");
for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) { snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshot);
purgeMapper.deleteSnapshot(snapshotUuidsPartition);
}
session.commit(); session.commit();
profiler.stop(); profiler.stop();
} }


void deleteAnalyses(PurgeSnapshotQuery... queries) {
List<IdUuidPair> snapshotIds = from(asList(queries))
.transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids)
.toList();
deleteAnalyses(snapshotIds);
}

@VisibleForTesting @VisibleForTesting
protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) { protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
Expand Down Expand Up @@ -240,11 +241,9 @@ protected void purgeSnapshots(Iterable<IdUuidPair> snapshotIdUuidPairs) {
profiler.stop(); profiler.stop();
} }


private void deleteSnapshotDuplications(Iterable<List<String>> snapshotUuidsPartition) { private void deleteSnapshotDuplications(List<List<String>> snapshotUuidsPartition) {
profiler.start("deleteSnapshotDuplications (duplications_index)"); profiler.start("deleteSnapshotDuplications (duplications_index)");
for (List<String> partSnapshotUuids : snapshotUuidsPartition) { snapshotUuidsPartition.forEach(purgeMapper::deleteSnapshotDuplications);
purgeMapper.deleteSnapshotDuplications(partSnapshotUuids);
}
session.commit(); session.commit();
profiler.stop(); profiler.stop();
} }
Expand Down
20 changes: 10 additions & 10 deletions sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
Expand Up @@ -57,10 +57,10 @@ public PurgeDao(ResourceDao resourceDao, System2 system2) {
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) {
PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeMapper mapper = session.getMapper(PurgeMapper.class);
PurgeCommands commands = new PurgeCommands(session, mapper, profiler); PurgeCommands commands = new PurgeCommands(session, mapper, profiler);
deleteAbortedAnalyses(conf.rootProjectIdUuid().getUuid(), commands);
List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session); List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session);
for (ResourceDto project : projects) { for (ResourceDto project : projects) {
LOG.debug("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]"); LOG.debug("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]");
deleteAbortedBuilds(project, commands);
purge(project, conf.scopesWithoutHistoricalData(), commands); purge(project, conf.scopesWithoutHistoricalData(), commands);
} }
for (ResourceDto project : projects) { for (ResourceDto project : projects) {
Expand All @@ -83,35 +83,35 @@ private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper m
listener.onIssuesRemoval(conf.rootProjectIdUuid().getUuid(), issueKeys); 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"); LOG.debug("<- Delete aborted builds");
PurgeSnapshotQuery query = PurgeSnapshotQuery.create() PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
.setIslast(false) .setIslast(false)
.setStatus(UNPROCESSED_STATUS) .setStatus(UNPROCESSED_STATUS)
.setRootComponentUuid(project.getUuid()); .setRootComponentUuid(rootUuid);
commands.deleteSnapshots(query); commands.deleteAnalyses(query);
} }


private static void purge(ResourceDto project, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { private static void purge(ResourceDto project, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) {
List<String> projectSnapshotIds = purgeCommands.selectSnapshotUuids( List<String> projectSnapshotUuids = purgeCommands.selectSnapshotUuids(
PurgeSnapshotQuery.create() PurgeSnapshotQuery.create()
.setComponentUuid(project.getUuid()) .setComponentUuid(project.getUuid())
.setIslast(false) .setIslast(false)
.setNotPurged(true)); .setNotPurged(true));
for (String analysisUuid : projectSnapshotIds) { for (String snapshotUuid : projectSnapshotUuids) {
LOG.debug("<- Clean analysis " + analysisUuid); LOG.debug("<- Clean analysis " + snapshotUuid);
if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) { if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) {
PurgeSnapshotQuery query = PurgeSnapshotQuery.create() PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
.setIslast(false) .setIslast(false)
.setScopes(scopesWithoutHistoricalData) .setScopes(scopesWithoutHistoricalData)
.setAnalysisUuid(analysisUuid); .setAnalysisUuid(snapshotUuid);
purgeCommands.deleteSnapshots(query); purgeCommands.deleteSnapshots(query);
} }


// must be executed at the end for reentrance // must be executed at the end for reentrance
purgeCommands.purgeSnapshots( purgeCommands.purgeSnapshots(
PurgeSnapshotQuery.create().setAnalysisUuid(analysisUuid).setNotPurged(true), PurgeSnapshotQuery.create().setAnalysisUuid(snapshotUuid).setNotPurged(true),
PurgeSnapshotQuery.create().setSnapshotUuid(analysisUuid).setNotPurged(true)); PurgeSnapshotQuery.create().setSnapshotUuid(snapshotUuid).setNotPurged(true));
} }
} }


Expand Down
Expand Up @@ -6,9 +6,9 @@ Snapshot 2 has been deleted
<dataset> <dataset>


<!-- the project --> <!-- the project -->
<projects uuid="projectUUID" <projects uuid="P1"
uuid_path="NOT_USED" uuid_path="NOT_USED"
project_uuid="projectUUID" project_uuid="P1"
long_name="[null]" long_name="[null]"
scope="PRJ" scope="PRJ"
qualifier="TRK" qualifier="TRK"
Expand All @@ -26,9 +26,9 @@ Snapshot 2 has been deleted
<!-- past snapshot with status "processed" and already purged --> <!-- past snapshot with status "processed" and already purged -->
<snapshots id="1" <snapshots id="1"
uuid="u1" uuid="u1"
component_uuid="projectUUID" component_uuid="P1"
parent_snapshot_id="[null]" parent_snapshot_id="[null]"
root_component_uuid="projectUUID" root_component_uuid="P1"
root_snapshot_id="[null]" root_snapshot_id="[null]"
status="P" status="P"
islast="[false]" islast="[false]"
Expand Down Expand Up @@ -59,9 +59,9 @@ Snapshot 2 has been deleted
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
<snapshots id="3" <snapshots id="3"
uuid="u3" uuid="u3"
component_uuid="projectUUID" component_uuid="P1"
parent_snapshot_id="[null]" parent_snapshot_id="[null]"
root_component_uuid="projectUUID" root_component_uuid="P1"
root_snapshot_id="[null]" root_snapshot_id="[null]"
status="P" status="P"
islast="[true]" islast="[true]"
Expand Down
@@ -1,9 +1,9 @@
<dataset> <dataset>


<!-- the project --> <!-- the project -->
<projects uuid="projectUUID" <projects uuid="P1"
uuid_path="NOT_USED" uuid_path="NOT_USED"
project_uuid="projectUUID" project_uuid="P1"
long_name="[null]" long_name="[null]"
scope="PRJ" scope="PRJ"
qualifier="TRK" qualifier="TRK"
Expand All @@ -16,14 +16,14 @@
authorization_updated_at="[null]" authorization_updated_at="[null]"
id="1" id="1"
enabled="[true]" enabled="[true]"
root_uuid="projectUUID"/> root_uuid="P1"/>


<!-- past snapshot with status "processed" and already purged --> <!-- past snapshot with status "processed" and already purged -->
<snapshots id="1" <snapshots id="1"
uuid="u1" uuid="u1"
component_uuid="projectUUID" component_uuid="P1"
parent_snapshot_id="[null]" parent_snapshot_id="[null]"
root_component_uuid="projectUUID" root_component_uuid="P1"
root_snapshot_id="[null]" root_snapshot_id="[null]"
status="P" status="P"
islast="[false]" islast="[false]"
Expand Down Expand Up @@ -54,9 +54,9 @@
<!-- snapshot with status "unprocessed" -> to be deleted --> <!-- snapshot with status "unprocessed" -> to be deleted -->
<snapshots id="2" <snapshots id="2"
uuid="u2" uuid="u2"
component_uuid="projectUUID" component_uuid="P1"
parent_snapshot_id="[null]" parent_snapshot_id="[null]"
root_component_uuid="projectUUID" root_component_uuid="P1"
root_snapshot_id="[null]" root_snapshot_id="[null]"
status="U" status="U"
islast="[false]" islast="[false]"
Expand Down Expand Up @@ -87,9 +87,9 @@
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
<snapshots id="3" <snapshots id="3"
uuid="u3" uuid="u3"
component_uuid="projectUUID" component_uuid="P1"
parent_snapshot_id="[null]" parent_snapshot_id="[null]"
root_component_uuid="projectUUID" root_component_uuid="P1"
root_snapshot_id="[null]" root_snapshot_id="[null]"
status="P" status="P"
islast="[true]" islast="[true]"
Expand Down

0 comments on commit 2c08255

Please sign in to comment.