aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-03-19 13:53:23 -0500
committersonartech <sonartech@sonarsource.com>2020-03-30 20:03:43 +0000
commit74384e67058fcfea16c80839740d28d9083b944a (patch)
treece9362fa2ec32af022638eb1895bd74f891b314b /server/sonar-db-dao/src
parent7294268682b6d1add416c7de5d41422367fec324 (diff)
downloadsonarqube-74384e67058fcfea16c80839740d28d9083b944a.tar.gz
sonarqube-74384e67058fcfea16c80839740d28d9083b944a.zip
SONAR-12691 Don't persist project measures that are not historical
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureQuery.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java38
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java38
9 files changed, 1 insertions, 129 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java
index e3f36923d01..c27e4d0d835 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java
@@ -74,15 +74,6 @@ public class MeasureDao implements Dao {
return mapper(dbSession).selectByQueryOnSingleComponent(query);
}
- public List<PastMeasureDto> selectPastMeasures(DbSession dbSession, String componentUuid, String analysisUuid, Collection<Integer> metricIds) {
- if (metricIds.isEmpty()) {
- return emptyList();
- }
- return executeLargeInputs(
- metricIds,
- ids -> mapper(dbSession).selectPastMeasuresOnSingleAnalysis(componentUuid, analysisUuid, ids));
- }
-
/**
* Select measures of:
* - one component
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java
index d98be0bbf21..5892ec457b0 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java
@@ -44,9 +44,6 @@ public interface MeasureMapper {
List<MeasureDto> selectByQueryOnSingleComponent(@Param("query") MeasureQuery query);
- List<PastMeasureDto> selectPastMeasuresOnSingleAnalysis(@Param("componentUuid") String componentUuid, @Param("analysisUuid") String analysisUuid,
- @Param("metricIds") List<Integer> metricIds);
-
List<MeasureDto> selectPastMeasuresOnSeveralAnalyses(@Param("query") PastMeasureQuery query);
void insert(MeasureDto measureDto);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureQuery.java
index 5ef8e2f9eaa..7113fca91ac 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureQuery.java
@@ -65,6 +65,7 @@ public class MeasureQuery {
this.metricKeys = metricKeys;
}
+ @CheckForNull
public String getAnalysisUuid() {
return analysisUuid;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index b27aa2fcf14..ac0cabedd62 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -134,15 +134,6 @@ class PurgeCommands {
deleteAnalysisDuplications(analysisUuidsPartitions);
- profiler.start("deleteSnapshotWastedMeasures (project_measures)");
- List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
- if (!metricIdsWithoutHistoricalData.isEmpty()) {
- analysisUuidsPartitions
- .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
- session.commit();
- }
- profiler.stop();
-
profiler.start("updatePurgeStatusToOne (snapshots)");
analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
session.commit();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 07052cbed3b..5000b6fcbec 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -54,10 +54,6 @@ public interface PurgeMapper {
void fullDeleteComponentMeasures(@Param("componentUuids") List<String> componentUuids);
- List<Long> selectMetricIdsWithoutHistoricalData();
-
- void deleteAnalysisWastedMeasures(@Param("analysisUuids") List<String> analysisUuids, @Param("metricIds") List<Long> metricIds);
-
/**
* Purge status flag is used to not attempt to remove duplications & historical data of analyses
* for which we already removed them.
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
index 64c92258fdc..dafc59b1939 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
@@ -97,16 +97,6 @@
</if>
</sql>
- <select id="selectPastMeasuresOnSingleAnalysis" parameterType="map" resultType="org.sonar.db.measure.PastMeasureDto">
- select pm.id as id, pm.metric_id as metricId, pm.value as value
- from project_measures pm
- inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
- where
- pm.component_uuid = #{componentUuid,jdbcType=VARCHAR}
- and analysis.uuid = #{analysisUuid,jdbcType=VARCHAR}
- and pm.metric_id in <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">#{metricId}</foreach>
- </select>
-
<select id="selectPastMeasuresOnSeveralAnalyses" parameterType="map" resultType="Measure">
select <include refid="measureColumns"/>
from project_measures pm
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index b2c7e568444..ede9138c4ad 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -58,10 +58,6 @@
and pb.updated_at &lt; #{toDate}
</select>
- <select id="selectMetricIdsWithoutHistoricalData" resultType="long">
- select id from metrics where delete_historical_data=${_true}
- </select>
-
<select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="IdUuidPair" parameterType="String">
select
p.id, p.uuid
@@ -173,20 +169,6 @@
</foreach>
</delete>
- <delete id="deleteAnalysisWastedMeasures" parameterType="map">
- delete from project_measures
- <where>
- analysis_uuid in
- <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=",">
- #{analysisUuid}
- </foreach>
- and metric_id in
- <foreach collection="metricIds" open="(" item="metricId" separator="," close=")">
- #{metricId,jdbcType=INTEGER}
- </foreach>
- </where>
- </delete>
-
<update id="updatePurgeStatusToOne" parameterType="map">
update
snapshots
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 25b723c7088..864ba5d85fe 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -116,44 +116,6 @@ public class PurgeCommandsTest {
assertThat(countDuplications(analysis4)).isZero();
}
- @Test
- public void purgeAnalyses_deletes_measures_of_metrics_without_historical_data() {
- MetricDto noHistoryMetric = dbTester.measures().insertMetric(t -> t.setDeleteHistoricalData(true));
- MetricDto withHistoryMetric = dbTester.measures().insertMetric(t -> t.setDeleteHistoricalData(false));
- ComponentDto project = dbTester.components().insertPrivateProject();
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project);
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project);
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project);
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project);
- int count = 1 + random.nextInt(12);
- for (SnapshotDto analysis : Arrays.asList(analysis1, analysis2, analysis3, analysis4)) {
- IntStream.range(0, count).forEach(i -> {
- dbTester.measures().insertMeasure(project, analysis, noHistoryMetric);
- dbTester.measures().insertMeasure(project, analysis, withHistoryMetric);
- });
- }
-
- underTest.purgeAnalyses(toIdUuidPairs(analysis1));
- assertThat(countMeasures(analysis1, noHistoryMetric)).isZero();
- assertThat(countMeasures(analysis1, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis2, noHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis2, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis3, noHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis3, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis4, noHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis4, withHistoryMetric)).isEqualTo(count);
-
- underTest.purgeAnalyses(toIdUuidPairs(analysis1, analysis3, analysis4));
- assertThat(countMeasures(analysis1, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis2, noHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis2, noHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis2, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis3, noHistoryMetric)).isZero();
- assertThat(countMeasures(analysis3, withHistoryMetric)).isEqualTo(count);
- assertThat(countMeasures(analysis4, noHistoryMetric)).isZero();
- assertThat(countMeasures(analysis4, withHistoryMetric)).isEqualTo(count);
- }
-
/**
* Test that SQL queries execution do not fail with a huge number of parameter
*/
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index e30e5008d05..c9f3a189682 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -88,7 +88,6 @@ import static java.util.Collections.emptySet;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -214,43 +213,6 @@ public class PurgeDaoTest {
}
@Test
- public void shouldDeleteNonHistoricalData() {
- MetricDto metricWithHistory = db.measures().insertMetric(t -> t.setDeleteHistoricalData(false));
- MetricDto metricWithoutHistory = db.measures().insertMetric(t -> t.setDeleteHistoricalData(true));
- ComponentDto project = db.components().insertPrivateProject();
- SnapshotDto lastAnalysis = db.components().insertSnapshot(project, t -> t.setLast(true));
- SnapshotDto oldAnalysis = db.components().insertSnapshot(project, t -> t.setLast(false));
- db.measures().insertMeasure(project, lastAnalysis, metricWithHistory);
- db.measures().insertMeasure(project, lastAnalysis, metricWithoutHistory);
- db.measures().insertMeasure(project, oldAnalysis, metricWithHistory);
- db.measures().insertMeasure(project, oldAnalysis, metricWithoutHistory);
- ComponentDto otherProject = db.components().insertPrivateProject();
- SnapshotDto otherLastAnalysis = db.components().insertSnapshot(otherProject, t -> t.setLast(true));
- SnapshotDto otherOldAnalysis = db.components().insertSnapshot(otherProject, t -> t.setLast(false));
- db.measures().insertMeasure(otherProject, otherLastAnalysis, metricWithHistory);
- db.measures().insertMeasure(otherProject, otherLastAnalysis, metricWithoutHistory);
- db.measures().insertMeasure(otherProject, otherOldAnalysis, metricWithHistory);
- db.measures().insertMeasure(otherProject, otherOldAnalysis, metricWithoutHistory);
-
- PurgeConfiguration conf = new PurgeConfiguration(project.uuid(), project.uuid(), 30, Optional.of(30), System2.INSTANCE, emptySet());
-
- underTest.purge(dbSession, conf, PurgeListener.EMPTY, new PurgeProfiler());
- dbSession.commit();
-
- assertThat(db.select("select metric_id as \"METRIC\",analysis_uuid as \"ANALYSIS\" from project_measures"))
- .extracting(t -> ((Long) t.get("METRIC")).intValue(), t -> t.get("ANALYSIS"))
- .containsOnly(
- tuple(metricWithHistory.getId(), lastAnalysis.getUuid()),
- tuple(metricWithoutHistory.getId(), lastAnalysis.getUuid()),
- tuple(metricWithHistory.getId(), oldAnalysis.getUuid()),
-
- tuple(metricWithHistory.getId(), otherLastAnalysis.getUuid()),
- tuple(metricWithoutHistory.getId(), otherLastAnalysis.getUuid()),
- tuple(metricWithHistory.getId(), otherOldAnalysis.getUuid()),
- tuple(metricWithoutHistory.getId(), otherOldAnalysis.getUuid()));
- }
-
- @Test
public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();