問題
在刪除之前的services之后鸣皂,重新安裝的時候恢准,發(fā)現(xiàn)日志中各有以下錯誤
17 Oct 2017 16:31:51,266 ERROR [ambari-hearbeat-monitor] HostImpl:1084 - Config inconsistency exists: unknown configType=hbase-site
同時戳气,在安裝HDFS的時候句各,ambari-server卡在了推薦host機器的地方吸占,報錯如下:
17 Oct 2017 15:38:36,515 ERROR [ambari-client-thread-31] ReadHandler:102 - Caught a runtime exception executing a query
java.lang.NullPointerException
at org.apache.ambari.server.state.HostConfig.hashCode(HostConfig.java:57)
at java.util.TreeMap$Entry.hashCode(TreeMap.java:1948)
at java.util.AbstractMap.hashCode(AbstractMap.java:494)
at java.util.Collections$SynchronizedMap.hashCode(Collections.java:2087)
at java.util.TreeMap$Entry.hashCode(TreeMap.java:1948)
at java.util.AbstractMap.hashCode(AbstractMap.java:494)
at java.util.Collections$SynchronizedMap.hashCode(Collections.java:2087)
at org.apache.ambari.server.controller.internal.ResourceImpl.hashCode(ResourceImpl.java:160)
at java.util.HashMap.hash(HashMap.java:362)
at java.util.HashMap.put(HashMap.java:492)
at java.util.HashSet.add(HashSet.java:217)
at org.apache.ambari.server.controller.internal.HostResourceProvider.getResourcesAuthorized(HostResourceProvider.java:307)
at org.apache.ambari.server.controller.internal.AbstractAuthorizedResourceProvider.getResources(AbstractAuthorizedResourceProvider.java:266)
at org.apache.ambari.server.controller.internal.ClusterControllerImpl$ExtendedResourceProviderWrapper.queryForResources(ClusterControllerImpl.java:966)
at org.apache.ambari.server.controller.internal.ClusterControllerImpl.getResources(ClusterControllerImpl.java:141)
at org.apache.ambari.server.api.query.QueryImpl.doQuery(QueryImpl.java:529)
at org.apache.ambari.server.api.query.QueryImpl.queryForResources(QueryImpl.java:398)
at org.apache.ambari.server.api.query.QueryImpl.execute(QueryImpl.java:222)
at org.apache.ambari.server.api.handlers.ReadHandler.handleRequest(ReadHandler.java:77)
at org.apache.ambari.server.api.services.BaseRequest.process(BaseRequest.java:144)
at org.apache.ambari.server.api.services.BaseService.handleRequest(BaseService.java:126)
at org.apache.ambari.server.api.services.BaseService.handleRequest(BaseService.java:90)
at org.apache.ambari.server.api.services.stackadvisor.commands.StackAdvisorCommand.getHostsInformation(StackAdvisorCommand.java:364)
at org.apache.ambari.server.api.services.stackadvisor.commands.StackAdvisorCommand.invoke(StackAdvisorCommand.java:283)
at org.apache.ambari.server.api.services.stackadvisor.StackAdvisorHelper.recommend(StackAdvisorHelper.java:113)
at org.apache.ambari.server.controller.internal.RecommendationResourceProvider.createResources(RecommendationResourceProvider.java:92)
at org.apache.ambari.server.controller.internal.ClusterControllerImpl.createResources(ClusterControllerImpl.java:298)
at org.apache.ambari.server.api.services.persistence.PersistenceManagerImpl.create(PersistenceManagerImpl.java:97)
at org.apache.ambari.server.api.handlers.CreateHandler.persist(CreateHandler.java:37)
at org.apache.ambari.server.api.handlers.BaseManagementHandler.handleRequest(BaseManagementHandler.java:73)
at org.apache.ambari.server.api.services.BaseRequest.process(BaseRequest.java:144)
at org.apache.ambari.server.api.services.BaseService.handleRequest(BaseService.java:126)
at org.apache.ambari.server.api.services.BaseService.handleRequest(BaseService.java:90)
at org.apache.ambari.server.api.services.RecommendationService.getRecommendation(RecommendationService.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1507)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter.doFilter(AmbariAuthorizationFilter.java:287)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.apache.ambari.server.security.authentication.AmbariDelegatingAuthenticationFilter.doFilter(AmbariDelegatingAuthenticationFilter.java:132)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.apache.ambari.server.security.authorization.AmbariUserAuthorizationFilter.doFilter(AmbariUserAuthorizationFilter.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1478)
at org.apache.ambari.server.api.MethodOverrideFilter.doFilter(MethodOverrideFilter.java:72)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1478)
at org.apache.ambari.server.api.AmbariPersistFilter.doFilter(AmbariPersistFilter.java:47)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1478)
at org.apache.ambari.server.security.AbstractSecurityHeaderFilter.doFilter(AbstractSecurityHeaderFilter.java:125)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1478)
at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:82)
at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:294)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1478)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:427)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.apache.ambari.server.controller.AmbariHandlerList.processHandlers(AmbariHandlerList.java:212)
at org.apache.ambari.server.controller.AmbariHandlerList.processHandlers(AmbariHandlerList.java:201)
at org.apache.ambari.server.controller.AmbariHandlerList.handle(AmbariHandlerList.java:139)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:984)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1045)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:231)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
問題梳理
-
Config inconsistency exists: unknown configType=hbase-site
錯誤: 已經(jīng)在ambari-server中將hbase服務(wù)刪除掉晴叨,出現(xiàn)該錯誤懷疑上次刪除完關(guān)閉ambari-server時,沒有來得及更新數(shù)據(jù)庫導(dǎo)致的矾屯,所以需要手動變更數(shù)據(jù)庫才能解決兼蕊;
-
- 為何上述問題導(dǎo)致了第二條異常?
源碼解析
定位到異常錯誤的地方,在HostImpl中件蚕,看到如下的代碼:
@Override
public Map<String, HostConfig> getDesiredHostConfigs(Cluster cluster,
Map<String, DesiredConfig> clusterDesiredConfigs) throws AmbariException {
Map<String, HostConfig> hostConfigMap = new HashMap<String, HostConfig>();
if( null == cluster ){
clusterDesiredConfigs = new HashMap<String, DesiredConfig>();
}
// per method contract, fetch if not supplied
if (null == clusterDesiredConfigs) {
clusterDesiredConfigs = cluster.getDesiredConfigs();
}
if (clusterDesiredConfigs != null) {
for (Map.Entry<String, DesiredConfig> desiredConfigEntry
: clusterDesiredConfigs.entrySet()) {
HostConfig hostConfig = new HostConfig();
hostConfig.setDefaultVersionTag(desiredConfigEntry.getValue().getTag());
hostConfigMap.put(desiredConfigEntry.getKey(), hostConfig);
}
}
// 懷疑是這里`cluster.getConfigGroupsByHostname(getHostName())`引入了沒有刪除的數(shù)據(jù)
Map<Long, ConfigGroup> configGroups = (cluster == null) ? new HashMap<Long, ConfigGroup>() : cluster.getConfigGroupsByHostname(getHostName());
if (configGroups != null && !configGroups.isEmpty()) {
for (ConfigGroup configGroup : configGroups.values()) {
for (Map.Entry<String, Config> configEntry : configGroup
.getConfigurations().entrySet()) {
String configType = configEntry.getKey();
// HostConfig config holds configType -> versionTag, per config group
HostConfig hostConfig = hostConfigMap.get(configType);
if (hostConfig == null) {
hostConfig = new HostConfig();
hostConfigMap.put(configType, hostConfig);
if (cluster != null) {
Config conf = cluster.getDesiredConfigByType(configType);
if(conf == null) {
//報錯出現(xiàn)在這個地方孙技,說明該config已經(jīng)被清理,但是循環(huán)還是走到了這里排作!
LOG.error("Config inconsistency exists:"+
" unknown configType="+configType);
} else {
hostConfig.setDefaultVersionTag(conf.getTag());
}
}
}
Config config = configEntry.getValue();
hostConfig.getConfigGroupOverrides().put(configGroup.getId(),
config.getTag());
}
}
}
return hostConfigMap;
}
在ambari中牵啦,同數(shù)據(jù)庫的連接是基于jpa完成的,找到ClusterEntity
下的configGroupEntities定義妄痪,可以看出ClusterEntity同ConfigGroupEntity之間的關(guān)系哈雏,
@OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
private Collection<ConfigGroupEntity> configGroupEntities;
在ConfigGroupEnity
中,可以發(fā)現(xiàn)其依賴一下兩個表:
@OneToMany(mappedBy = "configGroupEntity", cascade = CascadeType.ALL)
private Collection<ConfigGroupHostMappingEntity> configGroupHostMappingEntities;
@OneToMany(mappedBy = "configGroupEntity", cascade = CascadeType.ALL)
private Collection<ConfigGroupConfigMappingEntity> configGroupConfigMappingEntities;
在數(shù)據(jù)庫中找到如下對應(yīng)關(guān)系衫生,定位到問題:
mysql> select * from configgroup;
+----------+------------+------------+-------+----------------------------------------------------+------------------+--------------+
| group_id | cluster_id | group_name | tag | description | create_timestamp | service_name |
+----------+------------+------------+-------+----------------------------------------------------+------------------+--------------+
| 2 | 52 | test1 | HBASE | New configuration group created on Thu Sep 14 2017 | 1505381598669 | HBASE |
+----------+------------+------------+-------+----------------------------------------------------+------------------+--------------+
mysql> select * from confgroupclusterconfigmapping;
+-----------------+------------+-------------+----------------------+-----------+------------------+
| config_group_id | cluster_id | config_type | version_tag | user_name | create_timestamp |
+-----------------+------------+-------------+----------------------+-----------+------------------+| 2 | 52 | hbase-site | version1505381645818 | _db | 1505382442088 |+-----------------+------------+-------------+----------------------+-----------+------------------+
數(shù)據(jù)庫中數(shù)據(jù)清理
由于 confgroupclusterconfigmapping 中的group_id為configgroup的外鍵裳瘪,存在依賴關(guān)系,所以操作如下罪针,
mysql> delete from confgroupclusterconfigmapping;
Query OK, 1 row affected (0.02 sec)
mysql> delete from configgroup where group_id=2;ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`ambari`.`configgrouphostmapping`, CONSTRAINT `FK_cghm_cgid` FOREIGN KEY (`config_group_id`) REFERENCES `configgroup` (`group_id`))
mysql> SET FOREIGN_KEY_CHECKS=0;Query OK, 0 rows affected (0.00 sec)
mysql> delete from configgroup where group_id=2;Query OK, 1 row affected (0.00 sec)
mysql> SET FOREIGN_KEY_CHECKS=1;Query OK, 0 rows affected (0.00 sec)
總結(jié)
- 從問題上看彭羹,是數(shù)據(jù)庫中數(shù)據(jù)跟真實環(huán)境不一致導(dǎo)致的,具體原因沒法復(fù)現(xiàn)泪酱;
- Ambari-Server的處理流程強依賴于數(shù)據(jù)庫派殷,所以后續(xù)需要梳理數(shù)據(jù)庫各表之間的關(guān)系;