feiniaofeiafei opened a new pull request, #63058:
URL: https://github.com/apache/doris/pull/63058
### What problem does this PR solve?
Fix NPE: `Cannot invoke
"org.apache.doris.catalog.MaterializedIndexMeta.getSchema()" because the return
value of "java.util.Map.get(Object)" is null` in OlapTable.getSchemaByIndexId.
Related: DORIS-23676, CIR-20142
**Root cause (race condition):**
1. Nereids planner acquires table read lock, selects `selectedIndexId =
baseIndexId`, then releases the lock after planning
2. A concurrent `SchemaChangeJobV2.onFinished` (under write lock) calls
`deleteIndexInfo(originIdxName)` which removes `originIdxId` from
`indexIdToMeta`
3. Later, `OlapScanNode.toThrift()` calls
`getSchemaByIndexId(selectedIndexId)` **without** holding any table lock →
returns null → NPE
**Fix (same approach as apache/doris#59298 for master):**
1. `NereidsPlanner`: call `cacheThriftPlans()` inside the lock callback
(while table read lock is still held), serializing the TPlan Thrift under the
lock
2. `PlanFragment`: add `cacheThriftPlan()` that pre-serializes
`planRoot.treeToThrift()` via a memoized `Supplier`; `toThrift()` reuses the
cached result
3. `OlapTable.getSchemaByIndexId`: add null guard that throws a clear
`RuntimeException` with context info instead of an opaque NPE
### Release note
None
### Check List (For Author)
- Test
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [x] No need to test or manual test. Explain why:
- This is a port of apache/doris#59298 from master to branch-3.1
- Behavior changed:
- [x] No.
- Does this need documentation?
- [x] No.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]