GorlosHao opened a new pull request, #419:
URL: https://github.com/apache/doris-thirdparty/pull/419

   ## Summary
   Clamp `latencyMillis` before converting it to `int` in 
`LatencyPercentile.add()`. This PR changes one line in one file.
   
   ## Observed failure
   While a newly started FE was catching up, the existing master FE encountered 
this exception in the replication feeder. Its BDB environment became invalid 
and the FE service was interrupted until restart/recovery.
   
   ```text
   Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1871525518 out 
of bounds for length 1001
       at 
java.base/java.util.concurrent.atomic.AtomicLongArray.incrementAndGet(AtomicLongArray.java:234)
       at 
com.sleepycat.je.utilint.LatencyPercentile.add(LatencyPercentile.java:288)
       at 
com.sleepycat.je.rep.impl.node.Feeder$InputThread.processHeartbeatResponse(Feeder.java:981)
       at 
com.sleepycat.je.rep.impl.node.Feeder$InputThread.runResponseLoop(Feeder.java:856)
       at com.sleepycat.je.rep.impl.node.Feeder$InputThread.run(Feeder.java:755)
   ```
   
   The deployment used Doris 4.1.3-rc02 and Java 17.0.2; the JE runtime 
reported version 18.3.12. The same narrowing-before-clamping code is present in 
the current `bdbje` branch. The exact latency input was not logged.
   
   ## Root cause and fix
   `Math.min((int) latencyMillis, maxTrackedLatencyMillis)` narrows a positive 
`long` before applying the upper bound. Large values can produce a negative 
histogram index or wrap into an incorrect lower bucket. For example, 
`2423441778L` narrows to the negative index shown above.
   
   Using `(int) Math.min(latencyMillis, maxTrackedLatencyMillis)` applies the 
cap first and preserves the intended overflow-bucket behavior. Negative latency 
handling is unchanged.
   
   ## Validation
   Local isolated JUnit 4.12 tests compiled the actual upstream class and its 
supporting classes with JDK 26 (`--release 8`). Four tests covered large 
positive inputs, ignored negative inputs, normal in-range inputs, and a zero 
maximum.
   
   - Before: 4 tests run, 2 failed with `ArrayIndexOutOfBoundsException`.
   - After: all 4 tests passed.
   
   The test file is not included in this PR. The full Maven build and a live 
Doris cluster reproduction were not run.
   
   ## Related fix
   StarRocks addressed the same overflow failure in 
[StarRocks/starrocks-bdb-je#12](https://github.com/StarRocks/starrocks-bdb-je/pull/12).
 This change caps the original `long` value before conversion so oversized 
samples remain in the maximum bucket.


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