You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2015/06/08 15:31:52 UTC
ambari git commit: AMBARI-11784. Perf Cluster: Save configurations of
Config Group takes 40s. (mpapirkovskyy)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 5fb13c9ad -> 64bc2473b
AMBARI-11784. Perf Cluster: Save configurations of Config Group takes 40s. (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/64bc2473
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/64bc2473
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/64bc2473
Branch: refs/heads/branch-2.1
Commit: 64bc2473bf38a1e4e0a3dfd1b97ec1f91d5e285d
Parents: 5fb13c9
Author: Myroslav Papirkovskyy <mp...@hortonworks.com>
Authored: Tue Jun 2 23:23:00 2015 +0300
Committer: Myroslav Papirkovskyy <mp...@hortonworks.com>
Committed: Wed Jun 3 00:17:26 2015 +0300
----------------------------------------------------------------------
.../internal/ConfigGroupResourceProvider.java | 4 +-
.../orm/dao/ConfigGroupHostMappingDAO.java | 53 ++++++++++++--------
.../state/configgroup/ConfigGroupImpl.java | 10 ++--
.../ConfigGroupResourceProviderTest.java | 12 +++--
4 files changed, 47 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/64bc2473/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
index 2bbb9e7..30bcc86 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
@@ -582,8 +582,8 @@ public class ConfigGroupResourceProvider extends
if (request.getHosts() != null && !request.getHosts().isEmpty()) {
for (String hostname : request.getHosts()) {
Host host = clusters.getHost(hostname);
- HostEntity hostEntity = hostDAO.findByName(hostname);
- if (host == null || hostEntity == null) {
+ HostEntity hostEntity = hostDAO.findById(host.getHostId());
+ if (hostEntity == null) {
throw new HostNotFoundException(hostname);
}
hosts.put(hostEntity.getHostId(), host);
http://git-wip-us.apache.org/repos/asf/ambari/blob/64bc2473/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
index 4628a4c..71d93cc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
@@ -22,6 +22,7 @@ import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.RequiresSession;
import org.apache.ambari.server.orm.cache.ConfigGroupHostMapping;
import org.apache.ambari.server.orm.cache.ConfigGroupHostMappingImpl;
@@ -30,6 +31,7 @@ import org.apache.ambari.server.orm.entities.ConfigGroupHostMappingEntity;
import org.apache.ambari.server.orm.entities.ConfigGroupHostMappingEntityPK;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.cluster.ClusterFactory;
import org.apache.ambari.server.state.configgroup.ConfigGroup;
@@ -45,7 +47,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.WeakHashMap;
+import java.util.HashMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -61,6 +63,8 @@ public class ConfigGroupHostMappingDAO {
private ClusterFactory clusterFactory;
@Inject
private HostFactory hostFactory;
+ @Inject
+ Clusters clusters;
private final ReadWriteLock gl = new ReentrantReadWriteLock();
@@ -74,33 +78,35 @@ public class ConfigGroupHostMappingDAO {
if (!cacheLoaded) {
gl.writeLock().lock();
try {
- if (configGroupHostMappingByHost == null) {
- configGroupHostMappingByHost = new WeakHashMap<Long, Set<ConfigGroupHostMapping>>();
-
- TypedQuery<ConfigGroupHostMappingEntity> query = entityManagerProvider.get().createQuery(
- "SELECT entity FROM ConfigGroupHostMappingEntity entity",
- ConfigGroupHostMappingEntity.class);
+ if (!cacheLoaded) {
+ if (configGroupHostMappingByHost == null) {
+ configGroupHostMappingByHost = new HashMap<Long, Set<ConfigGroupHostMapping>>();
+
+ TypedQuery<ConfigGroupHostMappingEntity> query = entityManagerProvider.get().createQuery(
+ "SELECT entity FROM ConfigGroupHostMappingEntity entity",
+ ConfigGroupHostMappingEntity.class);
+
+ List<ConfigGroupHostMappingEntity> configGroupHostMappingEntities = daoUtils.selectList(query);
- List<ConfigGroupHostMappingEntity> configGroupHostMappingEntities = daoUtils.selectList(query);
-
- for (ConfigGroupHostMappingEntity configGroupHostMappingEntity : configGroupHostMappingEntities) {
+ for (ConfigGroupHostMappingEntity configGroupHostMappingEntity : configGroupHostMappingEntities) {
- Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get((configGroupHostMappingEntity.getHostId()));
-
- if (setByHost == null) {
- setByHost = new HashSet<ConfigGroupHostMapping>();
- configGroupHostMappingByHost.put(configGroupHostMappingEntity.getHostId(), setByHost);
+ Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get((configGroupHostMappingEntity.getHostId()));
+
+ if (setByHost == null) {
+ setByHost = new HashSet<ConfigGroupHostMapping>();
+ configGroupHostMappingByHost.put(configGroupHostMappingEntity.getHostId(), setByHost);
+ }
+
+ ConfigGroupHostMapping configGroupHostMapping = buildConfigGroupHostMapping(configGroupHostMappingEntity);
+ setByHost.add(configGroupHostMapping);
}
-
- ConfigGroupHostMapping configGroupHostMapping = buildConfigGroupHostMapping(configGroupHostMappingEntity);
- setByHost.add(configGroupHostMapping);
- }
+ }
+ cacheLoaded = true;
}
} finally {
gl.writeLock().unlock();
}
- cacheLoaded = true;
}
@@ -308,7 +314,12 @@ public class ConfigGroupHostMappingDAO {
}
private ConfigGroup buildConfigGroup(ConfigGroupEntity configGroupEntity) {
- Cluster cluster = clusterFactory.create(configGroupEntity.getClusterEntity());
+ Cluster cluster = null;
+ try {
+ cluster = clusters.getClusterById(configGroupEntity.getClusterId());
+ } catch (AmbariException e) {
+ //almost impossible
+ }
ConfigGroup configGroup = configGroupFactory.createExisting(cluster, configGroupEntity);
return configGroup;
http://git-wip-us.apache.org/repos/asf/ambari/blob/64bc2473/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
index 6bab661..d322735 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
@@ -343,7 +343,7 @@ public class ConfigGroupImpl implements ConfigGroup {
* @throws Exception
*/
@Transactional
- private void persistEntities() {
+ void persistEntities() {
ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
configGroupEntity.setClusterEntity(clusterEntity);
configGroupEntity.setTimestamp(System.currentTimeMillis());
@@ -361,7 +361,7 @@ public class ConfigGroupImpl implements ConfigGroup {
* @throws Exception
*/
@Transactional
- private void persistHostMapping() {
+ void persistHostMapping() {
if (isPersisted) {
// Delete existing mappings and create new ones
configGroupHostMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
@@ -370,7 +370,7 @@ public class ConfigGroupImpl implements ConfigGroup {
if (hosts != null && !hosts.isEmpty()) {
for (Host host : hosts.values()) {
- HostEntity hostEntity = hostDAO.findByName(host.getHostName());
+ HostEntity hostEntity = hostDAO.findById(host.getHostId());
if (hostEntity != null) {
ConfigGroupHostMappingEntity hostMappingEntity = new
ConfigGroupHostMappingEntity();
@@ -398,7 +398,7 @@ public class ConfigGroupImpl implements ConfigGroup {
* @throws Exception
*/
@Transactional
- private void persistConfigMapping(ClusterEntity clusterEntity) {
+ void persistConfigMapping(ClusterEntity clusterEntity) {
if (isPersisted) {
configGroupConfigMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
configGroupEntity.getConfigGroupConfigMappingEntities().clear();
@@ -451,7 +451,7 @@ public class ConfigGroupImpl implements ConfigGroup {
}
@Transactional
- private void saveIfPersisted() {
+ void saveIfPersisted() {
ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
if (isPersisted) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/64bc2473/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
index 5e0debf..753daec 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
@@ -275,10 +275,14 @@ public class ConfigGroupResourceProviderTest {
expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
expect(clusters.getHost("h1")).andReturn(h1);
expect(clusters.getHost("h2")).andReturn(h2);
- expect(hostDAO.findByName("h1")).andReturn(hostEntity1).atLeastOnce();
- expect(hostDAO.findByName("h2")).andReturn(hostEntity2).atLeastOnce();
+ expect(hostDAO.findByName("h1")).andReturn(hostEntity1).anyTimes();
+ expect(hostDAO.findById(1L)).andReturn(hostEntity1).anyTimes();
+ expect(hostDAO.findByName("h2")).andReturn(hostEntity2).anyTimes();
+ expect(hostDAO.findById(2L)).andReturn(hostEntity2).anyTimes();
expect(hostEntity1.getHostId()).andReturn(1L).atLeastOnce();
expect(hostEntity2.getHostId()).andReturn(2L).atLeastOnce();
+ expect(h1.getHostId()).andReturn(1L).anyTimes();
+ expect(h2.getHostId()).andReturn(2L).anyTimes();
expect(configGroup.getName()).andReturn("test-1").anyTimes();
expect(configGroup.getId()).andReturn(25L).anyTimes();
@@ -301,7 +305,7 @@ public class ConfigGroupResourceProviderTest {
expectLastCall().once();
replay(managementController, clusters, cluster,
- configGroup, response, configGroupResponse, configHelper, hostDAO, hostEntity1, hostEntity2);
+ configGroup, response, configGroupResponse, configHelper, hostDAO, hostEntity1, hostEntity2, h1, h2);
ResourceProvider provider = getConfigGroupResourceProvider
(managementController);
@@ -350,7 +354,7 @@ public class ConfigGroupResourceProviderTest {
provider.updateResources(request, predicate);
verify(managementController, clusters, cluster,
- configGroup, response, configGroupResponse, configHelper, hostDAO, hostEntity1, hostEntity2);
+ configGroup, response, configGroupResponse, configHelper, hostDAO, hostEntity1, hostEntity2, h1, h2);
}
@SuppressWarnings("unchecked")