This is an automated email from the ASF dual-hosted git repository.

pinal-shah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new bcc9a87f49 ATLAS-5423: Unknown/invalid typename hook notifications 
should not be retried (#778)
bcc9a87f49 is described below

commit bcc9a87f49b1bc527ec90e2cf8a039ff3ab3b787
Author: saksenasonali <[email protected]>
AuthorDate: Mon Nov 30 18:06:44 2026 +0530

    ATLAS-5423: Unknown/invalid typename hook notifications should not be 
retried (#778)
---
 .../atlas/notification/SerialEntityProcessor.java  | 27 +++++++-
 .../notification/NotificationHookConsumerTest.java | 75 ++++++++++++++++++++++
 2 files changed, 100 insertions(+), 2 deletions(-)

diff --git 
a/webapp/src/main/java/org/apache/atlas/notification/SerialEntityProcessor.java 
b/webapp/src/main/java/org/apache/atlas/notification/SerialEntityProcessor.java
index 08f2d9808a..34d8fb83ae 100644
--- 
a/webapp/src/main/java/org/apache/atlas/notification/SerialEntityProcessor.java
+++ 
b/webapp/src/main/java/org/apache/atlas/notification/SerialEntityProcessor.java
@@ -20,6 +20,7 @@ package org.apache.atlas.notification;
 import org.apache.atlas.AtlasClient;
 import org.apache.atlas.AtlasClientV2;
 import org.apache.atlas.AtlasConfiguration;
+import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.RequestContext;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.kafka.AtlasKafkaMessage;
@@ -347,6 +348,7 @@ public class SerialEntityProcessor implements 
NotificationEntityProcessor {
      * - IllegalStateException: Invalid application state
      * - NullPointerException: Programming errors
      * - AtlasBaseException with INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND: 
Entity not found (acceptable)
+     * - AtlasBaseException with UNKNOWN_TYPENAME, TYPE_NAME_INVALID or 
TYPE_NAME_NOT_FOUND: type is not registered
      *
      * @param e the exception to classify
      * @return true if the exception is retryable, false otherwise
@@ -371,8 +373,9 @@ public class SerialEntityProcessor implements 
NotificationEntityProcessor {
         // Non-retryable: Entity not found is acceptable in some scenarios
         if (e instanceof AtlasBaseException) {
             AtlasBaseException baseException = (AtlasBaseException) e;
-            if 
(baseException.getAtlasErrorCode().equals(INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND))
 {
-                LOG.warn("Non-retryable exception: 
INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND");
+            AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
+            if (errorCode.equals(INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) || 
isUnknownTypeError(baseException)) {
+                LOG.warn("Non-retryable exception: {}", errorCode);
                 return false;
             }
         }
@@ -696,6 +699,20 @@ public class SerialEntityProcessor implements 
NotificationEntityProcessor {
                             AtlasBaseException baseException = 
(AtlasBaseException) e;
                             LOG.warn("Error handling message: {}: {} - {} - 
{}",
                                     
ticket.getMessage().getMessage().getType(), baseException.getAtlasErrorCode(), 
baseException.getMessage(), ticket.getQualifiedNamesSet());
+
+                            if (isUnknownTypeError(baseException)) {
+                                LOG.warn("Skipped message with an unregistered 
type at offset {}. If a hook keeps sending this type, add it to {} to drop such 
messages before processing",
+                                        kafkaMsg.getOffset(), 
CONSUMER_PREPROCESS_ENTITY_TYPE_IGNORE_PATTERN);
+
+                                stats.isFailedMsg = true;
+
+                                
failedMessages.add(AbstractNotification.getMessageJson(message));
+
+                                if (failedMessages.size() >= 
failedMsgCacheSize) {
+                                    recordFailedMessages(kafkaMsg.getTopic(), 
failedMessages);
+                                }
+                            }
+
                             return new 
TopicPartitionOffsetResult(kafkaMsg.getTopicPartition(), kafkaMsg.getOffset());
                         } else {
                             LOG.error("Non-retryable exception: {}", 
exceptionClassName, e);
@@ -1093,6 +1110,12 @@ public class SerialEntityProcessor implements 
NotificationEntityProcessor {
         return ret;
     }
 
+    private static boolean isUnknownTypeError(AtlasBaseException excp) {
+        AtlasErrorCode errorCode = excp.getAtlasErrorCode();
+
+        return errorCode == AtlasErrorCode.UNKNOWN_TYPENAME || errorCode == 
AtlasErrorCode.TYPE_NAME_INVALID || errorCode == 
AtlasErrorCode.TYPE_NAME_NOT_FOUND;
+    }
+
     private void recordProcessedEntities(EntityMutationResponse 
mutationResponse, NotificationStat stats, PreprocessorContext context) {
         if (mutationResponse != null) {
             if (stats != null) {
diff --git 
a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerTest.java
 
b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerTest.java
index 46d2a6a203..7334717126 100644
--- 
a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerTest.java
+++ 
b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerTest.java
@@ -88,6 +88,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import static 
org.apache.atlas.notification.NotificationInterface.NotificationType.ASYNC_IMPORT;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyList;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -223,6 +224,67 @@ public class NotificationHookConsumerTest {
         verify(consumer, times(1)).commit(any(TopicPartition.class), 
anyLong());
     }
 
+    @Test
+    public void testUnknownTypeNameInPartialUpdateIsNotRetried() throws 
Exception {
+        NotificationConsumer consumer = mock(NotificationConsumer.class);
+        NotificationHookConsumer.HookConsumer hookConsumer = 
createHookConsumerWithConfig(buildFailedMsgCacheConfig(10), consumer);
+        AtlasObjectId entityId = new AtlasObjectId("trino_table", 
"qualifiedName", "db.tbl@cl1");
+        HookNotification.EntityPartialUpdateRequestV2 message = new 
HookNotification.EntityPartialUpdateRequestV2("user", entityId, new 
AtlasEntity.AtlasEntityWithExtInfo(new AtlasEntity("trino_table")));
+
+        when(atlasEntityStore.updateEntity(any(AtlasObjectId.class), 
any(AtlasEntity.AtlasEntityWithExtInfo.class), anyBoolean()))
+                .thenThrow(new 
AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, "trino_table"));
+
+        hookConsumer.handleMessage(new AtlasKafkaMessage(message, 5, 
KafkaNotification.ATLAS_HOOK_TOPIC, 0));
+
+        verify(atlasEntityStore, 
times(1)).updateEntity(any(AtlasObjectId.class), 
any(AtlasEntity.AtlasEntityWithExtInfo.class), anyBoolean());
+        verify(consumer, times(1)).commit(any(TopicPartition.class), eq(6L));
+    }
+
+    @Test
+    public void testInvalidTypeNameInCreateIsNotRetried() throws Exception {
+        NotificationConsumer consumer = mock(NotificationConsumer.class);
+        NotificationHookConsumer.HookConsumer hookConsumer = 
createHookConsumerWithConfig(buildFailedMsgCacheConfig(10), consumer);
+        AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo(new 
AtlasEntity("unknown_type"));
+
+        when(atlasEntityStore.createOrUpdate(any(EntityStream.class), 
anyBoolean()))
+                .thenThrow(new 
AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, "entity", "unknown_type"));
+
+        hookConsumer.handleMessage(new AtlasKafkaMessage(new 
EntityCreateRequestV2("user", entities), 5, KafkaNotification.ATLAS_HOOK_TOPIC, 
0));
+
+        verify(atlasEntityStore, 
times(1)).createOrUpdate(any(EntityStream.class), anyBoolean());
+        verify(consumer, times(1)).commit(any(TopicPartition.class), eq(6L));
+    }
+
+    @Test
+    public void testUnknownTypeNameInV1PartialUpdateIsNotRetried() throws 
Exception {
+        NotificationConsumer consumer = mock(NotificationConsumer.class);
+        NotificationHookConsumer.HookConsumer hookConsumer = 
createHookConsumerWithConfig(buildFailedMsgCacheConfig(10), consumer);
+        HookNotificationV1.EntityPartialUpdateRequest message = new 
HookNotificationV1.EntityPartialUpdateRequest("user", "trino_table", 
"qualifiedName", "db.tbl@cl1", new Referenceable("trino_table"));
+
+        
when(instanceConverter.toAtlasEntity(any(Referenceable.class))).thenThrow(new 
AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, "trino_table"));
+
+        hookConsumer.handleMessage(new AtlasKafkaMessage(message, 5, 
KafkaNotification.ATLAS_HOOK_TOPIC, 0));
+
+        verify(instanceConverter, 
times(1)).toAtlasEntity(any(Referenceable.class));
+        verify(atlasEntityStore, 
never()).createOrUpdate(any(EntityStream.class), anyBoolean());
+        verify(consumer, times(1)).commit(any(TopicPartition.class), eq(6L));
+    }
+
+    @Test
+    public void testUnknownTypeNameInDeleteV2IsNotRetried() throws Exception {
+        NotificationConsumer consumer = mock(NotificationConsumer.class);
+        NotificationHookConsumer.HookConsumer hookConsumer = 
createHookConsumerWithConfig(buildFailedMsgCacheConfig(10), consumer);
+        List<AtlasObjectId> objectIds = Collections.singletonList(new 
AtlasObjectId("unknown_type", "qualifiedName", "x@cl1"));
+
+        when(typeRegistry.getType("unknown_type")).thenThrow(new 
AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, "unknown_type"));
+
+        hookConsumer.handleMessage(new AtlasKafkaMessage(new 
EntityDeleteRequestV2("user", objectIds), 5, 
KafkaNotification.ATLAS_HOOK_TOPIC, 0));
+
+        verify(typeRegistry, times(1)).getType("unknown_type");
+        verify(atlasEntityStore, 
never()).deleteByUniqueAttributes(any(AtlasEntityType.class), any());
+        verify(consumer, times(1)).commit(any(TopicPartition.class), eq(6L));
+    }
+
     @Test
     public void testConsumerProceedsWithFalseIfInterrupted() throws Exception {
         NotificationHookConsumer notificationHookConsumer = new 
NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, 
instanceConverter, typeRegistry, metricsUtil, null, asyncImporter, null);
@@ -1370,6 +1432,12 @@ public class NotificationHookConsumerTest {
 
         NotificationHookConsumer.Timer mockTimer = 
mock(NotificationHookConsumer.Timer.class);
 
+        // A no-op sleep never observes the interrupt, leaving the thread 
spinning on mocks until the fork runs out of heap.
+        doAnswer(invocation -> {
+            Thread.sleep(10);
+            return null;
+        }).when(mockTimer).sleep(anyInt());
+
         // Run in separate thread to avoid blocking
         Thread testThread = new Thread(() -> {
             try {
@@ -1384,6 +1452,7 @@ public class NotificationHookConsumerTest {
         testThread.interrupt();
         testThread.join(1000);
 
+        assertFalse(testThread.isAlive(), "serverAvailable() should exit once 
interrupted");
         verify(serviceState, atLeast(1)).getState();
     }
 
@@ -2584,6 +2653,12 @@ public class NotificationHookConsumerTest {
         return cacheConfig;
     }
 
+    private NotificationHookConsumer.HookConsumer 
createHookConsumerWithConfig(Configuration config, NotificationConsumer 
consumer) throws Exception {
+        NotificationHookConsumer notificationHookConsumer = new 
NotificationHookConsumer(notificationInterface, atlasEntityStore, serviceState, 
instanceConverter, typeRegistry, metricsUtil, null, asyncImporter, null);
+
+        return (NotificationHookConsumer.HookConsumer) 
createHookConsumerWithEntityProcessor(notificationHookConsumer, consumer, 
createEntityProcessor(config));
+    }
+
     private Object createEntityProcessor(Configuration configuration) throws 
Exception {
         return new SerialEntityProcessor(
                 configuration,

Reply via email to