Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved all the calculated vertices to task and refactored the code. Al… #3603

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3993,14 +3993,12 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
String entityTypeName = AtlasGraphUtilsV2.getTypeName(entityVertex);
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
List<AtlasClassification> updatedClassifications = new ArrayList<>();
HashMap<String, String> updatedClassificationsVertices = new HashMap<>();
List<AtlasVertex> entitiesToPropagateTo = new ArrayList<>();
Set<AtlasVertex> notificationVertices = new HashSet<AtlasVertex>() {{ add(entityVertex); }};

Map<AtlasVertex, List<AtlasClassification>> addedPropagations = null;
Map<AtlasClassification, List<AtlasVertex>> removedPropagations = new HashMap<>();
String propagationType = null;
Queue<StaggeredTask> tasksToBeCreated = new LinkedList<>();

for (AtlasClassification classification : classifications) {
MetricRecorder metricRecorderClassification = RequestContext.get().startMetricRecord("updateClassifications_classification");
Expand Down Expand Up @@ -4071,10 +4069,7 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
}

if (isClassificationUpdated) {
List<AtlasVertex> propagatedEntityVertices = graphHelper.getAllPropagatedEntityVertices(classificationVertex);

notificationVertices.addAll(propagatedEntityVertices);
updatedClassificationsVertices.put(classificationName, classificationVertex.getIdForDisplay());
createAndQueueTask(CLASSIFICATION_PROPAGATION_TEXT_UPDATE, entityVertex, classificationVertex.getIdForDisplay(), classification.getTypeName());
}

if (LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -4130,8 +4125,8 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
if (removePropagation || !updatedTagPropagation) {
propagationType = CLASSIFICATION_PROPAGATION_DELETE;
}
tasksToBeCreated.add(new StaggeredTask(propagationType, entityVertex, classificationVertex.getIdForDisplay(), classificationName, currentRestrictPropagationThroughLineage,currentRestrictPropagationThroughHierarchy));
updatedTagPropagation = null;
createAndQueueTask(propagationType, entityVertex, classificationVertex.getIdForDisplay(), classificationName, currentRestrictPropagationThroughLineage,currentRestrictPropagationThroughHierarchy);
updatedTagPropagation = null;
}

// compute propagatedEntityVertices once and use it for subsequent iterations and notifications
Expand Down Expand Up @@ -4203,16 +4198,10 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
AtlasEntity entity = instanceConverter.getAndCacheEntity(entityGuid, ENTITY_CHANGE_NOTIFY_IGNORE_RELATIONSHIP_ATTRIBUTES);

if (entity != null) {
vertex.setProperty(CLASSIFICATION_TEXT_KEY, fullTextMapperV2.getClassificationTextForEntity(entity));
entityChangeNotifier.onClassificationUpdatedToEntity(entity, updatedClassifications);
}
RequestContext.get().endMetricRecord(metricRecorderEntity);}
for(String classification : updatedClassificationsVertices.keySet()){
createAndQueueTask(CLASSIFICATION_PROPAGATION_TEXT_UPDATE, entityVertex, updatedClassificationsVertices.get(classification), classification);
}
while (!tasksToBeCreated.isEmpty()){
StaggeredTask task = tasksToBeCreated.poll();
createAndQueueTask(task.taskType, task.entityVertex, task.classificationVertexId, task.classificationName, task.currentPropagateThroughLineage, task.currentRestrictPropagationThroughHierarchy);
}

if (MapUtils.isNotEmpty(removedPropagations)) {
AtlasPerfMetrics.MetricRecorder metricRecorderEntity = RequestContext.get().startMetricRecord("updateClassifications_removeProp");
Expand Down Expand Up @@ -4300,6 +4289,7 @@ public void updateClassificationTextPropagation(String classificationVertexId) {
}

AtlasVertex classificationVertex = graph.getVertex(classificationVertexId);
AtlasClassification classification = entityRetriever.toAtlasClassification(classificationVertex);
List<AtlasVertex> impactedVertices = graphHelper.getAllPropagatedEntityVertices(classificationVertex);
int batchSize = 100;
for (int i = 0; i < impactedVertices.size(); i += batchSize) {
Expand All @@ -4311,6 +4301,7 @@ public void updateClassificationTextPropagation(String classificationVertexId) {

if (entity != null) {
vertex.setProperty(CLASSIFICATION_TEXT_KEY, fullTextMapperV2.getClassificationTextForEntity(entity));
entityChangeNotifier.onClassificationUpdatedToEntity(entity, Collections.singletonList(classification));
}
}
transactionInterceptHelper.intercept();
Expand Down Expand Up @@ -5222,22 +5213,4 @@ private void isAuthorizedToLink(AtlasVertex vertex) throws AtlasBaseException {
"read on source Entity, link/unlink operation denied: ", sourceEntity.getAttribute(NAME));

}

class StaggeredTask {
String taskType;
AtlasVertex entityVertex;
String classificationVertexId;
String classificationName;
Boolean currentPropagateThroughLineage;
Boolean currentRestrictPropagationThroughHierarchy;

public StaggeredTask(String taskType, AtlasVertex entityVertex, String classificationVertexId, String classificationName, Boolean currentPropagateThroughLineage, Boolean currentRestrictPropagationThroughHierarchy) {
this.taskType = taskType;
this.entityVertex = entityVertex;
this.classificationVertexId = classificationVertexId;
this.classificationName = classificationName;
this.currentPropagateThroughLineage = currentPropagateThroughLineage;
this.currentRestrictPropagationThroughHierarchy = currentRestrictPropagationThroughHierarchy;
}
}
}
Loading