Commit 59648d28 by Madhan Neethiraj

ATLAS-3279: avoid unncessary retrieval of entity-extended info while sending notifications

Change-Id: I82e0bba27010709c74cd98a93f8a9c617577535e
parent 9062e2c8
...@@ -271,11 +271,11 @@ public class FullTextMapperV2 { ...@@ -271,11 +271,11 @@ public class FullTextMapperV2 {
} }
} }
private AtlasEntity getAndCacheEntity(String guid) throws AtlasBaseException { public AtlasEntity getAndCacheEntity(String guid) throws AtlasBaseException {
return getAndCacheEntity(guid, true); return getAndCacheEntity(guid, true);
} }
private AtlasEntity getAndCacheEntity(String guid, boolean includeReferences) throws AtlasBaseException { public AtlasEntity getAndCacheEntity(String guid, boolean includeReferences) throws AtlasBaseException {
RequestContext context = RequestContext.get(); RequestContext context = RequestContext.get();
AtlasEntity entity = context.getEntity(guid); AtlasEntity entity = context.getEntity(guid);
...@@ -294,7 +294,7 @@ public class FullTextMapperV2 { ...@@ -294,7 +294,7 @@ public class FullTextMapperV2 {
return entity; return entity;
} }
private AtlasEntityWithExtInfo getAndCacheEntityWithExtInfo(String guid) throws AtlasBaseException { public AtlasEntityWithExtInfo getAndCacheEntityWithExtInfo(String guid) throws AtlasBaseException {
RequestContext context = RequestContext.get(); RequestContext context = RequestContext.get();
AtlasEntityWithExtInfo entityWithExtInfo = context.getEntityWithExtInfo(guid); AtlasEntityWithExtInfo entityWithExtInfo = context.getEntityWithExtInfo(guid);
......
...@@ -92,7 +92,7 @@ public class AtlasEntityChangeNotifier { ...@@ -92,7 +92,7 @@ public class AtlasEntityChangeNotifier {
} }
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException { public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException {
if (CollectionUtils.isEmpty(entityChangeListeners) || instanceConverter == null) { if (CollectionUtils.isEmpty(entityChangeListeners)) {
return; return;
} }
...@@ -118,7 +118,7 @@ public class AtlasEntityChangeNotifier { ...@@ -118,7 +118,7 @@ public class AtlasEntityChangeNotifier {
} }
public void notifyRelationshipMutation(AtlasRelationship relationship, EntityNotification.EntityNotificationV2.OperationType operationType) throws AtlasBaseException { public void notifyRelationshipMutation(AtlasRelationship relationship, EntityNotification.EntityNotificationV2.OperationType operationType) throws AtlasBaseException {
if (CollectionUtils.isEmpty(entityChangeListeners) || instanceConverter == null) { if (CollectionUtils.isEmpty(entityChangeListeners)) {
return; return;
} }
...@@ -145,6 +145,7 @@ public class AtlasEntityChangeNotifier { ...@@ -145,6 +145,7 @@ public class AtlasEntityChangeNotifier {
} else { } else {
updateFullTextMapping(entity.getGuid(), addedClassifications); updateFullTextMapping(entity.getGuid(), addedClassifications);
if (instanceConverter != null) {
Referenceable entityRef = toReferenceable(entity.getGuid()); Referenceable entityRef = toReferenceable(entity.getGuid());
List<Struct> traits = toStruct(addedClassifications); List<Struct> traits = toStruct(addedClassifications);
...@@ -161,17 +162,17 @@ public class AtlasEntityChangeNotifier { ...@@ -161,17 +162,17 @@ public class AtlasEntityChangeNotifier {
} }
} }
} }
}
public void onClassificationUpdatedToEntity(AtlasEntity entity, List<AtlasClassification> updatedClassifications) throws AtlasBaseException { public void onClassificationUpdatedToEntity(AtlasEntity entity, List<AtlasClassification> updatedClassifications) throws AtlasBaseException {
if (isV2EntityNotificationEnabled) {
doFullTextMapping(entity.getGuid()); doFullTextMapping(entity.getGuid());
if (isV2EntityNotificationEnabled) {
for (EntityChangeListenerV2 listener : entityChangeListenersV2) { for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
listener.onClassificationsUpdated(entity, updatedClassifications); listener.onClassificationsUpdated(entity, updatedClassifications);
} }
} else { } else {
doFullTextMapping(entity.getGuid()); if (instanceConverter != null) {
Referenceable entityRef = toReferenceable(entity.getGuid()); Referenceable entityRef = toReferenceable(entity.getGuid());
List<Struct> traits = toStruct(updatedClassifications); List<Struct> traits = toStruct(updatedClassifications);
...@@ -188,17 +189,17 @@ public class AtlasEntityChangeNotifier { ...@@ -188,17 +189,17 @@ public class AtlasEntityChangeNotifier {
} }
} }
} }
}
public void onClassificationDeletedFromEntity(AtlasEntity entity, List<AtlasClassification> deletedClassifications) throws AtlasBaseException { public void onClassificationDeletedFromEntity(AtlasEntity entity, List<AtlasClassification> deletedClassifications) throws AtlasBaseException {
if (isV2EntityNotificationEnabled) {
doFullTextMapping(entity.getGuid()); doFullTextMapping(entity.getGuid());
if (isV2EntityNotificationEnabled) {
for (EntityChangeListenerV2 listener : entityChangeListenersV2) { for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
listener.onClassificationsDeleted(entity, deletedClassifications); listener.onClassificationsDeleted(entity, deletedClassifications);
} }
} else { } else {
doFullTextMapping(entity.getGuid()); if (instanceConverter != null) {
Referenceable entityRef = toReferenceable(entity.getGuid()); Referenceable entityRef = toReferenceable(entity.getGuid());
List<Struct> traits = toStruct(deletedClassifications); List<Struct> traits = toStruct(deletedClassifications);
...@@ -213,7 +214,7 @@ public class AtlasEntityChangeNotifier { ...@@ -213,7 +214,7 @@ public class AtlasEntityChangeNotifier {
throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete"); throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete");
} }
} }
}
} }
} }
...@@ -223,7 +224,7 @@ public class AtlasEntityChangeNotifier { ...@@ -223,7 +224,7 @@ public class AtlasEntityChangeNotifier {
for (EntityChangeListenerV2 listener : entityChangeListenersV2) { for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
listener.onTermAdded(term, entityIds); listener.onTermAdded(term, entityIds);
} }
} else { } else if (instanceConverter != null) {
List<Referenceable> entityRefs = toReferenceables(entityIds); List<Referenceable> entityRefs = toReferenceables(entityIds);
for (EntityChangeListener listener : entityChangeListeners) { for (EntityChangeListener listener : entityChangeListeners) {
...@@ -242,7 +243,7 @@ public class AtlasEntityChangeNotifier { ...@@ -242,7 +243,7 @@ public class AtlasEntityChangeNotifier {
for (EntityChangeListenerV2 listener : entityChangeListenersV2) { for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
listener.onTermDeleted(term, entityIds); listener.onTermDeleted(term, entityIds);
} }
} else { } else if (instanceConverter != null) {
List<Referenceable> entityRefs = toReferenceables(entityIds); List<Referenceable> entityRefs = toReferenceables(entityIds);
for (EntityChangeListener listener : entityChangeListeners) { for (EntityChangeListener listener : entityChangeListeners) {
...@@ -277,7 +278,7 @@ public class AtlasEntityChangeNotifier { ...@@ -277,7 +278,7 @@ public class AtlasEntityChangeNotifier {
continue; continue;
} }
AtlasEntity entity = instanceConverter.getAndCacheEntity(guid); AtlasEntity entity = fullTextMapperV2.getAndCacheEntity(guid);
if (entity == null) { if (entity == null) {
continue; continue;
...@@ -300,11 +301,15 @@ public class AtlasEntityChangeNotifier { ...@@ -300,11 +301,15 @@ public class AtlasEntityChangeNotifier {
return; return;
} }
MetricRecorder metric = RequestContext.get().startMetricRecord("notifyListeners");
if (isV2EntityNotificationEnabled) { if (isV2EntityNotificationEnabled) {
notifyV2Listeners(entityHeaders, operation, isImport); notifyV2Listeners(entityHeaders, operation, isImport);
} else { } else {
notifyV1Listeners(entityHeaders, operation, isImport); notifyV1Listeners(entityHeaders, operation, isImport);
} }
RequestContext.get().endMetricRecord(metric);
} }
private void notifyRelationshipListeners(List<AtlasRelationship> relationships, EntityOperation operation, boolean isImport) throws AtlasBaseException { private void notifyRelationshipListeners(List<AtlasRelationship> relationships, EntityOperation operation, boolean isImport) throws AtlasBaseException {
...@@ -322,6 +327,7 @@ public class AtlasEntityChangeNotifier { ...@@ -322,6 +327,7 @@ public class AtlasEntityChangeNotifier {
private void notifyV1Listeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException { private void notifyV1Listeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException {
if (instanceConverter != null) {
List<Referenceable> typedRefInsts = toReferenceables(entityHeaders, operation); List<Referenceable> typedRefInsts = toReferenceables(entityHeaders, operation);
for (EntityChangeListener listener : entityChangeListeners) { for (EntityChangeListener listener : entityChangeListeners) {
...@@ -343,6 +349,7 @@ public class AtlasEntityChangeNotifier { ...@@ -343,6 +349,7 @@ public class AtlasEntityChangeNotifier {
} }
} }
} }
}
private void notifyV2Listeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException { private void notifyV2Listeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException {
List<AtlasEntity> entities = toAtlasEntities(entityHeaders, operation); List<AtlasEntity> entities = toAtlasEntities(entityHeaders, operation);
...@@ -386,6 +393,7 @@ public class AtlasEntityChangeNotifier { ...@@ -386,6 +393,7 @@ public class AtlasEntityChangeNotifier {
private List<Referenceable> toReferenceables(List<AtlasEntityHeader> entityHeaders, EntityOperation operation) throws AtlasBaseException { private List<Referenceable> toReferenceables(List<AtlasEntityHeader> entityHeaders, EntityOperation operation) throws AtlasBaseException {
List<Referenceable> ret = new ArrayList<>(entityHeaders.size()); List<Referenceable> ret = new ArrayList<>(entityHeaders.size());
if (instanceConverter != null) {
// delete notifications don't need all attributes. Hence the special handling for delete operation // delete notifications don't need all attributes. Hence the special handling for delete operation
if (operation == EntityOperation.DELETE) { if (operation == EntityOperation.DELETE) {
for (AtlasEntityHeader entityHeader : entityHeaders) { for (AtlasEntityHeader entityHeader : entityHeaders) {
...@@ -396,6 +404,7 @@ public class AtlasEntityChangeNotifier { ...@@ -396,6 +404,7 @@ public class AtlasEntityChangeNotifier {
ret.add(toReferenceable(entityHeader.getGuid())); ret.add(toReferenceable(entityHeader.getGuid()));
} }
} }
}
return ret; return ret;
} }
...@@ -403,7 +412,7 @@ public class AtlasEntityChangeNotifier { ...@@ -403,7 +412,7 @@ public class AtlasEntityChangeNotifier {
private List<Referenceable> toReferenceables(List<AtlasRelatedObjectId> entityIds) throws AtlasBaseException { private List<Referenceable> toReferenceables(List<AtlasRelatedObjectId> entityIds) throws AtlasBaseException {
List<Referenceable> ret = new ArrayList<>(); List<Referenceable> ret = new ArrayList<>();
if (CollectionUtils.isNotEmpty(entityIds)) { if (instanceConverter != null && CollectionUtils.isNotEmpty(entityIds)) {
for (AtlasRelatedObjectId relatedObjectId : entityIds) { for (AtlasRelatedObjectId relatedObjectId : entityIds) {
String entityGuid = relatedObjectId.getGuid(); String entityGuid = relatedObjectId.getGuid();
...@@ -417,7 +426,7 @@ public class AtlasEntityChangeNotifier { ...@@ -417,7 +426,7 @@ public class AtlasEntityChangeNotifier {
private Referenceable toReferenceable(String entityId) throws AtlasBaseException { private Referenceable toReferenceable(String entityId) throws AtlasBaseException {
Referenceable ret = null; Referenceable ret = null;
if (StringUtils.isNotEmpty(entityId)) { if (instanceConverter != null && StringUtils.isNotEmpty(entityId)) {
ret = instanceConverter.getReferenceable(entityId); ret = instanceConverter.getReferenceable(entityId);
} }
...@@ -427,7 +436,7 @@ public class AtlasEntityChangeNotifier { ...@@ -427,7 +436,7 @@ public class AtlasEntityChangeNotifier {
private List<Struct> toStruct(List<AtlasClassification> classifications) throws AtlasBaseException { private List<Struct> toStruct(List<AtlasClassification> classifications) throws AtlasBaseException {
List<Struct> ret = null; List<Struct> ret = null;
if (classifications != null) { if (instanceConverter != null && classifications != null) {
ret = new ArrayList<>(classifications.size()); ret = new ArrayList<>(classifications.size());
for (AtlasClassification classification : classifications) { for (AtlasClassification classification : classifications) {
...@@ -468,7 +477,7 @@ public class AtlasEntityChangeNotifier { ...@@ -468,7 +477,7 @@ public class AtlasEntityChangeNotifier {
} else { } else {
String entityGuid = entityHeader.getGuid(); String entityGuid = entityHeader.getGuid();
entity = instanceConverter.getAndCacheEntity(entityGuid); entity = fullTextMapperV2.getAndCacheEntity(entityGuid);
} }
if (entity != null) { if (entity != null) {
...@@ -545,6 +554,10 @@ public class AtlasEntityChangeNotifier { ...@@ -545,6 +554,10 @@ public class AtlasEntityChangeNotifier {
} }
private void doFullTextMapping(String guid) { private void doFullTextMapping(String guid) {
if(AtlasRepositoryConfiguration.isFreeTextSearchEnabled() || !AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
return;
}
AtlasEntityHeader entityHeader = new AtlasEntityHeader(); AtlasEntityHeader entityHeader = new AtlasEntityHeader();
entityHeader.setGuid(guid); entityHeader.setGuid(guid);
......
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