Commit d9ebc242 by Madhan Neethiraj

ATLAS-3544: fix NPE during entity-delete

parent 9f5b7861
...@@ -99,22 +99,27 @@ public abstract class DeleteHandlerV1 { ...@@ -99,22 +99,27 @@ public abstract class DeleteHandlerV1 {
* @throws AtlasException * @throws AtlasException
*/ */
public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasBaseException { public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasBaseException {
RequestContext requestContext = RequestContext.get(); final RequestContext requestContext = RequestContext.get();
Set<AtlasVertex> deletionCandidateVertices = new HashSet<>(); final Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();
final boolean isPurgeRequested = requestContext.isPurgeRequested();
for (AtlasVertex instanceVertex : instanceVertices) { for (AtlasVertex instanceVertex : instanceVertices) {
String guid = AtlasGraphUtilsV2.getIdFromVertex(instanceVertex); final String guid = AtlasGraphUtilsV2.getIdFromVertex(instanceVertex);
AtlasEntity.Status state = getState(instanceVertex); final AtlasEntity.Status state = getState(instanceVertex);
final boolean needToSkip;
boolean needToSkip = requestContext.isPurgeRequested() ? (state == ACTIVE || requestContext.isPurgedEntity(guid)) : if (isPurgeRequested) {
(state == DELETED || requestContext.isDeletedEntity(guid)); needToSkip = state == ACTIVE || requestContext.isPurgedEntity(guid);
} else {
needToSkip = state == DELETED || requestContext.isDeletedEntity(guid);
}
if (needToSkip) { if (needToSkip) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
if(RequestContext.get().isPurgeRequested()) { if (isPurgeRequested) {
LOG.debug("Skipping purging of {} as it is active or already purged", guid); LOG.debug("Skipping purging of entity={} as it is active or already purged", guid);
} else { } else {
LOG.debug("Skipping deletion of {} as it is already deleted", guid); LOG.debug("Skipping deletion of entity={} as it is already deleted", guid);
} }
} }
...@@ -154,16 +159,18 @@ public abstract class DeleteHandlerV1 { ...@@ -154,16 +159,18 @@ public abstract class DeleteHandlerV1 {
* @throws AtlasBaseException * @throws AtlasBaseException
*/ */
public void deleteRelationships(Collection<AtlasEdge> edges, final boolean forceDelete) throws AtlasBaseException { public void deleteRelationships(Collection<AtlasEdge> edges, final boolean forceDelete) throws AtlasBaseException {
final boolean isPurgeRequested = RequestContext.get().isPurgeRequested();
for (AtlasEdge edge : edges) { for (AtlasEdge edge : edges) {
boolean isInternal = isInternalType(edge.getInVertex()) && isInternalType(edge.getOutVertex()); boolean isInternal = isInternalType(edge.getInVertex()) && isInternalType(edge.getOutVertex());
boolean needToSkip = !isInternal && (RequestContext.get().isPurgeRequested() ? getState(edge) == ACTIVE : getState(edge) == DELETED); boolean needToSkip = !isInternal && (getState(edge) == (isPurgeRequested ? ACTIVE : DELETED));
if (needToSkip) { if (needToSkip) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
if(RequestContext.get().isPurgeRequested()) { if(isPurgeRequested) {
LOG.debug("Skipping purging of {} as it is active or already purged", getIdFromEdge(edge)); LOG.debug("Skipping purging of edge={} as it is active or already purged", getIdFromEdge(edge));
} else{ } else{
LOG.debug("Skipping deletion of {} as it is already deleted", getIdFromEdge(edge)); LOG.debug("Skipping deletion of edge={} as it is already deleted", getIdFromEdge(edge));
} }
} }
...@@ -186,8 +193,9 @@ public abstract class DeleteHandlerV1 { ...@@ -186,8 +193,9 @@ public abstract class DeleteHandlerV1 {
* @throws AtlasException * @throws AtlasException
*/ */
public Collection<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException { public Collection<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException {
Map<String, GraphHelper.VertexInfo> vertexInfoMap = new HashMap<>(); final Map<String, GraphHelper.VertexInfo> vertexInfoMap = new HashMap<>();
Stack<AtlasVertex> vertices = new Stack<>(); final Stack<AtlasVertex> vertices = new Stack<>();
final boolean isPurgeRequested = RequestContext.get().isPurgeRequested();
vertices.push(entityVertex); vertices.push(entityVertex);
...@@ -197,8 +205,7 @@ public abstract class DeleteHandlerV1 { ...@@ -197,8 +205,7 @@ public abstract class DeleteHandlerV1 {
//In case of purge If the reference vertex is active then skip it or else //In case of purge If the reference vertex is active then skip it or else
//If the vertex marked for deletion, skip it //If the vertex marked for deletion, skip it
boolean needToSkip = RequestContext.get().isPurgeRequested() ? (state == ACTIVE) : (state == DELETED); if (state == (isPurgeRequested ? ACTIVE : DELETED)) {
if (needToSkip) {
continue; continue;
} }
...@@ -235,9 +242,7 @@ public abstract class DeleteHandlerV1 { ...@@ -235,9 +242,7 @@ public abstract class DeleteHandlerV1 {
} else { } else {
AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel); AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
needToSkip = (edge == null || RequestContext.get().isPurgeRequested() ? if (edge == null || (getState(edge) == (isPurgeRequested ? ACTIVE : DELETED))) {
getState(edge) == ACTIVE : getState(edge) == DELETED);
if (needToSkip) {
continue; continue;
} }
...@@ -290,9 +295,7 @@ public abstract class DeleteHandlerV1 { ...@@ -290,9 +295,7 @@ public abstract class DeleteHandlerV1 {
if (CollectionUtils.isNotEmpty(edges)) { if (CollectionUtils.isNotEmpty(edges)) {
for (AtlasEdge edge : edges) { for (AtlasEdge edge : edges) {
needToSkip = (edge == null || RequestContext.get().isPurgeRequested() ? if (edge == null || (getState(edge) == (isPurgeRequested ? ACTIVE : DELETED))) {
getState(edge) == ACTIVE : getState(edge) == DELETED);
if (needToSkip) {
continue; continue;
} }
...@@ -852,12 +855,17 @@ public abstract class DeleteHandlerV1 { ...@@ -852,12 +855,17 @@ public abstract class DeleteHandlerV1 {
LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), attribute.getName()); LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), attribute.getName());
} }
final String typeName = GraphHelper.getTypeName(outVertex); final RequestContext requestContext = RequestContext.get();
final String outId = GraphHelper.getGuid(outVertex); final String typeName = GraphHelper.getTypeName(outVertex);
final Status state = getState(outVertex); final String outId = GraphHelper.getGuid(outVertex);
final Status state = getState(outVertex);
final boolean needToSkip;
boolean needToSkip = RequestContext.get().isPurgeRequested() ? state == ACTIVE || (outId != null && RequestContext.get().isPurgedEntity(outId)) : if (requestContext.isPurgeRequested()) {
state == DELETED || (outId != null && RequestContext.get().isDeletedEntity(outId)); needToSkip = state == ACTIVE || (outId != null && requestContext.isPurgedEntity(outId));
} else {
needToSkip = state == DELETED || (outId != null && requestContext.isDeletedEntity(outId));
}
if (needToSkip) { if (needToSkip) {
return; return;
...@@ -952,8 +960,6 @@ public abstract class DeleteHandlerV1 { ...@@ -952,8 +960,6 @@ public abstract class DeleteHandlerV1 {
if (edge != null) { if (edge != null) {
deleteEdge(edge, isInternalType(inVertex) && isInternalType(outVertex)); deleteEdge(edge, isInternalType(inVertex) && isInternalType(outVertex));
RequestContext requestContext = RequestContext.get();
if (! requestContext.isUpdatedEntity(outId)) { if (! requestContext.isUpdatedEntity(outId)) {
AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime());
AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFIED_BY_KEY, requestContext.getUser()); AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFIED_BY_KEY, requestContext.getUser());
...@@ -969,12 +975,13 @@ public abstract class DeleteHandlerV1 { ...@@ -969,12 +975,13 @@ public abstract class DeleteHandlerV1 {
} }
// Delete external references to this vertex - incoming edges from lineage or glossary term edges // Delete external references to this vertex - incoming edges from lineage or glossary term edges
Iterable<AtlasEdge> incomingEdges = instanceVertex.getEdges(AtlasEdgeDirection.IN); final Iterable<AtlasEdge> incomingEdges = instanceVertex.getEdges(AtlasEdgeDirection.IN);
final boolean isPurgeRequested = RequestContext.get().isPurgeRequested();
for (AtlasEdge edge : incomingEdges) { for (AtlasEdge edge : incomingEdges) {
Status edgeState = getState(edge); AtlasEntity.Status edgeStatus = getStatus(edge);
boolean isProceed = edgeStatus == (isPurgeRequested ? DELETED : ACTIVE);
boolean isProceed = RequestContext.get().isPurgeRequested()? edgeState == DELETED : edgeState == ACTIVE;
if (isProceed) { if (isProceed) {
if (isRelationshipEdge(edge)) { if (isRelationshipEdge(edge)) {
deleteRelationship(edge); deleteRelationship(edge);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment