@@ -223,8 +223,21 @@ public Set<AtlasVertex> accumulateDeletionCandidates(Collection<AtlasVertex> ins
223223 */
224224 public void deleteTraitsAndVertices (Collection <AtlasVertex > deletionCandidateVertices ) throws AtlasBaseException {
225225 for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices ) {
226- deleteAllClassifications (deletionCandidateVertex );
227- deleteTypeVertex (deletionCandidateVertex , isInternalType (deletionCandidateVertex ));
226+ if (deletionCandidateVertex == null ) {
227+ continue ;
228+ }
229+
230+ if (!deletionCandidateVertex .exists ()) {
231+ LOG .warn ("deleteTraitsAndVertices(): skipping vertex - already removed" );
232+ continue ;
233+ }
234+
235+ try {
236+ deleteAllClassifications (deletionCandidateVertex );
237+ deleteTypeVertex (deletionCandidateVertex , isInternalType (deletionCandidateVertex ));
238+ } catch (IllegalStateException e ) {
239+ LOG .warn ("deleteTraitsAndVertices(): skipping vertex - already removed" , e );
240+ }
228241 }
229242 }
230243
@@ -717,11 +730,15 @@ public boolean isRelationshipEdge(AtlasEdge edge) {
717730 boolean ret = false ;
718731
719732 if (edge != null ) {
720- String outVertexType = getTypeName (edge .getOutVertex ());
721- String inVertexType = getTypeName (edge .getInVertex ());
733+ try {
734+ String outVertexType = getTypeName (edge .getOutVertex ());
735+ String inVertexType = getTypeName (edge .getInVertex ());
722736
723- ret = GraphHelper .isRelationshipEdge (edge ) || edge .getPropertyKeys ().contains (RELATIONSHIP_GUID_PROPERTY_KEY ) ||
724- (typeRegistry .getEntityTypeByName (outVertexType ) != null && typeRegistry .getEntityTypeByName (inVertexType ) != null );
737+ ret = GraphHelper .isRelationshipEdge (edge ) || edge .getPropertyKeys ().contains (RELATIONSHIP_GUID_PROPERTY_KEY ) ||
738+ (typeRegistry .getEntityTypeByName (outVertexType ) != null && typeRegistry .getEntityTypeByName (inVertexType ) != null );
739+ } catch (IllegalStateException e ) {
740+ LOG .warn ("Skipping edge {} because one of its vertices was removed" , edge .getIdForDisplay (), e );
741+ }
725742 }
726743
727744 return ret ;
@@ -1255,17 +1272,45 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At
12551272 final boolean isPurgeRequested = RequestContext .get ().isPurgeRequested ();
12561273
12571274 for (AtlasEdge edge : incomingEdges ) {
1275+ if (!edge .exists ()) {
1276+ LOG .debug ("deleteVertex(): skipping edge {} - already removed in this transaction" , edge .getIdForDisplay ());
1277+ continue ;
1278+ }
1279+
1280+ AtlasVertex outVertex ;
1281+ try {
1282+ outVertex = edge .getOutVertex ();
1283+ } catch (IllegalStateException e ) {
1284+ LOG .warn ("deleteVertex(): skipping edge {} - out-vertex was already removed" , edge .getIdForDisplay (), e );
1285+ continue ;
1286+ }
1287+
1288+ if (!outVertex .exists ()) {
1289+ LOG .debug ("deleteVertex(): skipping edge {} - out-vertex {} already removed in this transaction" , edge .getIdForDisplay (), outVertex .getIdForDisplay ());
1290+ continue ;
1291+ }
1292+
12581293 AtlasEntity .Status edgeStatus = getStatus (edge );
12591294 boolean isProceed = edgeStatus == (isPurgeRequested ? DELETED : ACTIVE );
12601295
12611296 if (isProceed ) {
12621297 if (isRelationshipEdge (edge )) {
12631298 deleteRelationship (edge );
12641299 } else {
1265- AtlasVertex outVertex = edge .getOutVertex ();
1266-
12671300 if (!isDeletedEntity (outVertex )) {
1268- AtlasVertex inVertex = edge .getInVertex ();
1301+ AtlasVertex inVertex ;
1302+ try {
1303+ inVertex = edge .getInVertex ();
1304+ } catch (IllegalStateException e ) {
1305+ LOG .warn ("deleteVertex(): skipping edge {} - in-vertex was already removed" , edge .getIdForDisplay (), e );
1306+ continue ;
1307+ }
1308+
1309+ if (!inVertex .exists ()) {
1310+ LOG .debug ("deleteVertex(): skipping edge {} - in-vertex {} already removed in this transaction" , edge .getIdForDisplay (), inVertex .getIdForDisplay ());
1311+ continue ;
1312+ }
1313+
12691314 AtlasAttribute attribute = getAttributeForEdge (edge .getLabel ());
12701315
12711316 deleteEdgeBetweenVertices (outVertex , inVertex , attribute );
@@ -1347,7 +1392,20 @@ private String getDelimitedPropagatedClassificationNames(AtlasVertex entityVerte
13471392 * @throws AtlasBaseException
13481393 */
13491394 private void deleteAllClassifications (AtlasVertex instanceVertex ) throws AtlasBaseException {
1350- List <AtlasEdge > classificationEdges = getAllClassificationEdges (instanceVertex );
1395+ if (instanceVertex == null || !instanceVertex .exists ()) {
1396+ LOG .warn ("deleteAllClassifications(): skipping vertex - already removed" );
1397+ return ;
1398+ }
1399+
1400+ List <AtlasEdge > classificationEdges ;
1401+
1402+ try {
1403+ classificationEdges = getAllClassificationEdges (instanceVertex );
1404+ } catch (IllegalStateException e ) {
1405+ LOG .warn ("deleteAllClassifications(): skipping vertex - already removed" , e );
1406+ return ;
1407+ }
1408+
13511409 boolean isImportInProgress = RequestContext .get ().isImportInProgress ();
13521410
13531411 for (AtlasEdge edge : classificationEdges ) {
0 commit comments