Ambari中表數(shù)據(jù)異常導(dǎo)致的一個小問題

問題

在刪除之前的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)

問題梳理

    1. 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ù)庫才能解決兼蕊;
    1. 為何上述問題導(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)系;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末西篓,一起剝皮案震驚了整個濱河市愈腾,隨后出現(xiàn)的幾起案子憋活,更是在濱河造成了極大的恐慌岂津,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,042評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件悦即,死亡現(xiàn)場離奇詭異吮成,居然都是意外死亡,警方通過查閱死者的電腦和手機辜梳,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評論 2 384
  • 文/潘曉璐 我一進店門粱甫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人作瞄,你說我怎么就攤上這事茶宵。” “怎么了宗挥?”我有些...
    開封第一講書人閱讀 156,674評論 0 345
  • 文/不壞的土叔 我叫張陵乌庶,是天一觀的道長种蝶。 經(jīng)常有香客問我,道長瞒大,這世上最難降的妖魔是什么螃征? 我笑而不...
    開封第一講書人閱讀 56,340評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮透敌,結(jié)果婚禮上盯滚,老公的妹妹穿的比我還像新娘。我一直安慰自己酗电,他們只是感情好魄藕,可當(dāng)我...
    茶點故事閱讀 65,404評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著顾瞻,像睡著了一般泼疑。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上荷荤,一...
    開封第一講書人閱讀 49,749評論 1 289
  • 那天退渗,我揣著相機與錄音,去河邊找鬼蕴纳。 笑死会油,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的古毛。 我是一名探鬼主播翻翩,決...
    沈念sama閱讀 38,902評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼稻薇!你這毒婦竟也來了嫂冻?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,662評論 0 266
  • 序言:老撾萬榮一對情侶失蹤塞椎,失蹤者是張志新(化名)和其女友劉穎桨仿,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體案狠,經(jīng)...
    沈念sama閱讀 44,110評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡服傍,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了骂铁。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片吹零。...
    茶點故事閱讀 38,577評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖拉庵,靈堂內(nèi)的尸體忽然破棺而出灿椅,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 34,258評論 4 328
  • 正文 年R本政府宣布茫蛹,位于F島的核電站泣懊,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏麻惶。R本人自食惡果不足惜馍刮,卻給世界環(huán)境...
    茶點故事閱讀 39,848評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望窃蹋。 院中可真熱鬧卡啰,春花似錦、人聲如沸警没。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽杀迹。三九已至亡脸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間树酪,已是汗流浹背浅碾。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評論 1 264
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留续语,地道東北人垂谢。 一個月前我還...
    沈念sama閱讀 46,271評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像疮茄,于是被迫代替她去往敵國和親滥朱。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,452評論 2 348

推薦閱讀更多精彩內(nèi)容