/**
   * Deletes the specified entity vertices. Deletes any traits, composite entities, and structs
   * owned by each entity. Also deletes all the references from/to the entity.
   *
   * @param instanceVertices
   * @throws AtlasException
   */
  public void deleteEntities(List<AtlasVertex> instanceVertices) throws AtlasException {
    RequestContext requestContext = RequestContext.get();

    Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();

    for (AtlasVertex instanceVertex : instanceVertices) {
      String guid = GraphHelper.getIdFromVertex(instanceVertex);
      Id.EntityState state = GraphHelper.getState(instanceVertex);
      if (requestContext.getDeletedEntityIds().contains(guid) || state == Id.EntityState.DELETED) {
        LOG.debug("Skipping deletion of {} as it is already deleted", guid);
        continue;
      }

      // Get GUIDs and vertices for all deletion candidates.
      Set<VertexInfo> compositeVertices = graphHelper.getCompositeVertices(instanceVertex);

      // Record all deletion candidate GUIDs in RequestContext
      // and gather deletion candidate vertices.
      for (VertexInfo vertexInfo : compositeVertices) {
        requestContext.recordEntityDelete(vertexInfo.getGuid(), vertexInfo.getTypeName());
        deletionCandidateVertices.add(vertexInfo.getVertex());
      }
    }

    // Delete traits and vertices.
    for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) {
      deleteAllTraits(deletionCandidateVertex);
      deleteTypeVertex(deletionCandidateVertex, false);
    }
  }