sheetalshah1007 opened a new pull request, #766:
URL: https://github.com/apache/atlas/pull/766

   
   ## Issue
   
   During startup, Atlas applies JSON typedef patches **before** the Java patch 
service creates `PatchContext`.
   
   Two typedef actions register a Java follow-up patch immediately:
   
   | Typedef action | Handler | Java patch |
   |----------------|---------|------------|
   | `ADD_SUPER_TYPES` | `AddSuperTypePatchHandler` | `SuperTypesUpdatePatch` 
(`JAVA_PATCH_0000_007_…`) |
   | `ADD_MANDATORY_ATTRIBUTE` | `AddMandatoryAttributePatchHandler` | 
`AddMandatoryAttributesPatch` (`JAVA_PATCH_0000_008_…`) |
   
   On unfixed code, `PatchContext` is still **null** when those handlers run. 
Both Java patches call `context.getPatchRegistry()` in their constructor and 
throw a **NullPointerException**. The typedef patch file is skipped and the 
Java entity update never runs.
   
   Manual repro used `ADD_SUPER_TYPES` / `SuperTypesUpdatePatch` with 
`018-fs_path_add_supertypes.json`; the same bootstrap bug applies to 
mandatory-attribute patches.
   
   ## Fix
   
   Create `PatchContext` when typedef bootstrap needs it 
(`getOrCreatePatchContext()`), and use it from `AddSuperTypePatchHandler` and 
`AddMandatoryAttributePatchHandler` so `SuperTypesUpdatePatch` and 
`AddMandatoryAttributesPatch` can register before `AtlasPatchService` starts.
   
   ## How tested
   
   - Unit tests: `AtlasPatchManagerTest`, `AtlasTypeDefStoreInitializerTest`.
   - Manual lab (ATLAS-5413): lab-tuned `fs_path` model and 
`018-fs_path_add_supertypes.json` (versions aligned so the patch applies), 
**fresh `data/`** each run.
   
   ## Negative testing (before fix)
   
   - Pre-fix build, same models/patch, wiped `data/`.
   - Patch **018** runs → log `Update entities of fs_path with new supertypes` 
→ **NPE**, patch file **Ignored**.
   - No `getOrCreatePatchContext` during typedef init; `AtlasPatchService` 
starts **after** the error.
   - No `JAVA_PATCH_0000_007_TYPEDEF_PATCH_1000_018_001` / 
`SuperTypesUpdatePatch.apply()`.
   
   ## Positive testing (after fix)
   
   - Fix build, same setup, wiped `data/`.
   - `getOrCreatePatchContext` during typedef init → 
`TYPEDEF_PATCH_1000_018_001` **APPLIED** → Java patch **APPLIED** (0 entities).
   
   ## Sample logs
   
   **Before fix**
   
   ```
   Update entities of fs_path with new supertypes
   Failed to apply patches in file .../018-fs_path_add_supertypes.json. Ignored
   java.lang.NullPointerException: null
        at 
org.apache.atlas.repository.patches.SuperTypesUpdatePatch.<init>(SuperTypesUpdatePatch.java:47)
        at ...AddSuperTypePatchHandler.applyPatch(...)
   ```
   
   **After fix**
   
   ```
   Update entities of fs_path with new supertypes
   AtlasPatchManager.getOrCreatePatchContext(): creating PatchContext
   TYPEDEF_PATCH_1000_018_001 (status: APPLIED; action: ADD_SUPER_TYPES) 
.../018-fs_path_add_supertypes.json
   Applying java handler: JAVA_PATCH_0000_007_TYPEDEF_PATCH_1000_018_001
   ==> SuperTypesUpdatePatch.apply(): 
patchId=JAVA_PATCH_0000_007_TYPEDEF_PATCH_1000_018_001
   <== SuperTypesUpdatePatch.apply(): ... status=APPLIED
   ```


-- 
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