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

MLH-73 | Cassandra optimisation. Optimise edgeLabel fetching only to root level vertices #4352

Merged
merged 14 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ on:
- development
- master
- lineageondemand
- cassandrapoliciesoptimisation

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum AtlasConfiguration {
ATLAS_INDEXSEARCH_LIMIT_UTM_TAGS("atlas.indexsearch.limit.ignore.utm.tags", ""),
ATLAS_INDEXSEARCH_ENABLE_API_LIMIT("atlas.indexsearch.enable.api.limit", false),
ATLAS_INDEXSEARCH_ENABLE_JANUS_OPTIMISATION("atlas.indexsearch.enable.janus.optimization", false),
ATLAS_INDEXSEARCH_ENABLE_JANUS_OPTIMISATION_FOR_RELATIONS("atlas.indexsearch.enable.janus.optimization.for.relationship", false),
ATLAS_MAINTENANCE_MODE("atlas.maintenance.mode", false),
DELTA_BASED_REFRESH_ENABLED("atlas.authorizer.enable.delta_based_refresh", false),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2065,30 +2065,6 @@ private static Set<String> parseLabelsString(String labels) {

return ret;
}

/**
* Get all the active edges
* @param vertex entity vertex
* @return Iterator of children edges
*/
public static Iterator<AtlasJanusEdge> getOnlyActiveEdges(AtlasVertex vertex, AtlasEdgeDirection direction) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("GraphHelper.getOnlyActiveEdges");

try {
return vertex.query()
.direction(direction)
.has(STATE_PROPERTY_KEY, ACTIVE_STATE_VALUE)
.edges()
.iterator();
} catch (Exception e) {
LOG.error("Error while getting active edges of vertex", e);
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
finally {
RequestContext.get().endMetricRecord(metricRecorder);
}
}

public Set<AbstractMap.SimpleEntry<String,String>> retrieveEdgeLabelsAndTypeName(AtlasVertex vertex) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("GraphHelper.retrieveEdgeLabelsAndTypeName");

Expand All @@ -2109,7 +2085,7 @@ public Set<AbstractMap.SimpleEntry<String,String>> retrieveEdgeLabelsAndTypeName

return new AbstractMap.SimpleEntry<>(labelStr, typeNameStr);
})
.filter(entry -> !entry.getKey().isEmpty() && !entry.getValue().isEmpty())
.filter(entry -> !entry.getKey().isEmpty())
.distinct()
.collect(Collectors.toSet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,14 @@ public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseE
AtlasObjectId ret = null;
String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

boolean enableJanusOptimisation = AtlasConfiguration.ATLAS_INDEXSEARCH_ENABLE_JANUS_OPTIMISATION_FOR_RELATIONS.getBoolean();
Map<String, Object> referenceVertexProperties = null;
if (entityType != null) {
Map<String, Object> uniqueAttributes = new HashMap<>();

Set<String> relationAttributes = RequestContext.get().getRelationAttrsForSearch();
if (enableJanusOptimisation) {
referenceVertexProperties = preloadProperties(entityVertex, entityType, relationAttributes);
}
for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) {
Object attrValue = getVertexAttribute(entityVertex, attribute);

Expand All @@ -298,13 +302,18 @@ public AtlasObjectId toAtlasObjectId(AtlasVertex entityVertex) throws AtlasBaseE
}

Map<String, Object> attributes = new HashMap<>();
Set<String> relationAttributes = RequestContext.get().getRelationAttrsForSearch();
if (CollectionUtils.isNotEmpty(relationAttributes)) {
for (String attributeName : relationAttributes) {
AtlasAttribute attribute = entityType.getAttribute(attributeName);
if (attribute != null
&& !uniqueAttributes.containsKey(attributeName)) {
Object attrValue = getVertexAttribute(entityVertex, attribute);
Object attrValue = null;
if (enableJanusOptimisation) {
attrValue = getVertexAttributePreFetchCache(entityVertex, attribute, referenceVertexProperties);
} else {
attrValue = getVertexAttribute(entityVertex, attribute);
}

if (attrValue != null) {
attributes.put(attribute.getName(), attrValue);
}
Expand Down Expand Up @@ -1132,12 +1141,25 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex,
&& typeName.equals("S3Bucket");

boolean shouldPrefetch = RequestContext.get().isInvokedByIndexSearch()
&& !isPolicyAttribute(attributes)
&& !isS3Bucket
&& AtlasConfiguration.ATLAS_INDEXSEARCH_ENABLE_JANUS_OPTIMISATION.getBoolean();

// remove isPolicyAttribute from shouldPrefetch check
// prefetch properties for policies
// if there is some exception in fetching properties,
// then we will fetch properties again without prefetch

if (shouldPrefetch) {
return mapVertexToAtlasEntityHeaderWithPrefetch(entityVertex, attributes);
try {
return mapVertexToAtlasEntityHeaderWithPrefetch(entityVertex, attributes);
} catch (AtlasBaseException e) {
if (isPolicyAttribute(attributes)) {
RequestContext.get().endMetricRecord(RequestContext.get().startMetricRecord("policiesPrefetchFailed"));
LOG.error("Error fetching properties for entity vertex: {}. Retrying without prefetch", entityVertex.getId(), e);
return mapVertexToAtlasEntityHeaderWithoutPrefetch(entityVertex, attributes);
}
throw e;
}
} else {
return mapVertexToAtlasEntityHeaderWithoutPrefetch(entityVertex, attributes);
}
Expand Down
Loading