This is an automated email from the ASF dual-hosted git repository. madhan pushed a commit to branch branch-0.8 in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/branch-0.8 by this push: new 213c1ed ATLAS-3227: fixed removal of indexes while deleting typedefs 213c1ed is described below commit 213c1ededf1437943ada14ff44f1530a1784f681 Author: Madhan Neethiraj <mad...@apache.org> AuthorDate: Sat Jun 1 12:59:06 2019 -0700 ATLAS-3227: fixed removal of indexes while deleting typedefs (cherry picked from commit e4f0b09e216360022f004126efcc2670c1038136) (cherry picked from commit d887d8aef09bf8c6ceb9e4af9758d2bf7342c5df) (cherry picked from commit a8b1c6d70f4d7de01648ca5a5d70da816896dfbe) --- .../repository/graph/GraphBackedSearchIndexer.java | 91 +++++++++------------- 1 file changed, 36 insertions(+), 55 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java index eca6f41..54f44af 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java @@ -314,6 +314,27 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } } + private void deleteIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) { + Preconditions.checkNotNull(typeDef, "Cannot process null typedef"); + + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting indexes for type {}", typeDef.getName()); + } + + if (typeDef instanceof AtlasStructDef) { + AtlasStructDef structDef = (AtlasStructDef) typeDef; + List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs(); + + if (CollectionUtils.isNotEmpty(attributeDefs)) { + for (AtlasAttributeDef attributeDef : attributeDefs) { + deleteIndexForAttribute(management, typeDef.getName(), attributeDef); + } + } + } + + LOG.info("Completed deleting indexes for type {}", typeDef.getName()); + } + private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + attributeDef.getName()); @@ -348,6 +369,20 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } } + private void deleteIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { + final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + attributeDef.getName()); + + try { + if (management.containsPropertyKey(propertyName)) { + LOG.info("Deleting propertyKey {}, for attribute {}.{}", propertyName, typeName, attributeDef.getName()); + + management.deletePropertyKey(propertyName); + } + } catch (Exception excp) { + LOG.warn("Failed to delete propertyKey {}, for attribute {}.{}", propertyName, typeName, attributeDef.getName()); + } + } + private void createLabelIfNeeded(final AtlasGraphManagement management, final String propertyName, final String attribTypeName) { // If any of the referenced typename is of type Entity or Struct then the edge label needs to be created for (String typeName : AtlasTypeUtil.getReferencedTypeNames(attribTypeName)) { @@ -729,7 +764,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang // Invalidate the property key for deleted types if (CollectionUtils.isNotEmpty(changedTypeDefs.getDeletedTypeDefs())) { for (AtlasBaseTypeDef typeDef : changedTypeDefs.getDeletedTypeDefs()) { - cleanupIndices(management, typeDef); + deleteIndexForType(management, typeDef); } } @@ -742,60 +777,6 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } - private void cleanupIndices(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) { - Preconditions.checkNotNull(typeDef, "Cannot process null typedef"); - if (LOG.isDebugEnabled()) { - LOG.debug("Cleaning up index for {}", typeDef); - } - - if (typeDef instanceof AtlasEnumDef) { - // Only handle complex types like Struct, Classification and Entity - return; - } - - if (typeDef instanceof AtlasStructDef) { - AtlasStructDef structDef = (AtlasStructDef) typeDef; - List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs(); - if (CollectionUtils.isNotEmpty(attributeDefs)) { - for (AtlasAttributeDef attributeDef : attributeDefs) { - cleanupIndexForAttribute(management, typeDef.getName(), attributeDef); - } - } - } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())){ - throw new IllegalArgumentException("bad data type" + typeDef.getName()); - } - } - - private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { - final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + attributeDef.getName()); - String attribTypeName = attributeDef.getTypeName(); - boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName); - boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName); - boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName); - - try { - AtlasType atlasType = typeRegistry.getType(attribTypeName); - - if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) { - LOG.warn("Ignoring non-indexable attribute {}", attribTypeName); - } else if (isBuiltInType || isEnumType(atlasType)) { - cleanupIndex(management, propertyName); - } else if (isStructType(atlasType)) { - AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName); - cleanupIndices(management, structDef); - } - } catch (AtlasBaseException e) { - LOG.error("No type exists for {}", attribTypeName, e); - } - } - - private void cleanupIndex(AtlasGraphManagement management, String propertyKey) { - if (LOG.isDebugEnabled()) { - LOG.debug("Invalidating property key = {}", propertyKey); - } - management.deletePropertyKey(propertyKey); - } - private void attemptRollback(ChangedTypeDefs changedTypeDefs, AtlasGraphManagement management) throws AtlasBaseException { if (null != management) {