return purgeMapper.selectSnapshotIdsAndUuids(query).stream().map(IdUuidPair::getUuid).collect(Collectors.toList());
}
+ List<IdUuidPair> selectSnapshotIdUuids(PurgeSnapshotQuery query) {
+ return purgeMapper.selectSnapshotIdsAndUuids(query);
+ }
+
void deleteAnalyses(String rootUuid) {
deleteAnalyses(purgeMapper.selectSnapshotIdsAndUuids(PurgeSnapshotQuery.create().setComponentUuid(rootUuid)));
}
@VisibleForTesting
protected void purgeSnapshots(Iterable<IdUuidPair> snapshotIdUuidPairs) {
- // note that events are not deleted
List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIdUuidPairs), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIdUuidPairs), MAX_SNAPSHOTS_PER_QUERY);
profiler.stop();
profiler.start("updatePurgeStatusToOne (snapshots)");
- snapshotIdUuidPairs.iterator().forEachRemaining(idUuidPair -> purgeMapper.updatePurgeStatusToOne(idUuidPair.getUuid()));
+ snapshotUuidsPartitions.forEach(snapshotUuidsPartition -> purgeMapper.updatePurgeStatusToOne(snapshotUuidsPartition));
+ session.commit();
+ profiler.stop();
+ }
+
+ public void purgeAnalyses(List<IdUuidPair> analysisUuids) {
+ List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
+ List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
+
+ deleteSnapshotDuplications(analysisUuidsPartitions);
+
+ profiler.start("deleteSnapshotWastedMeasures (project_measures)");
+ List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
+ analysisUuidsPartitions.stream()
+ .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
+ session.commit();
+ profiler.stop();
+
+ profiler.start("updatePurgeStatusToOne (snapshots)");
+ analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
+ analysisIdsPartitions.forEach(purgeMapper::updateDescendantPurgeStatusToOne);
session.commit();
profiler.stop();
}
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);
+ String rootUuid = conf.rootProjectIdUuid().getUuid();
+ deleteAbortedAnalyses(rootUuid, commands);
deleteDataOfComponentsWithoutHistoricalData(session, conf.rootProjectIdUuid().getUuid(), conf.scopesWithoutHistoricalData(), commands);
+
+ List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids(
+ PurgeSnapshotQuery.create()
+ .setComponentUuid(rootUuid)
+ .setIslast(false)
+ .setNotPurged(true));
+ commands.purgeAnalyses(analysisUuids);
+
// retrieve all nodes in the tree (including root) with scope=PROJECT
List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session);
- for (ResourceDto project : projects) {
- LOG.debug("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]");
- purge(project.getUuid(), commands);
- }
for (ResourceDto project : projects) {
disableOrphanResources(project, session, mapper, listener);
}
.setSortFields(UUID_FIELD_SORT);
}
- private static void purge(String componentUuid, PurgeCommands purgeCommands) {
- List<String> projectSnapshotUuids = purgeCommands.selectSnapshotUuids(
- PurgeSnapshotQuery.create()
- .setComponentUuid(componentUuid)
- .setIslast(false)
- .setNotPurged(true));
- for (String snapshotUuid : projectSnapshotUuids) {
- LOG.debug("<- Clean analysis " + snapshotUuid);
-
- // must be executed at the end for reentrance
- purgeCommands.purgeSnapshots(
- PurgeSnapshotQuery.create().setAnalysisUuid(snapshotUuid).setNotPurged(true),
- PurgeSnapshotQuery.create().setSnapshotUuid(snapshotUuid).setNotPurged(true));
- }
- }
-
private void disableOrphanResources(ResourceDto project, SqlSession session, PurgeMapper purgeMapper, PurgeListener purgeListener) {
List<String> componentUuids = new ArrayList<>();
session.select("org.sonar.db.purge.PurgeMapper.selectComponentUuidsToDisable", project.getUuid(),
void deleteSnapshotWastedMeasures(@Param("snapshotIds") List<Long> snapshotIds, @Param("mids") List<Long> metricIds);
- void updatePurgeStatusToOne(String snapshotUuid);
+ void deleteAnalysisWastedMeasures(@Param("analysisUuids") List<String> analysisUuids, @Param("metricIds") List<Long> metricIds);
+
+ void updatePurgeStatusToOne(@Param("analysisUuids") List<String> analysisUuid);
+
+ void updateDescendantPurgeStatusToOne(@Param("analysisIds") List<Long> analysisIds);
void disableComponent(String componentUuid);
</where>
</delete>
- <update id="updatePurgeStatusToOne" parameterType="string">
+ <delete id="deleteAnalysisWastedMeasures" parameterType="map">
+ delete from project_measures
+ <where>
+ analysis_uuid in
+ <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
+ #{analysisUuid}
+ </foreach>
+ and (person_id is not null
+ <if test="metricIds.size()>0">
+ or metric_id in
+ <foreach collection="metricIds" open="(" item="metricId" separator="," close=")">
+ #{metricId}
+ </foreach>
+ </if>
+ )
+ </where>
+ </delete>
+
+ <update id="updatePurgeStatusToOne" parameterType="map">
update
snapshots
set
purge_status = 1
where
- uuid = #{snapshotUuid}
+ uuid in
+ <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
+ #{analysisUuid}
+ </foreach>
+ </update>
+
+ <update id="updateDescendantPurgeStatusToOne" parameterType="map">
+ update
+ snapshots
+ set
+ purge_status = 1
+ where
+ root_snapshot_id in
+ <foreach collection="analysisIds" open="(" close=")" item="analysisId" separator=",">
+ #{analysisId}
+ </foreach>
</update>
<update id="disableComponent" parameterType="string">
<dataset>
<!-- the project -->
- <projects uuid="ABCD"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="ABCD"
+ project_uuid="P1"
module_uuid="[null]"
module_uuid_path="."
created_at="[null]"
authorization_updated_at="[null]"
id="1"
enabled="[false]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the directory -->
<projects uuid="EFGH"
uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
+ project_uuid="P1"
+ module_uuid="P1"
module_uuid_path="."
created_at="[null]"
long_name="[null]"
authorization_updated_at="[null]"
id="2"
enabled="[false]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the file -->
<projects uuid="GHIJ"
uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
- module_uuid_path=".ABCD."
+ project_uuid="P1"
+ module_uuid="P1"
+ module_uuid_path=".P1."
created_at="[null]"
long_name="[null]"
scope="FIL"
authorization_updated_at="[null]"
id="3"
enabled="[false]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<snapshots id="1"
uuid="u1"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
uuid="u2"
component_uuid="EFGH"
parent_snapshot_id="1"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
uuid="u3"
component_uuid="GHIJ"
parent_snapshot_id="2"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
<issues id="1"
kee="ISSUE-1"
component_uuid="GHIJ"
- project_uuid="ABCD"
+ project_uuid="P1"
status="CLOSED"
issue_close_date="1396994400000"
resolution="REMOVED"
<issues id="2"
kee="ISSUE-2"
component_uuid="EFGH"
- project_uuid="ABCD"
+ project_uuid="P1"
status="CLOSED"
issue_close_date="1396994400000"
resolution="REMOVED"
<!-- Open issue on project -->
<issues id="3"
kee="ISSUE-3"
- component_uuid="ABCD"
- project_uuid="ABCD"
+ component_uuid="P1"
+ project_uuid="P1"
status="CLOSED"
issue_close_date="1396994400000"
resolution="REMOVED"
<issues id="4"
kee="ISSUE-4"
component_uuid="GHIJ"
- project_uuid="ABCD"
+ project_uuid="P1"
status="CLOSED"
issue_close_date="1449529200000"
resolution="FIXED"
<dataset>
<!-- the project -->
- <projects uuid="ABCD"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="ABCD"
+ project_uuid="P1"
module_uuid="[null]"
module_uuid_path="."
created_at="[null]"
authorization_updated_at="[null]"
id="1"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the directory -->
<projects uuid="EFGH"
uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
+ project_uuid="P1"
+ module_uuid="P1"
module_uuid_path="."
created_at="[null]"
long_name="[null]"
authorization_updated_at="[null]"
id="2"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the file -->
<projects uuid="GHIJ"
uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
- module_uuid_path=".ABCD."
+ project_uuid="P1"
+ module_uuid="P1"
+ module_uuid_path=".P1."
created_at="[null]"
long_name="[null]"
scope="FIL"
authorization_updated_at="[null]"
id="3"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<snapshots id="1"
uuid="u1"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
uuid="u2"
component_uuid="EFGH"
parent_snapshot_id="1"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
uuid="u3"
component_uuid="GHIJ"
parent_snapshot_id="2"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
<issues id="1"
kee="ISSUE-1"
component_uuid="GHIJ"
- project_uuid="ABCD"
+ project_uuid="P1"
status="OPEN"
issue_close_date="[null]"
resolution="[null]"
<issues id="2"
kee="ISSUE-2"
component_uuid="EFGH"
- project_uuid="ABCD"
+ project_uuid="P1"
status="OPEN"
issue_close_date="[null]"
resolution="[null]"
<!-- Open issue on project -->
<issues id="3"
kee="ISSUE-3"
- component_uuid="ABCD"
- project_uuid="ABCD"
+ component_uuid="P1"
+ project_uuid="P1"
status="CONFIRM"
issue_close_date="[null]"
resolution="[null]"
<issues id="4"
kee="ISSUE-4"
component_uuid="GHIJ"
- project_uuid="ABCD"
+ project_uuid="P1"
status="CLOSED"
issue_close_date="1449529200000"
resolution="FIXED"
<dataset>
<!-- the project -->
- <projects uuid="ABCD"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="ABCD"
+ project_uuid="P1"
module_uuid="[null]"
module_uuid_path="."
enabled="[true]"
qualifier="TRK"
kee="project"
name="project"
- root_uuid="ABCD"
+ root_uuid="P1"
description="[null]"
language="java"
copy_component_uuid="[null]"
<!-- snapshot already purged -->
<snapshots id="1"
uuid="u1"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
<!-- do not purge snapshot with islast=true-->
<snapshots id="2"
uuid="u2"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[true]"
<!-- snapshot to be purged -->
<snapshots id="3"
uuid="u3"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
<dataset>
<!-- the project -->
- <projects uuid="ABCD"
+ <projects uuid="P1"
uuid_path="NOT_USED"
- project_uuid="ABCD"
+ project_uuid="P1"
module_uuid="[null]"
module_uuid_path="."
enabled="[true]"
qualifier="TRK"
kee="project"
name="project"
- root_uuid="ABCD"
+ root_uuid="P1"
description="[null]"
language="java"
copy_component_uuid="[null]"
<!-- snapshot already purged -->
<snapshots id="1"
uuid="u1"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
<!-- do not purge snapshot with islast=true-->
<snapshots id="2"
uuid="u2"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[true]"
<!-- snapshot to be purged -->
<snapshots id="3"
uuid="u3"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"