From 3b0bc018071a7ffb61e929927594871341261314 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 4 May 2017 16:30:03 +0200 Subject: [PATCH] SONAR-6315 index changes per quality profile to avoid OOM 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/qualityprofile/MassRegisterQualityProfiles.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java index 6cdd4a91a3b..7d933634e1f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/MassRegisterQualityProfiles.java @@ -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 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 getOrganizationsWithoutQP(DbSession session, DefinedQProfile qualityProfile) { -- 2.39.5