Fix Deletion of Entities (#20129)

This commit is contained in:
Mohit Yadav 2025-03-07 12:41:52 +05:30 committed by GitHub
parent c65a504ffd
commit 97bce917be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 44 additions and 37 deletions

View File

@ -369,13 +369,12 @@ public class AppRepository extends EntityRepository<App> {
}
@Override
protected void cleanup(App app) {
protected void entitySpecificCleanup(App app) {
// Remove the Pipelines for Application
List<EntityReference> pipelineRef = getIngestionPipelines(app);
pipelineRef.forEach(
reference ->
Entity.deleteEntity("admin", reference.getType(), reference.getId(), true, true));
super.cleanup(app);
}
@Override

View File

@ -1474,42 +1474,56 @@ public abstract class EntityRepository<T extends EntityInterface> {
}
}
@Transaction
protected void cleanup(T entityInterface) {
UUID id = entityInterface.getId();
protected final void cleanup(T entityInterface) {
Entity.getJdbi()
.inTransaction(
handle -> {
// Perform Entity Specific Cleanup
entitySpecificCleanup(entityInterface);
// Delete all the relationships to other entities
daoCollection.relationshipDAO().deleteAll(id, entityType);
UUID id = entityInterface.getId();
// Delete all the field relationships to other entities
daoCollection.fieldRelationshipDAO().deleteAllByPrefix(entityInterface.getFullyQualifiedName());
// Delete all the relationships to other entities
daoCollection.relationshipDAO().deleteAll(id, entityType);
// Delete all the extensions of entity
daoCollection.entityExtensionDAO().deleteAll(id);
// Delete all the field relationships to other entities
daoCollection
.fieldRelationshipDAO()
.deleteAllByPrefix(entityInterface.getFullyQualifiedName());
// Delete all the tag labels
daoCollection
.tagUsageDAO()
.deleteTagLabelsByTargetPrefix(entityInterface.getFullyQualifiedName());
// Delete all the extensions of entity
daoCollection.entityExtensionDAO().deleteAll(id);
// when the glossary and tag is deleted, delete its usage
daoCollection.tagUsageDAO().deleteTagLabelsByFqn(entityInterface.getFullyQualifiedName());
// Delete all the usage data
daoCollection.usageDAO().delete(id);
// Delete all the tag labels
daoCollection
.tagUsageDAO()
.deleteTagLabelsByTargetPrefix(entityInterface.getFullyQualifiedName());
// Delete the extension data storing custom properties
removeExtension(entityInterface);
// when the glossary and tag is deleted, delete its usage
daoCollection
.tagUsageDAO()
.deleteTagLabelsByFqn(entityInterface.getFullyQualifiedName());
// Delete all the usage data
daoCollection.usageDAO().delete(id);
// Delete all the threads that are about this entity
Entity.getFeedRepository().deleteByAbout(entityInterface.getId());
// Delete the extension data storing custom properties
removeExtension(entityInterface);
// Remove entity from the cache
invalidate(entityInterface);
// Delete all the threads that are about this entity
Entity.getFeedRepository().deleteByAbout(entityInterface.getId());
// Finally, delete the entity
dao.delete(id);
// Remove entity from the cache
invalidate(entityInterface);
// Finally, delete the entity
dao.delete(id);
return null;
});
}
protected void entitySpecificCleanup(T entityInterface) {}
private void invalidate(T entity) {
CACHE_WITH_ID.invalidate(new ImmutablePair<>(entityType, entity.getId()));
CACHE_WITH_NAME.invalidate(new ImmutablePair<>(entityType, entity.getFullyQualifiedName()));

View File

@ -552,7 +552,6 @@ public class FeedRepository {
dao.feedDAO().delete(id);
}
@Transaction
public void deleteByAbout(UUID entityId) {
List<String> threadIds = listOrEmpty(dao.feedDAO().findByEntityId(entityId.toString()));
for (String threadId : threadIds) {

View File

@ -305,7 +305,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
}
@Override
protected void cleanup(Pipeline pipeline) {
protected void entitySpecificCleanup(Pipeline pipeline) {
// When a pipeline is removed , the linege needs to be removed
daoCollection
.relationshipDAO()
@ -313,7 +313,6 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
pipeline.getId(),
LineageDetails.Source.PIPELINE_LINEAGE.value(),
Relationship.UPSTREAM.ordinal());
super.cleanup(pipeline);
}
@Override

View File

@ -72,7 +72,7 @@ public class StoredProcedureRepository extends EntityRepository<StoredProcedure>
}
@Override
protected void cleanup(StoredProcedure storedProcedure) {
protected void entitySpecificCleanup(StoredProcedure storedProcedure) {
// When a pipeline is removed , the linege needs to be removed
daoCollection
.relationshipDAO()
@ -80,7 +80,6 @@ public class StoredProcedureRepository extends EntityRepository<StoredProcedure>
storedProcedure.getId(),
LineageDetails.Source.QUERY_LINEAGE.value(),
Relationship.UPSTREAM.ordinal());
super.cleanup(storedProcedure);
}
@Override

View File

@ -295,7 +295,7 @@ public class TeamRepository extends EntityRepository<Team> {
}
@Override
protected void cleanup(Team team) {
protected void entitySpecificCleanup(Team team) {
// When a team is deleted, if the children team don't have another parent, set Organization as
// the parent
for (EntityReference child : listOrEmpty(team.getChildren())) {
@ -308,7 +308,6 @@ public class TeamRepository extends EntityRepository<Team> {
LOG.info("Moving parent of team " + childTeam.getId() + " to organization");
}
}
super.cleanup(team);
}
@Override

View File

@ -368,10 +368,8 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
}
}
@Transaction
@Override
protected void cleanup(TestCase entityInterface) {
super.cleanup(entityInterface);
protected void entitySpecificCleanup(TestCase entityInterface) {
deleteAllTestCaseResults(entityInterface.getFullyQualifiedName());
}