Преглед на файлове

AMBARI-20805. Autofix db leads to dangling entries in ClusterConfigMapping table (dlysnichenko)

Lisnichenko Dmitro преди 8 години
родител
ревизия
23f8b85b8b

+ 3 - 6
ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java

@@ -527,12 +527,9 @@ public class DatabaseConsistencyCheckHelper {
     List<ClusterConfigEntity> notMappedClusterConfigs = getNotMappedClusterConfigsToService();
 
     for (ClusterConfigEntity clusterConfigEntity : notMappedClusterConfigs){
-      List<String> types = new ArrayList<>();
-      String type = clusterConfigEntity.getType();
-      types.add(type);
-      LOG.error("Removing cluster config mapping of type {} that is not mapped to any service", type);
-      clusterDAO.removeClusterConfigMappingEntityByTypes(clusterConfigEntity.getClusterId(),types);
-      LOG.error("Removing config that is not mapped to any service", clusterConfigEntity);
+      LOG.info("Removing cluster config mapping of clusterConfigEntity {} that is not mapped to any service", clusterConfigEntity);
+      clusterDAO.removeClusterConfigMappingEntityByConfig(clusterConfigEntity);
+      LOG.info("Removing config that is not mapped to any service {}", clusterConfigEntity);
       clusterDAO.removeConfig(clusterConfigEntity);
     }
   }

+ 15 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java

@@ -364,6 +364,21 @@ public class ClusterDAO {
       daoUtils.executeUpdate(query, clusterId, types);
     }
 
+  /**
+   * Delete ClusterConfigMappingEntity corresponds to clusterConfigEntity
+   *
+   * @param clusterConfigEntity
+   *          clusterConfigEntity to match.
+   */
+  @Transactional
+  public void removeClusterConfigMappingEntityByConfig(ClusterConfigEntity clusterConfigEntity) {
+
+    TypedQuery<Long> query = entityManagerProvider.get().createQuery
+        ("DELETE FROM ClusterConfigMappingEntity configs WHERE configs" +
+            ".clusterId=?1 AND configs.typeName= ?2 AND configs.tag=?3 ", Long.class);
+
+    daoUtils.executeUpdate(query, clusterConfigEntity.getClusterId(), clusterConfigEntity.getType(), clusterConfigEntity.getTag());
+  }
 
   /**
    * Retrieve entity data from DB