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 @Override
protected void cleanup(App app) { protected void entitySpecificCleanup(App app) {
// Remove the Pipelines for Application // Remove the Pipelines for Application
List<EntityReference> pipelineRef = getIngestionPipelines(app); List<EntityReference> pipelineRef = getIngestionPipelines(app);
pipelineRef.forEach( pipelineRef.forEach(
reference -> reference ->
Entity.deleteEntity("admin", reference.getType(), reference.getId(), true, true)); Entity.deleteEntity("admin", reference.getType(), reference.getId(), true, true));
super.cleanup(app);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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