Skip to content

Commit

Permalink
SONAR-7705 use uuid in PurgeMapper.deleteSnapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Jul 4, 2016
1 parent acb655f commit ec7f728
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
40 changes: 20 additions & 20 deletions sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
Expand Up @@ -154,60 +154,60 @@ void deleteSnapshots(PurgeSnapshotQuery... queries) {

@VisibleForTesting
protected void deleteSnapshots(List<IdUuidPair> snapshotIds) {
List<List<Long>> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);

deleteSnapshotDuplications(snapshotUuidsPartition);
deleteSnapshotDuplications(snapshotUuidsPartitions);

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

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

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

@VisibleForTesting
protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
List<List<Long>> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);

deleteSnapshotDuplications(snapshotUuidsPartition);
deleteSnapshotDuplications(snapshotUuidsPartitions);

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

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

profiler.start("deleteAnalyses (snapshots)");
for (List<String> partSnapshotUuids : snapshotUuidsPartition) {
purgeMapper.deleteAnalyses(partSnapshotUuids);
for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
purgeMapper.deleteAnalyses(snapshotUuidsPartition);
}
for (List<Long> snapshotIdPartition : snapshotIdsPartition) {
purgeMapper.deleteDescendantSnapshots(snapshotIdPartition);
for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) {
purgeMapper.deleteDescendantSnapshots(snapshotIdsPartition);
}
session.commit();
profiler.stop();
Expand Down
10 changes: 6 additions & 4 deletions sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
Expand Up @@ -113,10 +113,12 @@
</delete>

<delete id="deleteSnapshot" parameterType="map">
delete from snapshots where id in
<foreach collection="snapshotIds" open="(" close=")" item="snapshotId" separator=",">
#{snapshotId}
</foreach>
delete from snapshots
where
uuid in
<foreach collection="snapshotUuids" open="(" close=")" item="snapshotUuid" separator=",">
#{snapshotUuid}
</foreach>
</delete>

<delete id="deleteAnalyses" parameterType="map">
Expand Down
Expand Up @@ -57,6 +57,15 @@ public void should_not_fail_when_deleting_huge_number_of_snapshots() {
// The goal of this test is only to check that the query do no fail, not to check result
}

/**
* Test that SQL queries execution do not fail with a huge number of parameter
*/
@Test
public void should_not_fail_when_deleting_huge_number_of_analyses() {
new PurgeCommands(dbTester.getSession(), profiler).deleteAnalyses(getHugeNumberOfIdUuidPairs());
// The goal of this test is only to check that the query do no fail, not to check result
}

/**
* Test that all related data is purged.
*/
Expand Down

0 comments on commit ec7f728

Please sign in to comment.