Skip to content

Commit 838acd4

Browse files
committed
updates per review
1 parent d101d78 commit 838acd4

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

metadata-io/src/main/java/com/linkedin/metadata/service/UpdateIndicesService.java

+52-23
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.linkedin.mxe.MetadataChangeLog;
3131
import com.linkedin.mxe.SystemMetadata;
3232
import com.linkedin.structured.StructuredPropertyDefinition;
33+
import com.linkedin.util.Pair;
3334
import io.datahubproject.metadata.context.OperationContext;
3435
import java.io.IOException;
3536
import java.io.UnsupportedEncodingException;
@@ -138,12 +139,15 @@ public void handleChangeEvent(
138139
// system metadata is last for tracing
139140
handleUpdateChangeEvent(opContext, mclItem, true);
140141
} else if (hookEvent.getChangeType() == ChangeType.DELETE) {
142+
Pair<EntitySpec, AspectSpec> specPair = extractSpecPair(mclItem);
143+
boolean isDeletingKey = isDeletingKey(specPair);
144+
141145
// non-system metadata
142-
handleDeleteChangeEvent(opContext, mclItem, false);
146+
handleNonSystemMetadataDeleteChangeEvent(opContext, specPair, mclItem, isDeletingKey);
143147
// graph update
144148
updateGraphIndicesService.handleChangeEvent(opContext, event);
145149
// system metadata is last for tracing
146-
handleDeleteChangeEvent(opContext, mclItem, true);
150+
handleSystemMetadataDeleteChangeEvent(mclItem.getUrn(), specPair, isDeletingKey);
147151
}
148152
}
149153
} catch (IOException e) {
@@ -242,6 +246,25 @@ public void updateIndexMappings(
242246
}
243247
}
244248

249+
private static Pair<EntitySpec, AspectSpec> extractSpecPair(@Nonnull final MCLItem event) {
250+
final EntitySpec entitySpec = event.getEntitySpec();
251+
final Urn urn = event.getUrn();
252+
253+
AspectSpec aspectSpec = entitySpec.getAspectSpec(event.getAspectName());
254+
if (aspectSpec == null) {
255+
throw new RuntimeException(
256+
String.format(
257+
"Failed to retrieve Aspect Spec for entity with name %s, aspect with name %s. Cannot update indices for MCL.",
258+
urn.getEntityType(), event.getAspectName()));
259+
}
260+
261+
return Pair.of(entitySpec, aspectSpec);
262+
}
263+
264+
private static boolean isDeletingKey(Pair<EntitySpec, AspectSpec> specPair) {
265+
return specPair.getSecond().getName().equals(specPair.getFirst().getKeyAspectName());
266+
}
267+
245268
/**
246269
* This very important method processes {@link MetadataChangeLog} deletion events to cleanup the
247270
* Metadata Graph when an aspect or entity is removed.
@@ -252,33 +275,39 @@ public void updateIndexMappings(
252275
* <p>Note that if an entity's key aspect is deleted, the entire entity will be purged from
253276
* search, graph, timeseries, etc.
254277
*
278+
* @param opContext operation's context
279+
* @param specPair entity & aspect spec
255280
* @param event the change event to be processed.
281+
* @param isDeletingKey whether the key aspect is being deleted
256282
*/
257-
private void handleDeleteChangeEvent(
283+
private void handleNonSystemMetadataDeleteChangeEvent(
258284
@Nonnull OperationContext opContext,
285+
Pair<EntitySpec, AspectSpec> specPair,
259286
@Nonnull final MCLItem event,
260-
boolean forSystemMetadata) {
261-
262-
final EntitySpec entitySpec = event.getEntitySpec();
263-
final Urn urn = event.getUrn();
264-
265-
AspectSpec aspectSpec = entitySpec.getAspectSpec(event.getAspectName());
266-
if (aspectSpec == null) {
267-
throw new RuntimeException(
268-
String.format(
269-
"Failed to retrieve Aspect Spec for entity with name %s, aspect with name %s. Cannot update indices for MCL.",
270-
urn.getEntityType(), event.getAspectName()));
287+
boolean isDeletingKey) {
288+
289+
if (!specPair.getSecond().isTimeseries()) {
290+
deleteSearchData(
291+
opContext,
292+
event.getUrn(),
293+
specPair.getFirst().getName(),
294+
specPair.getSecond(),
295+
event.getRecordTemplate(),
296+
isDeletingKey);
271297
}
298+
}
272299

273-
RecordTemplate aspect = event.getRecordTemplate();
274-
Boolean isDeletingKey = event.getAspectName().equals(entitySpec.getKeyAspectName());
275-
276-
if (!aspectSpec.isTimeseries()) {
277-
if (!forSystemMetadata) {
278-
deleteSearchData(opContext, urn, entitySpec.getName(), aspectSpec, aspect, isDeletingKey);
279-
} else {
280-
deleteSystemMetadata(urn, aspectSpec, isDeletingKey);
281-
}
300+
/**
301+
* Handle the system metadata separately for tracing
302+
*
303+
* @param urn delete urn
304+
* @param specPair entity & aspect spec
305+
* @param isDeletingKey whether the key aspect is being deleted
306+
*/
307+
private void handleSystemMetadataDeleteChangeEvent(
308+
@Nonnull Urn urn, Pair<EntitySpec, AspectSpec> specPair, boolean isDeletingKey) {
309+
if (!specPair.getSecond().isTimeseries()) {
310+
deleteSystemMetadata(urn, specPair.getSecond(), isDeletingKey);
282311
}
283312
}
284313

metadata-io/src/main/java/com/linkedin/metadata/trace/KafkaTraceReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public Map<Urn, Map<String, TraceStorageStatus>> tracePendingStatuses(
136136

137137
try {
138138
List<Map.Entry<Urn, Map<String, TraceStorageStatus>>> results =
139-
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
139+
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]))
140140
.thenApply(
141141
v -> futures.stream().map(CompletableFuture::join).collect(Collectors.toList()))
142142
.get(timeoutSeconds, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)