]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6315 index changes per quality profile to avoid OOM
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 4 May 2017 14:30:03 +0000 (16:30 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 12 May 2017 09:18:19 +0000 (11:18 +0200)
because indexing only at the end of MassRegisterQualityProfiles means holding every changes for every QP for every organization in memory and this can be a lot

server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java

index 6cdd4a91a3b0b9ff524ff905fbc8c83f854c7a95..7d933634e1f33154132d9ebafa4918808327a581 100644 (file)
@@ -77,10 +77,10 @@ public class MassRegisterQualityProfiles {
 
     try (DbSession session = dbClient.openSession(false);
       DbSession batchSession = dbClient.openSession(true)) {
+      // memory optimization: use a single array list for everything to avoid reallocating and increasing new array for each quality profiles
       List<ActiveRuleChange> changes = new ArrayList<>();
       definedQProfileRepository.getQProfilesByLanguage()
         .forEach((key, value) -> registerPerLanguage(session, batchSession, value, changes));
-      activeRuleIndexer.index(changes);
       profiler.stopDebug();
     }
   }
@@ -97,6 +97,10 @@ public class MassRegisterQualityProfiles {
     while (!(organizationDtos = getOrganizationsWithoutQP(session, qualityProfile)).isEmpty()) {
       organizationDtos.forEach(organization -> registerPerQualityProfileAndOrganization(session, batchSession, qualityProfile, organization, changes, profiler));
     }
+    profiler.startDebug("Indexing for profile " + qualityProfile.getQProfileName());
+    activeRuleIndexer.index(changes);
+    changes.clear();
+    profiler.stopDebug();
   }
 
   private List<OrganizationDto> getOrganizationsWithoutQP(DbSession session, DefinedQProfile qualityProfile) {