From 08a88878636d3202139cfd458e128b9c97a6fbda Mon Sep 17 00:00:00 2001 From: Hitesh Khandelwal Date: Mon, 1 Jul 2024 12:39:39 +0530 Subject: [PATCH 1/3] Added metric Recorder for delete operations --- .../atlas/repository/graph/GraphHelper.java | 4 +++- .../store/graph/v1/DeleteHandlerV1.java | 23 +++++++++---------- .../store/graph/v1/SoftDeleteHandlerV1.java | 4 +++- .../store/graph/v2/AtlasEntityStoreV2.java | 15 ++++++------ 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index 179d915df9..d45ce31764 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -56,6 +56,7 @@ import org.apache.atlas.exception.EntityNotFoundException; import org.apache.atlas.util.AttributeValueMap; import org.apache.atlas.util.IndexedInstance; +import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.IteratorUtils; import org.apache.commons.lang.StringUtils; @@ -857,6 +858,7 @@ public static List getTraitNames(AtlasVertex entityVertex, Boolean propa } public static List getPropagatableClassifications(AtlasEdge edge) { + MetricRecorder metric = RequestContext.get().startMetricRecord("getPropagatableClassifications"); List ret = new ArrayList<>(); RequestContext requestContext = RequestContext.get(); @@ -875,7 +877,7 @@ public static List getPropagatableClassifications(AtlasEdge edge) { ret.addAll(getPropagationEnabledClassificationVertices(inVertex)); } } - + RequestContext.get().endMetricRecord(metric); return ret; } //Returns the vertex from which the tag is being propagated diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index a4358e2967..3bb653a1bf 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -53,6 +53,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection; import org.apache.atlas.utils.AtlasEntityUtil; import org.apache.atlas.utils.AtlasPerfMetrics; +import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; @@ -118,37 +119,31 @@ public DeleteHandlerV1(AtlasGraph graph, AtlasTypeRegistry typeRegistry, boolean * @throws AtlasException */ public void deleteEntities(Collection instanceVertices) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEntities"); final RequestContext requestContext = RequestContext.get(); final Set deletionCandidateVertices = new HashSet<>(); - for (AtlasVertex instanceVertex : instanceVertices) { final String guid = AtlasGraphUtilsV2.getIdFromVertex(instanceVertex); - if (skipVertexForDelete(instanceVertex)) { if (LOG.isDebugEnabled()) { LOG.debug("Skipping deletion of entity={} as it is already deleted", guid); } continue; } - // Record all deletion candidate entities in RequestContext // and gather deletion candidate vertices. for (GraphHelper.VertexInfo vertexInfo : getOwnedVertices(instanceVertex)) { AtlasEntityHeader entityHeader = vertexInfo.getEntity(); - if (requestContext.isPurgeRequested()) { entityHeader.setClassifications(entityRetriever.getAllClassifications(vertexInfo.getVertex())); } - requestContext.recordEntityDelete(entityHeader); deletionCandidateVertices.add(vertexInfo.getVertex()); } } - // Delete traits and vertices. for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) { RequestContext.get().getDeletedEdgesIds().clear(); - deleteAllClassifications(deletionCandidateVertex); deleteTypeVertex(deletionCandidateVertex, isInternalType(deletionCandidateVertex)); @@ -160,6 +155,7 @@ public void deleteEntities(Collection instanceVertices) throws Atla } } } + RequestContext.get().endMetricRecord(metric); } /** @@ -779,6 +775,7 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, TypeCategory typeCat * @throws AtlasException */ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteTypeVertex"); if (LOG.isDebugEnabled()) { LOG.debug("Deleting {}, force={}", string(instanceVertex), force); } @@ -852,6 +849,7 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throw } deleteVertex(instanceVertex, force); + RequestContext.get().endMetricRecord(metric); } protected AtlasAttribute getAttributeForEdge(AtlasEdge edge) throws AtlasBaseException { @@ -881,6 +879,7 @@ protected AtlasAttribute getAttributeForEdge(AtlasEdge edge) throws AtlasBaseExc * @throws AtlasException */ protected void deleteEdgeBetweenVertices(AtlasVertex outVertex, AtlasVertex inVertex, AtlasAttribute attribute) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEdgeBetweenVertices"); if (LOG.isDebugEnabled()) { LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), attribute.getName()); } @@ -988,13 +987,14 @@ protected void deleteEdgeBetweenVertices(AtlasVertex outVertex, AtlasVertex inVe requestContext.recordEntityUpdate(entityRetriever.toAtlasEntityHeader(outVertex)); } } + RequestContext.get().endMetricRecord(metric); } protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteVertex"); if (LOG.isDebugEnabled()) { LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex)); } - // Delete external references to this vertex - incoming edges from lineage or glossary term edges final Iterable incomingEdges = instanceVertex.getEdges(AtlasEdgeDirection.IN); final Iterable outgoingEdges = instanceVertex.getEdges(AtlasEdgeDirection.OUT); @@ -1006,11 +1006,9 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At AtlasRelationshipStoreV2.recordRelationshipMutation(AtlasRelationshipStoreV2.RelationshipMutation.RELATIONSHIP_HARD_DELETE, edge, entityRetriever); } } - for (AtlasEdge edge : incomingEdges) { AtlasEntity.Status edgeStatus = getStatus(edge); boolean isProceed = edgeStatus == (isPurgeRequested ? DELETED : ACTIVE); - if (isProceed) { if (isRelationshipEdge(edge)) { deleteRelationship(edge); @@ -1020,14 +1018,13 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At if (!isDeletedEntity(outVertex)) { AtlasVertex inVertex = edge.getInVertex(); AtlasAttribute attribute = getAttributeForEdge(edge); - deleteEdgeBetweenVertices(outVertex, inVertex, attribute); } } } } - _deleteVertex(instanceVertex, force); + RequestContext.get().endMetricRecord(metric); } private boolean isDeletedEntity(AtlasVertex entityVertex) { @@ -1106,6 +1103,7 @@ private String getDelimitedPropagatedClassificationNames(AtlasVertex entityVerte * @throws AtlasException */ private void deleteAllClassifications(AtlasVertex instanceVertex) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteAllClassifications"); // If instance is deleted no need to operate classification deleted if (!ACTIVE.equals(getState(instanceVertex))) return; @@ -1127,6 +1125,7 @@ private void deleteAllClassifications(AtlasVertex instanceVertex) throws AtlasBa deleteEdgeReference(edge, CLASSIFICATION, false, false, instanceVertex); } + RequestContext.get().endMetricRecord(metric); } private boolean skipVertexForDelete(AtlasVertex vertex) { diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java index ed103e2402..af1e5a3873 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java @@ -30,6 +30,7 @@ import org.apache.atlas.repository.store.graph.v2.AtlasRelationshipStoreV2; import org.apache.atlas.tasks.TaskManagement; import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder; import org.apache.commons.collections.CollectionUtils; import javax.inject.Inject; @@ -68,6 +69,7 @@ protected void _deleteVertex(AtlasVertex instanceVertex, boolean force) { @Override protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEdge"); try { if (LOG.isDebugEnabled()) { LOG.debug("==> SoftDeleteHandlerV1.deleteEdge({}, {})", GraphHelper.string(edge), force); @@ -104,6 +106,6 @@ protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseExcepti LOG.error("Error while deleting edge {}", GraphHelper.string(edge), e); throw new AtlasBaseException(e); } - + RequestContext.get().endMetricRecord(metric); } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 83df0fe2ef..1e1ef81560 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -582,13 +582,13 @@ public EntityMutationResponse updateEntityAttributeByGuid(String guid, String at @Override @GraphTransaction public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException { + AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("deleteById"); if (StringUtils.isEmpty(guid)) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid); } Collection deletionCandidates = new ArrayList<>(); AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(graph, guid); - if (vertex != null) { AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex); @@ -602,15 +602,13 @@ public EntityMutationResponse deleteById(final String guid) throws AtlasBaseExce LOG.debug("Deletion request ignored for non-existent entity with guid " + guid); } } - EntityMutationResponse ret = deleteVertices(deletionCandidates); - if(ret.getDeletedEntities()!=null) processTermEntityDeletion(ret.getDeletedEntities()); - // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); atlasRelationshipStore.onRelationshipsMutated(RequestContext.get().getRelationshipMutationMap()); + RequestContext.get().endMetricRecord(metricRecorder); return ret; } @@ -773,6 +771,7 @@ public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityTyp @Override @GraphTransaction public EntityMutationResponse deleteByUniqueAttributes(List objectIds) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteByUniqueAttributes"); if (CollectionUtils.isEmpty(objectIds)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS); } @@ -820,7 +819,7 @@ public EntityMutationResponse deleteByUniqueAttributes(List objec // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); atlasRelationshipStore.onRelationshipsMutated(RequestContext.get().getRelationshipMutationMap()); - + RequestContext.get().endMetricRecord(metric); } catch (Exception e) { LOG.error("Failed to delete objects:{}", objectIds.stream().map(AtlasObjectId::getUniqueAttributes).collect(Collectors.toList()), e); throw new AtlasBaseException(e); @@ -1931,7 +1930,7 @@ private EntityMutationResponse deleteVertices(Collection deletionCa Collection categories = new ArrayList<>(); Collection others = new ArrayList<>(); - MetricRecorder metric = RequestContext.get().startMetricRecord("filterCategoryVertices"); + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteVertices_filterCategoryVertices"); for (AtlasVertex vertex : deletionCandidates) { String typeName = getTypeName(vertex); @@ -1947,7 +1946,7 @@ private EntityMutationResponse deleteVertices(Collection deletionCa } } RequestContext.get().endMetricRecord(metric); - + MetricRecorder metric2 = RequestContext.get().startMetricRecord("deleteVertices"); // todo change name if (CollectionUtils.isNotEmpty(categories)) { entityGraphMapper.removeAttrForCategoryDelete(categories); deleteDelegate.getHandler(DeleteType.HARD).deleteEntities(categories); @@ -1976,11 +1975,11 @@ private EntityMutationResponse deleteVertices(Collection deletionCa for (AtlasEntityHeader entity : req.getUpdatedEntities()) { response.addEntity(UPDATE, entity); } + RequestContext.get().endMetricRecord(metric2); } catch (Exception e) { LOG.error("Delete vertices request failed", e); throw new AtlasBaseException(e); } - return response; } From f6d9bd5607b04d0dd4fe383093b5fa6d4ceb3605 Mon Sep 17 00:00:00 2001 From: Hitesh Khandelwal Date: Mon, 1 Jul 2024 14:14:39 +0530 Subject: [PATCH 2/3] Added finally --- .../store/graph/v1/DeleteHandlerV1.java | 21 +++++++++++++++---- .../store/graph/v1/SoftDeleteHandlerV1.java | 3 ++- .../store/graph/v2/AtlasEntityStoreV2.java | 12 ++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 3bb653a1bf..536c6d1828 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -122,28 +122,35 @@ public void deleteEntities(Collection instanceVertices) throws Atla MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEntities"); final RequestContext requestContext = RequestContext.get(); final Set deletionCandidateVertices = new HashSet<>(); + for (AtlasVertex instanceVertex : instanceVertices) { final String guid = AtlasGraphUtilsV2.getIdFromVertex(instanceVertex); + if (skipVertexForDelete(instanceVertex)) { if (LOG.isDebugEnabled()) { LOG.debug("Skipping deletion of entity={} as it is already deleted", guid); } continue; } + // Record all deletion candidate entities in RequestContext // and gather deletion candidate vertices. for (GraphHelper.VertexInfo vertexInfo : getOwnedVertices(instanceVertex)) { AtlasEntityHeader entityHeader = vertexInfo.getEntity(); + if (requestContext.isPurgeRequested()) { entityHeader.setClassifications(entityRetriever.getAllClassifications(vertexInfo.getVertex())); } + requestContext.recordEntityDelete(entityHeader); deletionCandidateVertices.add(vertexInfo.getVertex()); } } + // Delete traits and vertices. for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) { RequestContext.get().getDeletedEdgesIds().clear(); + deleteAllClassifications(deletionCandidateVertex); deleteTypeVertex(deletionCandidateVertex, isInternalType(deletionCandidateVertex)); @@ -750,6 +757,7 @@ protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolea } protected void deleteTypeVertex(AtlasVertex instanceVertex, TypeCategory typeCategory, boolean force) throws AtlasBaseException { + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteTypeVertex"); switch (typeCategory) { case STRUCT: deleteTypeVertex(instanceVertex, force); @@ -767,6 +775,7 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, TypeCategory typeCat default: throw new IllegalStateException("Type category " + typeCategory + " not handled"); } + RequestContext.get().endMetricRecord(metric); } /** @@ -879,7 +888,6 @@ protected AtlasAttribute getAttributeForEdge(AtlasEdge edge) throws AtlasBaseExc * @throws AtlasException */ protected void deleteEdgeBetweenVertices(AtlasVertex outVertex, AtlasVertex inVertex, AtlasAttribute attribute) throws AtlasBaseException { - MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEdgeBetweenVertices"); if (LOG.isDebugEnabled()) { LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), attribute.getName()); } @@ -887,6 +895,7 @@ protected void deleteEdgeBetweenVertices(AtlasVertex outVertex, AtlasVertex inVe if (skipVertexForDelete(outVertex)) { return; } + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteEdgeBetweenVertices"); AtlasStructType parentType = (AtlasStructType) typeRegistry.getType(GraphHelper.getTypeName(outVertex)); String propertyName = getQualifiedAttributePropertyKey(parentType, attribute.getName()); @@ -995,6 +1004,7 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At if (LOG.isDebugEnabled()) { LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex)); } + // Delete external references to this vertex - incoming edges from lineage or glossary term edges final Iterable incomingEdges = instanceVertex.getEdges(AtlasEdgeDirection.IN); final Iterable outgoingEdges = instanceVertex.getEdges(AtlasEdgeDirection.OUT); @@ -1006,9 +1016,11 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At AtlasRelationshipStoreV2.recordRelationshipMutation(AtlasRelationshipStoreV2.RelationshipMutation.RELATIONSHIP_HARD_DELETE, edge, entityRetriever); } } + for (AtlasEdge edge : incomingEdges) { AtlasEntity.Status edgeStatus = getStatus(edge); boolean isProceed = edgeStatus == (isPurgeRequested ? DELETED : ACTIVE); + if (isProceed) { if (isRelationshipEdge(edge)) { deleteRelationship(edge); @@ -1023,6 +1035,7 @@ protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws At } } } + _deleteVertex(instanceVertex, force); RequestContext.get().endMetricRecord(metric); } @@ -1103,11 +1116,11 @@ private String getDelimitedPropagatedClassificationNames(AtlasVertex entityVerte * @throws AtlasException */ private void deleteAllClassifications(AtlasVertex instanceVertex) throws AtlasBaseException { - MetricRecorder metric = RequestContext.get().startMetricRecord("deleteAllClassifications"); // If instance is deleted no need to operate classification deleted if (!ACTIVE.equals(getState(instanceVertex))) return; + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteAllClassifications"); List classificationEdges = getAllClassificationEdges(instanceVertex); for (AtlasEdge edge : classificationEdges) { @@ -1335,7 +1348,7 @@ public void createAndQueueTask(String taskType, AtlasEdge relationshipEdge, Atla } public void createAndQueueClassificationRefreshPropagationTask(AtlasEdge edge) throws AtlasBaseException{ - + MetricRecorder metric = RequestContext.get().startMetricRecord("createAndQueueClassificationRefreshPropagationTask"); if (taskManagement==null) { LOG.warn("Task management is null, can't schedule task now"); return; @@ -1376,7 +1389,7 @@ public void createAndQueueClassificationRefreshPropagationTask(AtlasEdge edge) t RequestContext.get().queueTask(task); } - + RequestContext.get().endMetricRecord(metric); } private boolean skipClassificationTaskCreation(String classificationId) throws AtlasBaseException { diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java index af1e5a3873..18cdf30949 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java @@ -105,7 +105,8 @@ protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseExcepti } catch (Exception e) { LOG.error("Error while deleting edge {}", GraphHelper.string(edge), e); throw new AtlasBaseException(e); + } finally { + RequestContext.get().endMetricRecord(metric); } - RequestContext.get().endMetricRecord(metric); } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 1e1ef81560..a3a0f70016 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -589,6 +589,7 @@ public EntityMutationResponse deleteById(final String guid) throws AtlasBaseExce Collection deletionCandidates = new ArrayList<>(); AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(graph, guid); + if (vertex != null) { AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex); @@ -602,9 +603,12 @@ public EntityMutationResponse deleteById(final String guid) throws AtlasBaseExce LOG.debug("Deletion request ignored for non-existent entity with guid " + guid); } } + EntityMutationResponse ret = deleteVertices(deletionCandidates); + if(ret.getDeletedEntities()!=null) processTermEntityDeletion(ret.getDeletedEntities()); + // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); atlasRelationshipStore.onRelationshipsMutated(RequestContext.get().getRelationshipMutationMap()); @@ -771,11 +775,12 @@ public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityTyp @Override @GraphTransaction public EntityMutationResponse deleteByUniqueAttributes(List objectIds) throws AtlasBaseException { - MetricRecorder metric = RequestContext.get().startMetricRecord("deleteByUniqueAttributes"); + if (CollectionUtils.isEmpty(objectIds)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS); } + MetricRecorder metric = RequestContext.get().startMetricRecord("deleteByUniqueAttributes"); EntityMutationResponse ret = new EntityMutationResponse(); Collection deletionCandidates = new ArrayList<>(); try { @@ -819,10 +824,11 @@ public EntityMutationResponse deleteByUniqueAttributes(List objec // Notify the change listeners entityChangeNotifier.onEntitiesMutated(ret, false); atlasRelationshipStore.onRelationshipsMutated(RequestContext.get().getRelationshipMutationMap()); - RequestContext.get().endMetricRecord(metric); } catch (Exception e) { LOG.error("Failed to delete objects:{}", objectIds.stream().map(AtlasObjectId::getUniqueAttributes).collect(Collectors.toList()), e); throw new AtlasBaseException(e); + } finally { + RequestContext.get().endMetricRecord(metric); } return ret; } @@ -1946,7 +1952,7 @@ private EntityMutationResponse deleteVertices(Collection deletionCa } } RequestContext.get().endMetricRecord(metric); - MetricRecorder metric2 = RequestContext.get().startMetricRecord("deleteVertices"); // todo change name + MetricRecorder metric2 = RequestContext.get().startMetricRecord("deleteVertices"); if (CollectionUtils.isNotEmpty(categories)) { entityGraphMapper.removeAttrForCategoryDelete(categories); deleteDelegate.getHandler(DeleteType.HARD).deleteEntities(categories); From eefb18759e78612104da285d2db032399e99fe89 Mon Sep 17 00:00:00 2001 From: Hitesh Khandelwal Date: Mon, 1 Jul 2024 14:19:51 +0530 Subject: [PATCH 3/3] fix --- .../atlas/repository/store/graph/v1/DeleteHandlerV1.java | 3 ++- .../atlas/repository/store/graph/v2/AtlasEntityStoreV2.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 536c6d1828..bf0fb2f8af 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -1348,12 +1348,13 @@ public void createAndQueueTask(String taskType, AtlasEdge relationshipEdge, Atla } public void createAndQueueClassificationRefreshPropagationTask(AtlasEdge edge) throws AtlasBaseException{ - MetricRecorder metric = RequestContext.get().startMetricRecord("createAndQueueClassificationRefreshPropagationTask"); if (taskManagement==null) { LOG.warn("Task management is null, can't schedule task now"); return; } + MetricRecorder metric = RequestContext.get().startMetricRecord("createAndQueueClassificationRefreshPropagationTask"); + String currentUser = RequestContext.getCurrentUser(); boolean isRelationshipEdge = isRelationshipEdge(edge); boolean isTermEntityEdge = GraphHelper.isTermEntityEdge(edge); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index a3a0f70016..974bff8baf 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -582,11 +582,12 @@ public EntityMutationResponse updateEntityAttributeByGuid(String guid, String at @Override @GraphTransaction public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException { - AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("deleteById"); if (StringUtils.isEmpty(guid)) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid); } + AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("deleteById"); + Collection deletionCandidates = new ArrayList<>(); AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(graph, guid);