Skip to content

Commit 8324b14

Browse files
committed
fix comparison, reduce duplicate logging
1 parent a1fd30c commit 8324b14

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

entity-registry/src/main/java/com/linkedin/metadata/aspect/batch/AspectsBatch.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,17 @@ static Stream<MCLItem> applyMCLSideEffects(
159159
.flatMap(mclSideEffect -> mclSideEffect.apply(items, retrieverContext));
160160
}
161161

162-
default boolean containsDuplicateAspects() {
162+
default Map<String, Set<? extends BatchItem>> duplicateAspects() {
163163
return getItems().stream()
164-
.map(i -> String.format("%s_%s", i.getClass().getName(), i.hashCode()))
165-
.distinct()
166-
.count()
167-
!= getItems().size();
164+
.collect(
165+
Collectors.groupingBy(
166+
i -> String.format("%s_%s", i.getClass().getName(), i.hashCode()),
167+
Collectors.collectingAndThen(
168+
Collectors.toSet(), set -> set.size() > 1 ? set : null)))
169+
.entrySet()
170+
.stream()
171+
.filter(entry -> entry.getValue() != null)
172+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
168173
}
169174

170175
default Map<String, Set<String>> getUrnAspectsMap() {

metadata-io/src/main/java/com/linkedin/metadata/entity/EntityServiceImpl.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,9 @@ private List<UpdateAspectResult> ingestAspectsToLocalDB(
853853
@Nonnull final AspectsBatch inputBatch,
854854
boolean overwrite) {
855855

856-
if (inputBatch.containsDuplicateAspects()) {
857-
log.warn(String.format("Batch contains duplicates: %s", inputBatch));
856+
Map<String, Set<? extends BatchItem>> duplicates = inputBatch.duplicateAspects();
857+
if (!duplicates.isEmpty()) {
858+
log.warn(String.format("Batch contains duplicates: %s", duplicates.values()));
858859
MetricUtils.counter(EntityServiceImpl.class, "batch_with_duplicate").inc();
859860
}
860861

@@ -2550,7 +2551,8 @@ private UpdateAspectResult ingestAspectToLocalDB(
25502551
} catch (CloneNotSupportedException e) {
25512552
throw new RuntimeException(e);
25522553
}
2553-
latestSystemMetadata.setLastObserved(writeItem.getSystemMetadata().getLastObserved());
2554+
latestSystemMetadata.setLastObserved(
2555+
writeItem.getSystemMetadata().getLastObserved(), SetMode.IGNORE_NULL);
25542556
latestSystemMetadata.setLastRunId(
25552557
writeItem.getSystemMetadata().getLastRunId(GetMode.NULL), SetMode.IGNORE_NULL);
25562558

0 commit comments

Comments
 (0)