Skip to content

Conversation

@UmeshPatil-1
Copy link

@UmeshPatil-1 UmeshPatil-1 commented Dec 27, 2025

ATLAS-4988
What changes were proposed in this pull request?
Background: In Apache Atlas, deleting a Business Metadata (BM) definition requires a pre-check to ensure no existing entities are assigned to those attributes. For attributes with a data type of Array (multi-valued), the deletion process was taking an exceptionally long time (e.g., over 55 minutes for -1,18,300 entities), even when the BM was not assigned to any entity.

Root Cause:

  1. Array attributes are not Solr-indexed
    ARRAY BM attributes are not indexed in Solr.
    Solr therefore performs a full collection scan when queried with NOT_EMPTY, causing severe latency.
  2. Single-path Solr validation
    The previous logic forced all BM attributes (STRING + ARRAY) through Solr.
    This was efficient for STRING attributes but pathological for ARRAY attributes.
  3. Historical entities ignored
    The earlier implementation excluded deleted entities.
    This allowed historical BM references to be missed, leading to potential integrity violations.
  4. Unnecessary data retrieval
    The Solr query requested attribute payloads, increasing I/O cost even though only existence was required.

Changes Proposed:

  1. Hybrid Validation Strategy: Introduced a conditional check to determine if an attribute is indexable before deciding the search path.
  2. Optimized Solr Validation for STRING Attributes: Uses NOT_EMPTY existence check only , Includes historical (deleted) entities.
  3. Direct Graph Fallback: Introduced isBusinessAttributePresentInGraph() for non-indexable attributes. This method queries the Graph database (JanusGraph) directly.
  4. Subtype & Inheritance Enforcement: Applicable entity types are expanded to include all subtypes.
  5. Integrity Maintenance: Ensured that even unindexed attributes are checked before deletion to prevent "dangling" metadata, while maintaining sub-second performance and Prevents accidental deletion under partial failure conditions also maintain strict metadata integrity.

Impact:

Performance Gain: Deletion time for Business Metadata with Array attributes reduced from -55 minutes to -25 second's.
Reliability: Maintains strict data integrity by ensuring no "in-use" Business Metadata can be deleted.
Scalability: The fix ensures that as the number of entities grows, the deletion of metadata remains performant.
Correctness:Prevents deletion when BM is referenced by: Active entities, Deleted (historical) entities, Subtypes via inheritance and Custom entity types.

How was this patch tested?
Maven Build:
Build Successful.

Manual Testing:

  1. Creation & Deletion (No Assignment): Created Business Metadata with String and Array types. Verified deletion is nearly instantaneous (-20s - 25s).
  2. Deletion Blocked (With Assignment): * Assigned a Business Metadata attribute to a hive_table entity and custom entities.
  3. Attempted to delete the BM definition.
  4. Historical Validation: BM assigned - Entity Deleted - BM delete attempted - Deletion Correctly Blocked.
  5. Verified the system correctly throws ATLAS-409-00-002: Given type has references.
  6. Large Dataset Validation: Tested against a repository containing -1,18,000 hive_table entities and custom entities to confirm the Solr timeout and latency issue is resolved.

The Patch was tested on cluster:- Result's as per below
1. Time taken to delete unassigned BM of String type :- Existing Code :- 2 sec - 4 sec, Updated Code:- 2 sec - 3 Sec.
2. Time taken to delete unassigned BM of Array type :- Existing Code :- 1 Hr 40 min, Updated Code:- 1.5 min - 3 min.

Please refer the attached sheet on JIRA-4988 ticket for more insight's

@UmeshPatil-1 UmeshPatil-1 changed the title ATLAS_4988: Resolve slow deletion issue of Business Metadata with arr… ATLAS_4988: BusinessMetadata with attribute of data type Array takes time to Delete. Dec 27, 2025
String qualifiedName = AtlasStructType.AtlasAttribute.getQualifiedAttributeName(businessMetadataDef, attributeDef.getName());
String vertexPropertyName = AtlasStructType.AtlasAttribute.generateVertexPropertyName(businessMetadataDef, attributeDef, qualifiedName);
Set<String> applicableTypes = AtlasJson.fromJson(attributeDef.getOption(AtlasBusinessMetadataDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES), Set.class);
for (AtlasStructDef.AtlasAttributeDef attributeDef : businessMetadataDef.getAttributeDefs()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the attribute iteration logic in checkBusinessMetadataRef to a private method (e.g., validateAttributeReferences) for better readability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return atlasSearchResult != null && CollectionUtils.isNotEmpty(atlasSearchResult.getEntities());
}

private boolean isBusinessAttributePresentInGraph(String vertexPropertyName, Set<String> applicableTypes) {
Copy link
Contributor

@sheetalshah1007 sheetalshah1007 Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. Replace manual iteration with Graph Query for better performance:
The method isBusinessAttributePresentInGraph manually iterates over all vertices of each applicable type using graph.getVertices(Constants.ENTITY_TYPE_PROPERTY_KEY, typeName), then checks each vertex for the property and state. This can be slow for large graphs, as it loads and inspects every vertex in memory. This needs to be improved

2. Add error handling and logging:
No exception handling in the graph operations.
If the graph is unavailable or queries fail, it could lead to unhandled exceptions. Wrap the query in a try-catch and log warnings/errors.
Also, add optional performance logging to monitor query times in production.

3. Add JUnit tests for the new method covering:
-Non-indexable attributes with/without assignments.
-Inactive entities (should not count).


return CollectionUtils.isNotEmpty(atlasSearchResult.getEntities());
Iterable<AtlasVertex> vertices = graph.query()
.has(Constants.ENTITY_TYPE_PROPERTY_KEY, typeName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add ENTITY_TYPE_PROPERTY_KEY filter here? If yes, note that all subTypes of types inapplicableTypes should be checked as well; consider a business attribute associated with a type like DataSet.

Iterable<AtlasVertex> vertices = graph.query()
.has(Constants.ENTITY_TYPE_PROPERTY_KEY, typeName)
.has(vertexPropertyName, AtlasGraphQuery.ComparisionOperator.NOT_EQUAL, (Object) null)
.has(Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to check only for ACTIVE entities? The business metadata can't be deleted even when a deleted entity has reference to it, right?

@UmeshPatil-1 UmeshPatil-1 changed the title ATLAS_4988: BusinessMetadata with attribute of data type Array takes time to Delete. ATLAS-4988: BusinessMetadata with attribute of data type Array takes time to Delete. Jan 3, 2026
…nt BM applicability is enforced across subtype inheritance etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants