mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-17 13:00:56 +00:00
Fixes 4421 Clean up versions, entity extension, and other lingering entity data during hard deletion (#4425)
This commit is contained in:
parent
67009ba3ae
commit
a9570a21c6
@ -1297,6 +1297,9 @@ public interface CollectionDAO {
|
|||||||
@SqlUpdate("DELETE FROM tag_usage where tagFQN LIKE CONCAT(:tagFQN, '.%') AND source = :source")
|
@SqlUpdate("DELETE FROM tag_usage where tagFQN LIKE CONCAT(:tagFQN, '.%') AND source = :source")
|
||||||
void deleteTagLabelsByPrefix(@Bind("source") int source, @Bind("tagFQN") String tagFQN);
|
void deleteTagLabelsByPrefix(@Bind("source") int source, @Bind("tagFQN") String tagFQN);
|
||||||
|
|
||||||
|
@SqlUpdate("DELETE FROM tag_usage where targetFQN LIKE CONCAT(:targetFQN, '%')")
|
||||||
|
void deleteTagLabelsByTargetPrefix(@Bind("targetFQN") String targetFQN);
|
||||||
|
|
||||||
class TagLabelMapper implements RowMapper<TagLabel> {
|
class TagLabelMapper implements RowMapper<TagLabel> {
|
||||||
@Override
|
@Override
|
||||||
public TagLabel map(ResultSet r, StatementContext ctx) throws SQLException {
|
public TagLabel map(ResultSet r, StatementContext ctx) throws SQLException {
|
||||||
|
@ -492,20 +492,7 @@ public abstract class EntityRepository<T> {
|
|||||||
T original = JsonUtils.readValue(json, entityClass);
|
T original = JsonUtils.readValue(json, entityClass);
|
||||||
setFields(original, putFields); // TODO why this?
|
setFields(original, putFields); // TODO why this?
|
||||||
|
|
||||||
// If an entity being deleted contains other **non-deleted** children entities, it can't be deleted
|
deleteChildren(id, recursive, hardDelete, updatedBy);
|
||||||
List<EntityReference> contains =
|
|
||||||
daoCollection.relationshipDAO().findTo(id, entityType, Relationship.CONTAINS.ordinal());
|
|
||||||
|
|
||||||
if (!contains.isEmpty()) {
|
|
||||||
if (!recursive) {
|
|
||||||
throw new IllegalArgumentException(CatalogExceptionMessage.entityIsNotEmpty(entityType));
|
|
||||||
}
|
|
||||||
// Soft delete all the contained entities
|
|
||||||
for (EntityReference entityReference : contains) {
|
|
||||||
LOG.info("Recursively deleting {} {}", entityReference.getType(), entityReference.getId());
|
|
||||||
Entity.deleteEntity(updatedBy, entityReference.getType(), entityReference.getId(), true, hardDelete, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String changeType;
|
String changeType;
|
||||||
T updated = JsonUtils.readValue(json, entityClass);
|
T updated = JsonUtils.readValue(json, entityClass);
|
||||||
@ -517,16 +504,53 @@ public abstract class EntityRepository<T> {
|
|||||||
updater.update();
|
updater.update();
|
||||||
changeType = RestUtil.ENTITY_SOFT_DELETED;
|
changeType = RestUtil.ENTITY_SOFT_DELETED;
|
||||||
} else {
|
} else {
|
||||||
// Hard delete
|
cleanup(entityInterface);
|
||||||
daoCollection.relationshipDAO().deleteAll(id, entityType);
|
|
||||||
daoCollection.fieldRelationshipDAO().deleteAllByPrefix(entityInterface.getFullyQualifiedName());
|
|
||||||
daoCollection.entityExtensionDAO().deleteAll(id);
|
|
||||||
dao.delete(id);
|
|
||||||
changeType = RestUtil.ENTITY_DELETED;
|
changeType = RestUtil.ENTITY_DELETED;
|
||||||
}
|
}
|
||||||
return new DeleteResponse<>(updated, changeType);
|
return new DeleteResponse<>(updated, changeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteChildren(String id, boolean recursive, boolean hardDelete, String updatedBy) throws IOException {
|
||||||
|
// If an entity being deleted contains other **non-deleted** children entities, it can't be deleted
|
||||||
|
List<EntityReference> contains =
|
||||||
|
daoCollection.relationshipDAO().findTo(id, entityType, Relationship.CONTAINS.ordinal());
|
||||||
|
|
||||||
|
if (contains.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Entity being deleted contains children entities
|
||||||
|
if (!recursive) {
|
||||||
|
throw new IllegalArgumentException(CatalogExceptionMessage.entityIsNotEmpty(entityType));
|
||||||
|
}
|
||||||
|
// Delete all the contained entities
|
||||||
|
for (EntityReference entityReference : contains) {
|
||||||
|
LOG.info("Recursively deleting {} {}", entityReference.getType(), entityReference.getId());
|
||||||
|
Entity.deleteEntity(updatedBy, entityReference.getType(), entityReference.getId(), true, hardDelete, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanup(EntityInterface<T> entityInterface) {
|
||||||
|
String id = entityInterface.getId().toString();
|
||||||
|
|
||||||
|
// Delete all the relationships to other entities
|
||||||
|
daoCollection.relationshipDAO().deleteAll(id, entityType);
|
||||||
|
|
||||||
|
// Delete all the field relationships to other entities
|
||||||
|
daoCollection.fieldRelationshipDAO().deleteAllByPrefix(entityInterface.getFullyQualifiedName());
|
||||||
|
|
||||||
|
// Delete all the extensions of entity
|
||||||
|
daoCollection.entityExtensionDAO().deleteAll(id);
|
||||||
|
|
||||||
|
// Delete all the tag labels
|
||||||
|
daoCollection.tagUsageDAO().deleteTagLabelsByTargetPrefix(entityInterface.getFullyQualifiedName());
|
||||||
|
|
||||||
|
// Delete all the usage data
|
||||||
|
daoCollection.usageDAO().delete(id);
|
||||||
|
|
||||||
|
// Finally, delete the entity
|
||||||
|
dao.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public PutResponse<T> deleteFollower(String updatedBy, UUID entityId, UUID userId) throws IOException {
|
public PutResponse<T> deleteFollower(String updatedBy, UUID entityId, UUID userId) throws IOException {
|
||||||
T entity = dao.findEntityById(entityId);
|
T entity = dao.findEntityById(entityId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user