From: Julien HENRY Date: Tue, 29 Apr 2014 08:45:35 +0000 (+0200) Subject: SONAR-5249 Merge measure_data and project_measure tables X-Git-Tag: 4.4-RC1~1359 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5d63d85a14b4a5a6934bc178f95bcd2a894c7f63;p=sonarqube.git SONAR-5249 Merge measure_data and project_measure tables --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 9624513e288..d5e42948fc5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -176,10 +176,7 @@ public class DefaultIndex extends SonarIndex { public Measure getMeasure(Resource resource, Metric metric) { Bucket bucket = buckets.get(resource); if (bucket != null) { - Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric)); - if (measure != null) { - return persistence.reloadMeasure(measure); - } + return bucket.getMeasures(MeasuresFilters.metric(metric)); } return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java index 14da97381cf..9dd3460e0ff 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java @@ -40,8 +40,8 @@ public final class DefaultPersistenceManager implements PersistenceManager { private EventPersister eventPersister; public DefaultPersistenceManager(ResourcePersister resourcePersister, SourcePersister sourcePersister, - MeasurePersister measurePersister, DependencyPersister dependencyPersister, - LinkPersister linkPersister, EventPersister eventPersister) { + MeasurePersister measurePersister, DependencyPersister dependencyPersister, + LinkPersister linkPersister, EventPersister eventPersister) { this.resourcePersister = resourcePersister; this.sourcePersister = sourcePersister; this.measurePersister = measurePersister; @@ -88,10 +88,6 @@ public final class DefaultPersistenceManager implements PersistenceManager { } } - public Measure reloadMeasure(Measure measure) { - return measurePersister.reloadMeasure(measure); - } - public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) { if (ResourceUtils.isPersistable(dependency.getFrom()) && ResourceUtils.isPersistable(dependency.getTo())) { dependencyPersister.saveDependency(project, dependency, parentDependency); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index 8e61a931bd0..2e1c8995bac 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -47,25 +47,19 @@ public final class MeasurePersister { private final MyBatis mybatis; private final ResourcePersister resourcePersister; private final RuleFinder ruleFinder; - private final MemoryOptimizer memoryOptimizer; private final SetMultimap unsavedMeasuresByResource = LinkedHashMultimap.create(); private boolean delayedMode = false; - public MeasurePersister(MyBatis mybatis, ResourcePersister resourcePersister, RuleFinder ruleFinder, MemoryOptimizer memoryOptimizer) { + public MeasurePersister(MyBatis mybatis, ResourcePersister resourcePersister, RuleFinder ruleFinder) { this.mybatis = mybatis; this.resourcePersister = resourcePersister; this.ruleFinder = ruleFinder; - this.memoryOptimizer = memoryOptimizer; } public void setDelayedMode(boolean delayedMode) { this.delayedMode = delayedMode; } - public Measure reloadMeasure(Measure measure) { - return memoryOptimizer.reloadMeasure(measure); - } - public void dump() { LoggerFactory.getLogger(getClass()).debug("{} measures to dump", unsavedMeasuresByResource.size()); @@ -81,16 +75,12 @@ public final class MeasurePersister { unsavedMeasuresByResource.put(resource, measure); return; } - MeasureModel model; try { - model = insertOrUpdate(resource, measure); + insertOrUpdate(resource, measure); } catch (Exception e) { // SONAR-4066 throw new SonarException(String.format("Unable to save measure for metric [%s] on component [%s]", measure.getMetricKey(), resource.getKey()), e); } - if (model != null) { - memoryOptimizer.evictDataMeasure(measure, model); - } } private MeasureModel insertOrUpdate(Resource resource, Measure measure) { @@ -192,9 +182,6 @@ public final class MeasurePersister { for (MeasureModelAndDetails value : values) { try { mapper.insert(value.getMeasureModel()); - if (value.getMeasureModel().getMeasureData() != null) { - mapper.insertData(value.getMeasureModel().getMeasureData()); - } } catch (Exception e) { // SONAR-4066 throw new SonarException(String.format("Unable to save measure for metric [%s] on component [%s]", value.getMetricKey(), value.getResourceKey()), e); @@ -216,9 +203,6 @@ public final class MeasurePersister { MeasureMapper mapper = session.getMapper(MeasureMapper.class); mapper.insert(value); - if (value.getMeasureData() != null) { - mapper.insertData(value.getMeasureData()); - } session.commit(); } finally { @@ -238,10 +222,6 @@ public final class MeasurePersister { MeasureMapper mapper = session.getMapper(MeasureMapper.class); mapper.update(value); - mapper.deleteData(value); - if (value.getMeasureData() != null) { - mapper.insertData(value.getMeasureData()); - } session.commit(); } finally { diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java deleted file mode 100644 index 9daa941b823..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.events.DecoratorExecutionHandler; -import org.sonar.api.batch.events.DecoratorsPhaseHandler; -import org.sonar.api.batch.events.SensorExecutionHandler; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.database.model.MeasureData; -import org.sonar.api.database.model.MeasureModel; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.PersistenceMode; - -import java.util.List; -import java.util.Map; - -/** - * @since 2.7 - */ -public class MemoryOptimizer implements SensorExecutionHandler, DecoratorExecutionHandler, DecoratorsPhaseHandler { - - private static final Logger LOG = LoggerFactory.getLogger(MemoryOptimizer.class); - - private List loadedMeasures = Lists.newArrayList(); - private Map dataIdByMeasureId = Maps.newHashMap(); - private DatabaseSession session; - - public MemoryOptimizer(DatabaseSession session) { - this.session = session; - } - - /** - * Remove data of a database measure from memory. - */ - public void evictDataMeasure(Measure measure, MeasureModel model) { - if (PersistenceMode.DATABASE.equals(measure.getPersistenceMode())) { - MeasureData data = model.getMeasureData(); - if (data != null && data.getId() != null) { - measure.unsetData(); - dataIdByMeasureId.put(measure.getId(), data.getId()); - } - } - } - - public Measure reloadMeasure(Measure measure) { - if (measure.getId() != null && dataIdByMeasureId.containsKey(measure.getId()) && !measure.hasData()) { - Integer dataId = dataIdByMeasureId.get(measure.getId()); - MeasureData data = session.getSingleResult(MeasureData.class, "id", dataId); - if (data == null) { - LOG.error("The MEASURE_DATA row with id {} is lost", dataId); - - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Reload the data measure: {}, id={}", measure.getMetricKey(), measure.getId()); - } - measure.setData(data.getText()); - loadedMeasures.add(measure); - } - } - return measure; - } - - public void flushMemory() { - if (LOG.isDebugEnabled() && !loadedMeasures.isEmpty()) { - LOG.debug("Flush {} data measures from memory: ", loadedMeasures.size()); - } - for (Measure measure : loadedMeasures) { - measure.unsetData(); - } - loadedMeasures.clear(); - } - - boolean isTracked(Long measureId) { - return dataIdByMeasureId.get(measureId) != null; - } - - public void onSensorExecution(SensorExecutionEvent event) { - if (event.isEnd()) { - flushMemory(); - session.commit(); - } - } - - public void onDecoratorExecution(DecoratorExecutionEvent event) { - if (event.isEnd()) { - flushMemory(); - } - } - - public void onDecoratorsPhase(DecoratorsPhaseEvent event) { - if (event.isEnd()) { - session.commit(); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java index d42e1a9f2e1..dec88e49d15 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java @@ -46,8 +46,6 @@ public interface PersistenceManager { void saveMeasure(Resource resource, Measure measure); - Measure reloadMeasure(Measure measure); - void saveDependency(Project project, Dependency dependency, Dependency parentDependency); void saveLink(Project project, ProjectLink link); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index e4eacf6aa8d..59e68e6078c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -21,7 +21,6 @@ package org.sonar.batch.scan; import com.google.common.annotations.VisibleForTesting; import org.sonar.api.BatchComponent; -import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.bootstrap.ProjectBootstrapper; @@ -36,12 +35,33 @@ import org.sonar.batch.DefaultFileLinesContextFactory; import org.sonar.batch.DefaultResourceCreationLock; import org.sonar.batch.ProjectConfigurator; import org.sonar.batch.ProjectTree; -import org.sonar.batch.bootstrap.*; +import org.sonar.batch.bootstrap.BootstrapSettings; +import org.sonar.batch.bootstrap.ExtensionInstaller; +import org.sonar.batch.bootstrap.ExtensionMatcher; +import org.sonar.batch.bootstrap.ExtensionUtils; +import org.sonar.batch.bootstrap.MetricProvider; import org.sonar.batch.components.PeriodsDefinition; import org.sonar.batch.debt.DebtModelProvider; import org.sonar.batch.debt.IssueChangelogDebtCalculator; -import org.sonar.batch.index.*; -import org.sonar.batch.issue.*; +import org.sonar.batch.index.Caches; +import org.sonar.batch.index.ComponentDataCache; +import org.sonar.batch.index.ComponentDataPersister; +import org.sonar.batch.index.DefaultIndex; +import org.sonar.batch.index.DefaultPersistenceManager; +import org.sonar.batch.index.DefaultResourcePersister; +import org.sonar.batch.index.DependencyPersister; +import org.sonar.batch.index.EventPersister; +import org.sonar.batch.index.LinkPersister; +import org.sonar.batch.index.MeasurePersister; +import org.sonar.batch.index.ResourceCache; +import org.sonar.batch.index.ResourceKeyMigration; +import org.sonar.batch.index.SnapshotCache; +import org.sonar.batch.index.SourcePersister; +import org.sonar.batch.issue.DefaultProjectIssues; +import org.sonar.batch.issue.DeprecatedViolations; +import org.sonar.batch.issue.IssueCache; +import org.sonar.batch.issue.IssuePersister; +import org.sonar.batch.issue.ScanIssueStorage; import org.sonar.batch.phases.GraphPersister; import org.sonar.batch.profiling.PhasesSumUpTimeProfiler; import org.sonar.batch.rule.RulesProvider; @@ -112,7 +132,6 @@ public class ProjectScanContainer extends ComponentContainer { EventPersister.class, LinkPersister.class, MeasurePersister.class, - MemoryOptimizer.class, DefaultResourcePersister.class, SourcePersister.class, DefaultNotificationManager.class, diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index fc3a69628d2..0b3363527da 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -23,8 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.junit.Before; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.ArgumentCaptor; -import org.sonar.api.database.model.MeasureModel; import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; @@ -41,10 +39,7 @@ import org.sonar.api.utils.SonarException; import org.sonar.core.persistence.AbstractDaoTestCase; import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class MeasurePersisterTest extends AbstractDaoTestCase { @@ -64,7 +59,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { MeasurePersister measurePersister; RuleFinder ruleFinder = mock(RuleFinder.class); ResourcePersister resourcePersister = mock(ResourcePersister.class); - MemoryOptimizer memoryOptimizer = mock(MemoryOptimizer.class); Project project = new Project("foo"); Directory aDirectory = new Directory("org/foo"); File aFile = new File("org/foo/Bar.java"); @@ -78,7 +72,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { when(resourcePersister.getSnapshot(project)).thenReturn(projectSnapshot); when(resourcePersister.getSnapshot(aDirectory)).thenReturn(packageSnapshot); - measurePersister = new MeasurePersister(getMyBatis(), resourcePersister, ruleFinder, memoryOptimizer); + measurePersister = new MeasurePersister(getMyBatis(), resourcePersister, ruleFinder); } @Test @@ -89,7 +83,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(project, measure); checkTables("shouldInsertMeasure", "project_measures"); - verify(memoryOptimizer).evictDataMeasure(eq(measure), any(MeasureModel.class)); assertThat(measure.getId()).isNotNull(); } @@ -105,15 +98,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(project, measure); } - @Test - public void should_reload_measure() { - Measure measure = new Measure(ncloc()); - - measurePersister.reloadMeasure(measure); - - verify(memoryOptimizer).reloadMeasure(measure); - } - @Test public void should_insert_rule_measure() { setupData("empty"); @@ -135,11 +119,8 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { Measure withLargeData = new Measure(ncloc()).setData(LONG); measurePersister.saveMeasure(project, withLargeData); - checkTables("shouldInsertMeasureWithLargeData", "project_measures", "measure_data"); + checkTables("shouldInsertMeasureWithLargeData", "project_measures"); - ArgumentCaptor validMeasureModel = ArgumentCaptor.forClass(MeasureModel.class); - verify(memoryOptimizer).evictDataMeasure(eq(withLargeData), validMeasureModel.capture()); - assertThat(validMeasureModel.getValue().getMeasureData().getId()).isNotNull(); assertThat(withLargeData.getId()).isNotNull(); } @@ -149,7 +130,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0)); - assertEmptyTables("project_measures", "measure_data"); + assertEmptyTables("project_measures"); } @Test @@ -158,7 +139,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(aFile, new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY)); - assertEmptyTables("project_measures", "measure_data"); + assertEmptyTables("project_measures"); } @Test @@ -179,7 +160,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(project, new Measure(coverage()).setData(SHORT).setId(2L)); measurePersister.saveMeasure(aDirectory, new Measure(coverage()).setData(LONG).setId(3L)); - checkTables("shouldUpdateMeasure", "project_measures", "measure_data"); + checkTables("shouldUpdateMeasure", "project_measures"); } @Test @@ -207,7 +188,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { assertEmptyTables("project_measures"); measurePersister.dump(); - checkTables("shouldDelaySaving", "project_measures", "measure_data"); + checkTables("shouldDelaySaving", "project_measures"); } @Test @@ -242,11 +223,11 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.setDelayedMode(true); measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0)); - assertEmptyTables("project_measures", "measure_data"); + assertEmptyTables("project_measures"); measurePersister.dump(); - assertEmptyTables("project_measures", "measure_data"); + assertEmptyTables("project_measures"); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java deleted file mode 100644 index 468654da72c..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MemoryOptimizerTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import org.junit.Test; -import org.sonar.api.database.model.MeasureData; -import org.sonar.api.database.model.MeasureModel; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.PersistenceMode; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; - -public class MemoryOptimizerTest extends AbstractDbUnitTestCase { - - @Test - public void shouldEvictDatabaseOnlyMeasure() { - MemoryOptimizer optimizer = new MemoryOptimizer(getSession()); - Measure measure = new Measure(CoreMetrics.CONDITIONS_BY_LINE) - .setData("10=23") - .setPersistenceMode(PersistenceMode.DATABASE) - .setId(12345L); - MeasureModel model = newPersistedModel(); - - optimizer.evictDataMeasure(measure, model); - - assertThat(optimizer.isTracked(12345L),is(true)); - assertThat(measure.getData(), nullValue());// data has been removed from memory - } - - @Test - public void shouldNotEvictStandardMeasure() { - MemoryOptimizer optimizer = new MemoryOptimizer(getSession()); - Measure measure = new Measure(CoreMetrics.PROFILE) - .setData("Sonar way") - .setId(12345L); - MeasureModel model = newPersistedModel(); - - optimizer.evictDataMeasure(measure, model); - - assertThat(optimizer.isTracked(12345L),is(false)); - assertThat(measure.getData(), is("Sonar way")); - } - - @Test - public void shouldReloadEvictedMeasure() { - setupData("shouldReloadEvictedMeasure"); - MemoryOptimizer optimizer = new MemoryOptimizer(getSession()); - Measure measure = new Measure(CoreMetrics.CONDITIONS_BY_LINE) - .setData("initial") - .setPersistenceMode(PersistenceMode.DATABASE) - .setId(12345L); - - optimizer.evictDataMeasure(measure, newPersistedModel()); - assertThat(measure.getData(), nullValue()); - - optimizer.reloadMeasure(measure); - - assertThat(measure.getData().length(), greaterThan(5)); - - optimizer.flushMemory(); - assertThat(measure.getData(), nullValue()); - } - - private MeasureModel newPersistedModel() { - MeasureModel model = new MeasureModel(); - model.setId(12345L); - MeasureData measureData = new MeasureData(); - measureData.setId(500); - model.setMeasureData(measureData); - return model; - } -} diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml index a9d69262af3..416ec0a604b 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAddDelayedMeasureSeveralTimes-result.xml @@ -4,6 +4,7 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml index cc956fb7770..cd064d6d9f1 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldAlwaysPersistNonFileMeasures-result.xml @@ -4,11 +4,13 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml index 97b4eb2090a..28f2942aec1 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml @@ -5,14 +5,14 @@ RULE_ID="[null]" text_value="SHORT" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> - - + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml index f7475f591e8..a19db3a8c05 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml @@ -4,6 +4,7 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml index 77b6b6049a8..7aec2e88e4e 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml @@ -5,8 +5,7 @@ tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> - - + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml index 5472c06aaea..89acf2b2223 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertRuleMeasure-result.xml @@ -4,6 +4,7 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="2" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml index 22201f588e4..07f08fb086c 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml @@ -4,20 +4,21 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" - variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="[null]"/> - - + variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]" + measure_data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml deleted file mode 100644 index 5f40b829f73..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MemoryOptimizerTest/shouldReloadEvictedMeasure.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java index 474aee60f7a..c2003a9796e 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDataDto.java @@ -28,8 +28,6 @@ public class MeasureDataDto { private Integer id; - private Long measureId; - private Integer snapshotId; private byte[] data; @@ -43,15 +41,6 @@ public class MeasureDataDto { return this; } - public Long getMeasureId() { - return measureId; - } - - public MeasureDataDto setMeasureId(Long measureId) { - this.measureId = measureId; - return this; - } - public Integer getSnapshotId() { return snapshotId; } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index d815836f613..41ca1b31a1e 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 526; + public static final int LAST_VERSION = 530; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL @@ -67,7 +67,6 @@ public class DatabaseVersion implements BatchComponent, ServerComponent { "issue_filter_favourites", "loaded_templates", "manual_measures", - "measure_data", "measure_filters", "measure_filter_favourites", "metrics", diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 765f8e2a7bf..3a4e0ac18e6 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -173,13 +173,6 @@ class PurgeCommands { session.commit(); profiler.stop(); - profiler.start("deleteSnapshotMeasureData (measure_data)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshotMeasureData(partSnapshotIds); - } - session.commit(); - profiler.stop(); - profiler.start("deleteSnapshotMeasures (project_measures)"); for (List partSnapshotIds : snapshotIdsPartition) { purgeMapper.deleteSnapshotMeasures(partSnapshotIds); @@ -276,7 +269,8 @@ class PurgeCommands { profiler.start("deleteSnapshotDependencies (dependencies)"); for (List partSnapshotIds : snapshotIdsPartition) { // SONAR-4586 - // On MsSQL, the maximum number of parameters allowed in a query is 2000, so we have to execute 3 queries instead of one with 3 or inside + // On MsSQL, the maximum number of parameters allowed in a query is 2000, so we have to execute 3 queries instead of one with 3 or + // inside purgeMapper.deleteSnapshotDependenciesFromSnapshotId(partSnapshotIds); purgeMapper.deleteSnapshotDependenciesToSnapshotId(partSnapshotIds); purgeMapper.deleteSnapshotDependenciesProjectSnapshotId(partSnapshotIds); diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index ff7d36d2d04..684c8d6500e 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -48,8 +48,6 @@ public interface PurgeMapper { void deleteSnapshotMeasures(@Param("snapshotIds") List snapshotIds); - void deleteSnapshotMeasureData(@Param("snapshotIds") List snapshotIds); - void deleteSnapshotSource(@Param("snapshotIds") List snapshotIds); void deleteSnapshotGraphs(@Param("snapshotIds") List snapshotIds); diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml index 034e3dffd10..4caafcf45ed 100644 --- a/sonar-core/src/main/resources/META-INF/persistence.xml +++ b/sonar-core/src/main/resources/META-INF/persistence.xml @@ -12,7 +12,6 @@ org.sonar.api.database.model.User org.sonar.api.database.model.Snapshot org.sonar.api.database.model.MeasureModel - org.sonar.api.database.model.MeasureData org.sonar.api.design.DependencyDto org.sonar.api.measures.Metric org.sonar.api.database.model.ResourceModel diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml index 2ee23a30df0..b908ad21cd1 100644 --- a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureDataMapper.xml @@ -4,17 +4,15 @@ - m.id, - m.measure_id as measureId, - m.snapshot_id as snapshotId, - m.data as data + pm.id, + pm.snapshot_id as snapshotId, + pm.measure_data as data