From: Julien Lancelot Date: Thu, 11 Sep 2014 11:51:17 +0000 (+0200) Subject: SONAR-5566 Fix issue when updating a lot of permissions X-Git-Tag: 5.0-RC1~1031 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6fac8a53f051d2b3e6720a0c93dcd1a8fca704a4;p=sonarqube.git SONAR-5566 Fix issue when updating a lot of permissions --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index 00489a93409..bceb86eb7b2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -23,12 +23,12 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.apache.ibatis.session.ResultContext; -import org.apache.ibatis.session.ResultHandler; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.Dto; import org.sonar.server.exceptions.NotFoundException; +import org.sonar.server.search.DbSynchronizationHandler; import org.sonar.server.search.IndexDefinition; import org.sonar.server.search.action.DeleteKey; import org.sonar.server.search.action.DeleteNestedItem; @@ -303,13 +303,18 @@ public abstract class BaseDao, KEY extends Serializ // Synchronization methods - protected ResultHandler getSynchronizationResultHandler(final DbSession session) { - return new ResultHandler() { + protected DbSynchronizationHandler getSynchronizationResultHandler(final DbSession session) { + return new DbSynchronizationHandler() { @Override public void handleResult(ResultContext resultContext) { DTO dto = (DTO) resultContext.getResultObject(); session.enqueue(new UpsertDto(getIndexType(), dto, true)); } + + @Override + public void enqueueCollected() { + // Do nothing in this case + } }; } @@ -322,7 +327,9 @@ public abstract class BaseDao, KEY extends Serializ @Override public void synchronizeAfter(final DbSession session, Date date) { try { - session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date), getSynchronizationResultHandler(session)); + DbSynchronizationHandler handler = getSynchronizationResultHandler(session); + session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date), handler); + handler.enqueueCollected(); } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueAuthorizationDao.java b/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueAuthorizationDao.java index 2a819600370..e3d3535163a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueAuthorizationDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueAuthorizationDao.java @@ -23,7 +23,6 @@ package org.sonar.server.issue.db; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import org.apache.ibatis.session.ResultContext; -import org.apache.ibatis.session.ResultHandler; import org.sonar.api.security.DefaultGroups; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; @@ -32,6 +31,7 @@ import org.sonar.core.issue.db.IssueAuthorizationMapper; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DbSession; import org.sonar.server.db.BaseDao; +import org.sonar.server.search.DbSynchronizationHandler; import org.sonar.server.search.IndexDefinition; import org.sonar.server.search.action.UpsertDto; @@ -59,10 +59,9 @@ public class IssueAuthorizationDao extends BaseDao authorizationDtoMap = new HashMap(); - private int count = 0; @Override public void handleResult(ResultContext context) { @@ -85,14 +84,12 @@ public class IssueAuthorizationDao extends BaseDao(getIndexType(), authorization, true)); - } + } + + @Override + public void enqueueCollected() { + for (IssueAuthorizationDto authorization : authorizationDtoMap.values()) { + session.enqueue(new UpsertDto(getIndexType(), authorization, true)); } } }; diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java index f51f45b523f..ef7cbd7566d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java @@ -275,7 +275,7 @@ public class InternalPermissionService implements ServerComponent { } private void synchronizePermissions() { - // The index synchronizer cannot use an existing session, otherwise it's failing with the error : org.apache.ibatis.executor.ExecutorException: Executor was closed + // The synchronisation cannot use an existing session, otherwise it's failing with the error : org.apache.ibatis.executor.ExecutorException: Executor was closed DbSession session = dbClient.openSession(false); try { dbClient.issueAuthorizationDao().synchronizeAfter(session, index.get(IssueAuthorizationIndex.class).getLastSynchronization()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java b/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java new file mode 100644 index 00000000000..8e56aa61f5f --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/search/DbSynchronizationHandler.java @@ -0,0 +1,35 @@ +/* + * 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.server.search; + +import org.apache.ibatis.session.ResultContext; +import org.apache.ibatis.session.ResultHandler; + +import javax.annotation.CheckForNull; + +public interface DbSynchronizationHandler extends ResultHandler { + + @Override + void handleResult(ResultContext context); + + @CheckForNull + void enqueueCollected(); +}