JNSimba opened a new pull request, #61253:
URL: https://github.com/apache/doris/pull/61253

   ### What problem does this PR solve?
   
   #### Problem                                                                 
                                 
                     
     `StreamingInsertJob.replayOnCommitted()` throws a `NullPointerException` 
during FE replay:                  
                     
   ```
     java.lang.NullPointerException: Cannot invoke
     "org.apache.doris.metric.LongCounterMetric.increase(java.lang.Long)"
       because 
"org.apache.doris.metric.MetricRepo.COUNTER_STREAMING_JOB_TOTAL_ROWS" is null
         at 
StreamingInsertJob.updateJobStatisticAndOffset(StreamingInsertJob.java:634)
         at StreamingInsertJob.replayOnCommitted(StreamingInsertJob.java:1020)
         at 
TransactionState.replaySetTransactionStatus(TransactionState.java:589)
         at 
DatabaseTransactionMgr.replayUpsertTransactionState(DatabaseTransactionMgr.java:2636)
         at 
GlobalTransactionMgr.replayUpsertTransactionState(GlobalTransactionMgr.java:952)
   ```
   
     The root cause is that `MetricRepo` may not be initialized when FE replays 
transaction logs during startup,
     but `StreamingInsertJob` unconditionally calls metric update methods, 
leading to NPE.
   
   #### Fix
   
     Two separate changes are applied to `StreamingInsertJob`:
   
     1. **Skip metric updates during replay**: `updateJobStatisticAndOffset` and
     `updateCloudJobStatisticAndOffset` now accept an `isReplay` boolean 
parameter. Call sites in
     `replayOnCommitted` and `replayOnCloudMode` pass `true`, while 
`afterCommitted` passes `false`.
   
     2. **Guard all metric calls with `MetricRepo.isInit`**: All remaining 
`MetricRepo.COUNTER_STREAMING_JOB_*`
     call sites are wrapped with `if (MetricRepo.isInit && !isReplay)` or `if 
(MetricRepo.isInit)` to prevent NPE
      if `MetricRepo` has not been fully initialized.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


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

Reply via email to