Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
e4f0b09e
Commit
e4f0b09e
authored
Jun 01, 2019
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3227: fixed removal of indexes while deleting typedefs
parent
a92ddec0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
56 deletions
+36
-56
GraphBackedSearchIndexer.java
...ache/atlas/repository/graph/GraphBackedSearchIndexer.java
+36
-56
No files found.
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
View file @
e4f0b09e
...
...
@@ -181,7 +181,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
);
}
}
...
...
@@ -335,6 +335,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
static
boolean
isStringAttribute
(
AtlasStructDef
.
AtlasAttributeDef
attributeDef
)
{
return
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
.
equals
(
attributeDef
.
getTypeName
());
}
...
...
@@ -428,6 +449,20 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
}
}
private
void
deleteIndexForAttribute
(
AtlasGraphManagement
management
,
String
typeName
,
AtlasAttributeDef
attributeDef
)
{
final
String
propertyName
=
AtlasGraphUtilsV2
.
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
))
{
...
...
@@ -767,61 +802,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
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
typeName
+
"."
+
attributeDef
.
getName
());
String
attribTypeName
=
attributeDef
.
getTypeName
();
boolean
isBuiltInType
=
AtlasTypeUtil
.
isBuiltInType
(
attribTypeName
);
boolean
isArrayType
=
isArrayType
(
attribTypeName
);
boolean
isMapType
=
isMapType
(
attribTypeName
);
try
{
AtlasType
atlasType
=
typeRegistry
.
getType
(
attribTypeName
);
if
(
isClassificationType
(
atlasType
)
||
isEntityType
(
atlasType
))
{
LOG
.
warn
(
"Ignoring non-indexable attribute {}"
,
attribTypeName
);
}
else
if
(
isBuiltInType
||
isEnumType
(
atlasType
)
||
isArrayType
||
isMapType
)
{
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment