Skip to content

Commit fbd5e65

Browse files
authored
Refactor deletion (#499)
1 parent a9f1320 commit fbd5e65

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

dao-api/src/main/java/com/linkedin/metadata/dao/BaseLocalDAO.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ public Collection<ASPECT_UNION> deleteMany(@Nonnull URN urn,
967967

968968
// entire delete operation should be atomic
969969
final Collection<RecordTemplate> results = runInTransactionWithRetry(() -> aspectClasses.stream()
970-
.map(x -> deleteWithReturn(urn, x, auditStamp, maxTransactionRetry, trackingContext))
970+
.map(x -> delete(urn, x, auditStamp, maxTransactionRetry, trackingContext))
971971
.collect(Collectors.toList()), maxTransactionRetry);
972972

973973
// package into ASPECT_UNION, this is logic performed in unwrapAddResultToUnion()
@@ -979,42 +979,35 @@ public Collection<ASPECT_UNION> deleteMany(@Nonnull URN urn,
979979
}
980980

981981
/**
982-
* Deletes the latest version of aspect for an entity.
982+
* Deletes the latest version of an aspect for an entity and returns the ***old value***.
983983
*
984984
* <p>The new aspect will have an automatically assigned version number, which is guaranteed to be positive and
985985
* monotonically increasing. Older versions of aspect will be purged automatically based on the retention setting.
986986
*
987-
* <p>Note that we do not support Post-update hooks while soft deleting an aspect
987+
* <p>Note that we do not currently support pre- or post- update hooks while soft deleting an aspect.
988+
*
989+
* <p>Note that if the aspect is already null or deleted, the return value will be null. Mechanistically, upon a normal
990+
* "LIVE" ingestion, the deletion operation is skipped altogether.
988991
*
989992
* @param urn urn the URN for the entity the aspect is attached to
990993
* @param aspectClass aspectClass of the aspect being saved
991994
* @param auditStamp the audit stamp of the previous latest aspect, null if new value is the first version
992995
* @param maxTransactionRetry maximum number of transaction retries before throwing an exception
993996
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}
997+
* @return the content of the aspect before deletion
994998
*/
995-
public <ASPECT extends RecordTemplate> void delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
999+
@Nullable
1000+
public <ASPECT extends RecordTemplate> ASPECT delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
9961001
@Nonnull AuditStamp auditStamp, int maxTransactionRetry) {
997-
delete(urn, aspectClass, auditStamp, maxTransactionRetry, null);
1002+
return delete(urn, aspectClass, auditStamp, maxTransactionRetry, null);
9981003
}
9991004

10001005
/**
10011006
* Same as above {@link #delete(Urn, Class, AuditStamp, int)} but with tracking context.
10021007
*/
1003-
public <ASPECT extends RecordTemplate> void delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
1004-
@Nonnull AuditStamp auditStamp, int maxTransactionRetry, @Nullable IngestionTrackingContext trackingContext) {
1005-
deleteWithReturn(urn, aspectClass, auditStamp, maxTransactionRetry, trackingContext);
1006-
}
1007-
1008-
/**
1009-
* Deletes the latest version of an aspect for an entity and returns the ***old value***.
1010-
*
1011-
* <p>Note that if the aspect is already null or deleted, the return value will be null. Mechanistically, upon a normal
1012-
* "LIVE" ingestion, the deletion operation is skipped altogether.
1013-
*/
10141008
@Nullable
1015-
public <ASPECT extends RecordTemplate> ASPECT deleteWithReturn(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
1009+
public <ASPECT extends RecordTemplate> ASPECT delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
10161010
@Nonnull AuditStamp auditStamp, int maxTransactionRetry, @Nullable IngestionTrackingContext trackingContext) {
1017-
10181011
checkValidAspect(aspectClass);
10191012

10201013
final AddResult<ASPECT> result = runInTransactionWithRetry(() -> {
@@ -1126,19 +1119,19 @@ public URN create(@Nonnull URN urn, @Nonnull List<? extends RecordTemplate> aspe
11261119
/**
11271120
* Similar to {@link #delete(Urn, Class, AuditStamp, int)} but uses the default maximum transaction retry.
11281121
*/
1129-
@Nonnull
1130-
public <ASPECT extends RecordTemplate> void delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
1122+
@Nullable
1123+
public <ASPECT extends RecordTemplate> ASPECT delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
11311124
@Nonnull AuditStamp auditStamp) {
1132-
delete(urn, aspectClass, auditStamp, null);
1125+
return delete(urn, aspectClass, auditStamp, null);
11331126
}
11341127

11351128
/**
11361129
* Same as above {@link #delete(Urn, Class, AuditStamp)} but with tracking context.
11371130
*/
1138-
@Nonnull
1139-
public <ASPECT extends RecordTemplate> void delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
1131+
@Nullable
1132+
public <ASPECT extends RecordTemplate> ASPECT delete(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
11401133
@Nonnull AuditStamp auditStamp, @Nullable IngestionTrackingContext trackingContext) {
1141-
delete(urn, aspectClass, auditStamp, DEFAULT_MAX_TRANSACTION_RETRY, trackingContext);
1134+
return delete(urn, aspectClass, auditStamp, DEFAULT_MAX_TRANSACTION_RETRY, trackingContext);
11421135
}
11431136

11441137
private <ASPECT extends RecordTemplate> void applyRetention(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,

dao-impl/ebean-dao/src/test/java/com/linkedin/metadata/dao/EbeanLocalDAOTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ public void testDeleteWithReturnOnNonexistentAsset() {
27352735
EbeanLocalDAO<EntityAspectUnion, FooUrn> dao = createDao(FooUrn.class);
27362736
FooUrn urn = makeFooUrn(1);
27372737

2738-
AspectFoo foo = dao.deleteWithReturn(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
2738+
AspectFoo foo = dao.delete(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
27392739
assertNull(foo);
27402740
}
27412741

@@ -2749,7 +2749,7 @@ public void testDeleteWithReturnOnNullAspect() {
27492749
dao.add(urn, v0, _dummyAuditStamp);
27502750

27512751
// attempt to delete an aspect that doesn't exist
2752-
AspectBar foo = dao.deleteWithReturn(urn, AspectBar.class, _dummyAuditStamp, 3, null);
2752+
AspectBar foo = dao.delete(urn, AspectBar.class, _dummyAuditStamp, 3, null);
27532753
assertNull(foo);
27542754
}
27552755

@@ -2759,13 +2759,13 @@ public void testDeleteWithReturnOnAlreadyDeletedAspect() {
27592759
FooUrn urn = makeFooUrn(1);
27602760
AspectFoo v0 = new AspectFoo().setValue("foo");
27612761
dao.add(urn, v0, _dummyAuditStamp);
2762-
AspectFoo foo = dao.deleteWithReturn(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
2762+
AspectFoo foo = dao.delete(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
27632763

27642764
// make sure that the content matches the original
27652765
assertEquals(foo, v0);
27662766

27672767
// attempt to delete an aspect that has already been deleted
2768-
AspectFoo fooAgain = dao.deleteWithReturn(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
2768+
AspectFoo fooAgain = dao.delete(urn, AspectFoo.class, _dummyAuditStamp, 3, null);
27692769
assertNull(fooAgain);
27702770
}
27712771

0 commit comments

Comments
 (0)