justinmclean opened a new issue, #10176:
URL: https://github.com/apache/gravitino/issues/10176

   ### What would you like to be improved?
   
   BuiltInJobTemplateEventListener.updateBuiltInJobTemplate(...) builds the 
update NameIdentifier from newTemplate.name() instead of the existing persisted 
entity identity. When names differ (for example, rename/name drift), 
reconciliation enters update flow but entityStore.update(...) is executed with 
the wrong key, which can fail with not-found or update the wrong record.
   
   ### How should we improve?
   
   Use the existing entity identifier for lock and update target, not the 
incoming template name. In practice, derive NameIdentifier from existing (or 
existing.name() under the same metalake) and keep payload fields updated from 
newTemplate. 
   
   Here's a unit test to help:
   ```
   @Test
   public void testReconcileBuiltInJobTemplatesUpdateUsesExistingIdentifier() 
throws IOException {
     String metalakeName = "test_metalake";
     Map<String, JobTemplate> builtInTemplates = new HashMap<>();
   
     ShellJobTemplate renamedTemplate =
         ShellJobTemplate.builder()
             .withName("builtin-renamed")
             .withComment("updated")
             .withExecutable("/bin/echo")
             .withCustomFields(Collections.singletonMap("version", "v2"))
             .build();
     builtInTemplates.put("builtin-existing", renamedTemplate);
   
     JobTemplateEntity existingEntity = 
createJobTemplateEntity("builtin-existing", "v1");
     entityStore.put(existingEntity, false);
   
     when(jobManager.listJobTemplates(metalakeName))
         .thenReturn(Collections.singletonList(existingEntity));
   
     listener.reconcileBuiltInJobTemplates(metalakeName, builtInTemplates);
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to