30
30
import com .linkedin .mxe .MetadataChangeLog ;
31
31
import com .linkedin .mxe .SystemMetadata ;
32
32
import com .linkedin .structured .StructuredPropertyDefinition ;
33
+ import com .linkedin .util .Pair ;
33
34
import io .datahubproject .metadata .context .OperationContext ;
34
35
import java .io .IOException ;
35
36
import java .io .UnsupportedEncodingException ;
@@ -138,12 +139,15 @@ public void handleChangeEvent(
138
139
// system metadata is last for tracing
139
140
handleUpdateChangeEvent (opContext , mclItem , true );
140
141
} else if (hookEvent .getChangeType () == ChangeType .DELETE ) {
142
+ Pair <EntitySpec , AspectSpec > specPair = extractSpecPair (mclItem );
143
+ boolean isDeletingKey = isDeletingKey (specPair );
144
+
141
145
// non-system metadata
142
- handleDeleteChangeEvent (opContext , mclItem , false );
146
+ handleNonSystemMetadataDeleteChangeEvent (opContext , specPair , mclItem , isDeletingKey );
143
147
// graph update
144
148
updateGraphIndicesService .handleChangeEvent (opContext , event );
145
149
// system metadata is last for tracing
146
- handleDeleteChangeEvent ( opContext , mclItem , true );
150
+ handleSystemMetadataDeleteChangeEvent ( mclItem . getUrn (), specPair , isDeletingKey );
147
151
}
148
152
}
149
153
} catch (IOException e ) {
@@ -242,6 +246,25 @@ public void updateIndexMappings(
242
246
}
243
247
}
244
248
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
+
245
268
/**
246
269
* This very important method processes {@link MetadataChangeLog} deletion events to cleanup the
247
270
* Metadata Graph when an aspect or entity is removed.
@@ -252,33 +275,39 @@ public void updateIndexMappings(
252
275
* <p>Note that if an entity's key aspect is deleted, the entire entity will be purged from
253
276
* search, graph, timeseries, etc.
254
277
*
278
+ * @param opContext operation's context
279
+ * @param specPair entity & aspect spec
255
280
* @param event the change event to be processed.
281
+ * @param isDeletingKey whether the key aspect is being deleted
256
282
*/
257
- private void handleDeleteChangeEvent (
283
+ private void handleNonSystemMetadataDeleteChangeEvent (
258
284
@ Nonnull OperationContext opContext ,
285
+ Pair <EntitySpec , AspectSpec > specPair ,
259
286
@ 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 );
271
297
}
298
+ }
272
299
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 );
282
311
}
283
312
}
284
313
0 commit comments