Commit 0e53c3ee by Sarath Subramanian

ATLAS-3778: Improve performance during classification delete

parent 1c07f93b
...@@ -111,6 +111,16 @@ public interface AtlasElement { ...@@ -111,6 +111,16 @@ public interface AtlasElement {
void removeProperty(String propertyName); void removeProperty(String propertyName);
/** /**
* Removes a property with given property value from the vertex.
*/
void removePropertyValue(String propertyName, Object propertyValue);
/**
* Removes a property with given property value from the vertex.
*/
void removeAllPropertyValue(String propertyName, Object propertyValue);
/**
* Sets a single-valued property to the given value. For * Sets a single-valued property to the given value. For
* properties defined as multiplicty many in the graph schema, the value is added instead * properties defined as multiplicty many in the graph schema, the value is added instead
* (following set semantics) * (following set semantics)
......
...@@ -22,6 +22,7 @@ import java.util.Collection; ...@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdge;
...@@ -107,6 +108,35 @@ public class AtlasJanusElement<T extends Element> implements AtlasElement { ...@@ -107,6 +108,35 @@ public class AtlasJanusElement<T extends Element> implements AtlasElement {
} }
@Override @Override
public void removePropertyValue(String propertyName, Object propertyValue) {
Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);
while (it.hasNext()) {
Property currentProperty = it.next();
Object currentPropertyValue = currentProperty.value();
if (Objects.equals(currentPropertyValue, propertyValue)) {
currentProperty.remove();
break;
}
}
}
@Override
public void removeAllPropertyValue(String propertyName, Object propertyValue) {
Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);
while (it.hasNext()) {
Property currentProperty = it.next();
Object currentPropertyValue = currentProperty.value();
if (Objects.equals(currentPropertyValue, propertyValue)) {
currentProperty.remove();
}
}
}
@Override
public void setProperty(String propertyName, Object value) { public void setProperty(String propertyName, Object value) {
try { try {
if (value == null) { if (value == null) {
......
...@@ -993,42 +993,39 @@ public abstract class DeleteHandlerV1 { ...@@ -993,42 +993,39 @@ public abstract class DeleteHandlerV1 {
} }
entityVertex.addListProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName); entityVertex.addListProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName);
String propClsNames = entityVertex.getProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, String.class); entityVertex.setProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, getDelimitedPropagatedClassificationNames(entityVertex, classificationName));
propClsNames = StringUtils.isEmpty(propClsNames) ? CLASSIFICATION_NAME_DELIMITER + classificationName
: (propClsNames + classificationName);
propClsNames = propClsNames + CLASSIFICATION_NAME_DELIMITER;
entityVertex.setProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, propClsNames);
} }
private void removeFromPropagatedClassificationNames(AtlasVertex entityVertex, String classificationName) { public void removeFromPropagatedClassificationNames(AtlasVertex entityVertex, String classificationName) {
if (entityVertex != null && StringUtils.isNotEmpty(classificationName)) { if (entityVertex != null && StringUtils.isNotEmpty(classificationName)) {
List<String> propagatedTraitNames = getTraitNames(entityVertex, true); if (LOG.isDebugEnabled()) {
LOG.debug("Removing from property: {} value: {} in vertex: {}", PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName, string(entityVertex));
}
entityVertex.removePropertyValue(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName);
List<String> propagatedTraitNames = getPropagatedTraitNames(entityVertex);
if (CollectionUtils.isNotEmpty(propagatedTraitNames)) {
propagatedTraitNames.remove(classificationName); propagatedTraitNames.remove(classificationName);
setPropagatedClassificationNames(entityVertex, propagatedTraitNames); String propClsName = CLASSIFICATION_NAME_DELIMITER + StringUtils.join(propagatedTraitNames, CLASSIFICATION_NAME_DELIMITER) + CLASSIFICATION_NAME_DELIMITER;
entityVertex.setProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, propClsName);
} }
} }
private void setPropagatedClassificationNames(AtlasVertex entityVertex, List<String> classificationNames) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding property {} = \"{}\" to vertex {}", PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationNames, string(entityVertex));
} }
entityVertex.removeProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY); private String getDelimitedPropagatedClassificationNames(AtlasVertex entityVertex, String classificationName) {
entityVertex.removeProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY); String ret = entityVertex.getProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, String.class);
if (CollectionUtils.isNotEmpty(classificationNames)) { if (StringUtils.isEmpty(ret)) {
for (String classificationName : classificationNames) { ret = CLASSIFICATION_NAME_DELIMITER + classificationName + CLASSIFICATION_NAME_DELIMITER;
entityVertex.addListProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName); } else {
ret = ret + classificationName + CLASSIFICATION_NAME_DELIMITER;
} }
String propClsName = CLASSIFICATION_NAME_DELIMITER + StringUtils.join(classificationNames, CLASSIFICATION_NAME_DELIMITER) + CLASSIFICATION_NAME_DELIMITER; return ret;
entityVertex.setProperty(PROPAGATED_CLASSIFICATION_NAMES_KEY, propClsName);
}
} }
/** /**
......
...@@ -2086,7 +2086,13 @@ public class EntityGraphMapper { ...@@ -2086,7 +2086,13 @@ public class EntityGraphMapper {
traitNames.remove(classificationName); traitNames.remove(classificationName);
setClassificationNames(entityVertex, traitNames); // update 'TRAIT_NAMES_PROPERTY_KEY' property
entityVertex.removePropertyValue(TRAIT_NAMES_PROPERTY_KEY, classificationName);
// update 'CLASSIFICATION_NAMES_KEY' property
entityVertex.removeProperty(CLASSIFICATION_NAMES_KEY);
entityVertex.setProperty(CLASSIFICATION_NAMES_KEY, getClassificationNamesString(traitNames));
updateModificationMetadata(entityVertex); updateModificationMetadata(entityVertex);
...@@ -2140,30 +2146,21 @@ public class EntityGraphMapper { ...@@ -2140,30 +2146,21 @@ public class EntityGraphMapper {
private void addToClassificationNames(AtlasVertex entityVertex, String classificationName) { private void addToClassificationNames(AtlasVertex entityVertex, String classificationName) {
AtlasGraphUtilsV2.addEncodedProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, classificationName); AtlasGraphUtilsV2.addEncodedProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, classificationName);
String clsNames = entityVertex.getProperty(CLASSIFICATION_NAMES_KEY, String.class); String delimitedClassificationNames = entityVertex.getProperty(CLASSIFICATION_NAMES_KEY, String.class);
clsNames = StringUtils.isEmpty(clsNames) ? CLASSIFICATION_NAME_DELIMITER + classificationName : clsNames + classificationName; if (StringUtils.isEmpty(delimitedClassificationNames)) {
delimitedClassificationNames = CLASSIFICATION_NAME_DELIMITER + classificationName + CLASSIFICATION_NAME_DELIMITER;
clsNames = clsNames + CLASSIFICATION_NAME_DELIMITER; } else {
delimitedClassificationNames = delimitedClassificationNames + classificationName + CLASSIFICATION_NAME_DELIMITER;
entityVertex.setProperty(CLASSIFICATION_NAMES_KEY, clsNames);
} }
private void setClassificationNames(AtlasVertex entityVertex, List<String> traitNames) { entityVertex.setProperty(CLASSIFICATION_NAMES_KEY, delimitedClassificationNames);
if (entityVertex != null) {
entityVertex.removeProperty(TRAIT_NAMES_PROPERTY_KEY);
entityVertex.removeProperty(CLASSIFICATION_NAMES_KEY);
for (String traitName : traitNames) {
AtlasGraphUtilsV2.addEncodedProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, traitName);
} }
String clsNames = StringUtils.join(traitNames, CLASSIFICATION_NAME_DELIMITER); private String getClassificationNamesString(List<String> traitNames) {
String ret = StringUtils.join(traitNames, CLASSIFICATION_NAME_DELIMITER);
clsNames = StringUtils.isEmpty(clsNames) ? clsNames : CLASSIFICATION_NAME_DELIMITER + clsNames + CLASSIFICATION_NAME_DELIMITER; return StringUtils.isEmpty(ret) ? ret : CLASSIFICATION_NAME_DELIMITER + ret + CLASSIFICATION_NAME_DELIMITER;
entityVertex.setProperty(CLASSIFICATION_NAMES_KEY, clsNames);
}
} }
public void updateClassifications(EntityMutationContext context, String guid, List<AtlasClassification> classifications) throws AtlasBaseException { public void updateClassifications(EntityMutationContext context, String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
......
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