aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-db/src/main/java')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java75
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java71
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java11
3 files changed, 49 insertions, 108 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 7e728f84ca0..03d53ea9d30 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
@@ -21,8 +21,6 @@ package org.sonar.db.purge;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.ibatis.session.SqlSession;
@@ -72,79 +70,57 @@ class PurgeCommands {
// possible missing optimization: filter requests according to resource scope
profiler.start("deleteResourceLinks (project_links)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentLinks(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentLinks);
session.commit();
profiler.stop();
profiler.start("deleteResourceProperties (properties)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentProperties(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentProperties);
session.commit();
profiler.stop();
profiler.start("deleteResourceIndex (resource_index)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteResourceIndex(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteResourceIndex);
session.commit();
profiler.stop();
profiler.start("deleteResourceGroupRoles (group_roles)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentGroupRoles(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentGroupRoles);
session.commit();
profiler.stop();
profiler.start("deleteResourceUserRoles (user_roles)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentUserRoles(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentUserRoles);
session.commit();
profiler.stop();
profiler.start("deleteResourceManualMeasures (manual_measures)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentManualMeasures(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentManualMeasures);
session.commit();
profiler.stop();
profiler.start("deleteComponentIssueChanges (issue_changes)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentIssueChanges(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssueChanges);
session.commit();
profiler.stop();
profiler.start("deleteComponentIssues (issues)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentIssues(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssues);
session.commit();
profiler.stop();
profiler.start("deleteComponentEvents (events)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentEvents(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentEvents);
session.commit();
profiler.stop();
profiler.start("deleteResource (projects)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponents(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
session.commit();
profiler.stop();
profiler.start("deleteAuthors (authors)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteAuthors(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteAuthors);
session.commit();
profiler.stop();
}
@@ -223,38 +199,12 @@ class PurgeCommands {
profiler.start("deleteAnalyses (snapshots)");
analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses);
+ // FIXME remove this when cardinality of snapshots has been changed
analysisIdsPartitions.forEach(purgeMapper::deleteDescendantSnapshots);
session.commit();
profiler.stop();
}
- void purgeSnapshots(PurgeSnapshotQuery... queries) {
- // use LinkedHashSet to keep order by remove duplicated ids
- LinkedHashSet<IdUuidPair> snapshotIds = Sets.newLinkedHashSet(from(asList(queries))
- .transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids));
- purgeSnapshots(snapshotIds);
- }
-
- @VisibleForTesting
- protected void purgeSnapshots(Iterable<IdUuidPair> snapshotIdUuidPairs) {
- 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);
-
- deleteSnapshotDuplications(snapshotUuidsPartitions);
-
- profiler.start("deleteSnapshotWastedMeasures (project_measures)");
- List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
- snapshotIdsPartitions.stream()
- .forEach(snapshotIdsPartition -> purgeMapper.deleteSnapshotWastedMeasures(snapshotIdsPartition, metricIdsWithoutHistoricalData));
- session.commit();
- profiler.stop();
-
- profiler.start("updatePurgeStatusToOne (snapshots)");
- 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);
@@ -270,6 +220,7 @@ class PurgeCommands {
profiler.start("updatePurgeStatusToOne (snapshots)");
analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
+ // FIXME remove this when cardinality of snapshots has been changed
analysisIdsPartitions.forEach(purgeMapper::updateDescendantPurgeStatusToOne);
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 b15c88048bd..a470b4d2dfd 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
@@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -36,8 +35,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTreeQuery;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceDto;
import static java.util.Collections.emptyList;
import static org.sonar.api.utils.DateUtils.dateToLong;
@@ -51,12 +48,10 @@ public class PurgeDao implements Dao {
private static final String[] UNPROCESSED_STATUS = new String[] {"U"};
private static final List<String> UUID_FIELD_SORT = Collections.singletonList("uuid");
- private final ResourceDao resourceDao;
private final ComponentDao componentDao;
private final System2 system2;
- public PurgeDao(ResourceDao resourceDao, ComponentDao componentDao, System2 system2) {
- this.resourceDao = resourceDao;
+ public PurgeDao(ComponentDao componentDao, System2 system2) {
this.componentDao = componentDao;
this.system2 = system2;
}
@@ -66,26 +61,25 @@ public class PurgeDao implements Dao {
PurgeCommands commands = new PurgeCommands(session, mapper, profiler);
String rootUuid = conf.rootProjectIdUuid().getUuid();
deleteAbortedAnalyses(rootUuid, commands);
- deleteDataOfComponentsWithoutHistoricalData(session, conf.rootProjectIdUuid().getUuid(), conf.scopesWithoutHistoricalData(), commands);
+ deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands);
+ purgeAnalyses(commands, rootUuid);
+ disableOrphanResources(rootUuid, session, mapper, listener);
+ deleteOldClosedIssues(conf, mapper, listener);
+ }
+ private static void purgeAnalyses(PurgeCommands commands, String rootUuid) {
List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids(
- PurgeSnapshotQuery.create()
- .setComponentUuid(rootUuid)
- .setIslast(false)
- .setNotPurged(true));
+ 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) {
- disableOrphanResources(project, session, mapper, listener);
- }
- deleteOldClosedIssues(conf, mapper, listener);
}
private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper mapper, PurgeListener listener) {
Date toDate = conf.maxLiveDateOfClosedIssues();
- List<String> issueKeys = mapper.selectOldClosedIssueKeys(conf.rootProjectIdUuid().getUuid(), dateToLong(toDate));
+ String rootUuid = conf.rootProjectIdUuid().getUuid();
+ List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate));
executeLargeInputs(issueKeys, input -> {
mapper.deleteIssueChangesFromIssueKeys(input);
return emptyList();
@@ -94,7 +88,7 @@ public class PurgeDao implements Dao {
mapper.deleteIssuesFromKeys(input);
return emptyList();
});
- listener.onIssuesRemoval(conf.rootProjectIdUuid().getUuid(), issueKeys);
+ listener.onIssuesRemoval(rootUuid, issueKeys);
}
private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) {
@@ -145,9 +139,10 @@ public class PurgeDao implements Dao {
.setSortFields(UUID_FIELD_SORT);
}
- private void disableOrphanResources(ResourceDto project, SqlSession session, PurgeMapper purgeMapper, PurgeListener purgeListener) {
+ private void disableOrphanResources(String rootUuid, SqlSession session, PurgeMapper mapper, PurgeListener listener) {
List<String> componentUuids = new ArrayList<>();
- session.select("org.sonar.db.purge.PurgeMapper.selectComponentUuidsToDisable", project.getUuid(),
+ mapper.selectComponentUuidsToDisable(
+ rootUuid,
resultContext -> {
String componentUuid = (String) resultContext.getResultObject();
if (componentUuid != null) {
@@ -155,9 +150,9 @@ public class PurgeDao implements Dao {
}
});
+ disableComponents(componentUuids, mapper);
for (String componentUuid : componentUuids) {
- disableComponent(componentUuid, purgeMapper);
- purgeListener.onComponentDisabling(componentUuid);
+ listener.onComponentDisabling(componentUuid);
}
session.commit();
@@ -187,30 +182,22 @@ public class PurgeDao implements Dao {
commands.deleteCeActivity(rootUuid);
}
- private void disableComponent(String uuid, PurgeMapper mapper) {
- mapper.deleteResourceIndex(Collections.singletonList(uuid));
- mapper.setSnapshotIsLastToFalse(uuid);
- mapper.deleteFileSourcesByUuid(uuid);
- mapper.disableComponent(uuid);
- mapper.resolveComponentIssuesNotAlreadyResolved(uuid, system2.now());
- }
-
- public PurgeDao deleteSnapshots(DbSession session, PurgeProfiler profiler, PurgeSnapshotQuery... queries) {
- new PurgeCommands(session, profiler).deleteSnapshots(queries);
- return this;
+ private void disableComponents(List<String> uuids, PurgeMapper mapper) {
+ executeLargeInputs(uuids,
+ input -> {
+ mapper.deleteResourceIndex(input);
+ mapper.setSnapshotIsLastToFalse(input);
+ mapper.deleteFileSourcesByUuid(input);
+ mapper.disableComponent(input);
+ mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now());
+ return emptyList();
+ });
}
public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<IdUuidPair> analysisIdUuids) {
new PurgeCommands(session, profiler).deleteAnalyses(analysisIdUuids);
}
- /**
- * Load the whole tree of projects, including the project given in parameter.
- */
- private List<ResourceDto> getProjects(long rootId, SqlSession session) {
- return resourceDao.selectWholeTreeForRootId(session, rootId, Scopes.PROJECT);
- }
-
private static PurgeMapper mapper(DbSession session) {
return session.getMapper(PurgeMapper.class);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 82215fdfa21..c58961f872e 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -22,6 +22,7 @@ package org.sonar.db.purge;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
public interface PurgeMapper {
@@ -32,6 +33,8 @@ public interface PurgeMapper {
*/
List<IdUuidPair> selectComponentsByProjectUuid(String projectUuid);
+ void selectComponentUuidsToDisable(@Param("rootUuid") String rootUuid, ResultHandler resultHandler);
+
void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids);
void deleteDescendantSnapshots(@Param("snapshotIds") List<Long> snapshotIds);
@@ -58,13 +61,13 @@ public interface PurgeMapper {
void updateDescendantPurgeStatusToOne(@Param("analysisIds") List<Long> analysisIds);
- void disableComponent(String componentUuid);
+ void disableComponent(@Param("componentUuids") List<String> componentUuids);
- void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuid") String componentUuid, @Param("dateAsLong") Long dateAsLong);
+ void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List<String> componentUuids, @Param("dateAsLong") Long dateAsLong);
void deleteResourceIndex(@Param("componentUuids") List<String> componentUuids);
- void setSnapshotIsLastToFalse(@Param("componentUuid") String componentUuid);
+ void setSnapshotIsLastToFalse(@Param("componentUuids") List<String> componentUuids);
void deleteComponentLinks(@Param("componentUuids") List<String> componentUuids);
@@ -98,7 +101,7 @@ public interface PurgeMapper {
void deleteFileSourcesByProjectUuid(String rootProjectUuid);
- void deleteFileSourcesByUuid(String fileUuid);
+ void deleteFileSourcesByUuid(@Param("fileUuids") List<String> fileUuids);
void deleteCeActivityByProjectUuid(String projectUuid);
}