leerho opened a new pull request, #808:
URL: https://github.com/apache/datasketches-java/pull/808
Follows #805 (classic quantiles) and #806 (KLL): the same kind of failure,
now in `ReqSketch`.
## Problem
In `ReqSketch.compress()`, `ReqCompactor.compact()` trimmed the compacted
items from its own buffer and returned the promoted half. The caller then
merged that half into the next level, which may have to grow its buffer. If
that allocation failed, the promoted items were gone, and `retItems` and
`maxNomSize` no longer matched the compactors.
`update()` also set min and max before appending the item, so a failed
append left a min or max for an item that was never added.
## Changes
- `ReqCompactor.compact()` now takes the next level's buffer. It reserves
space there first, merges the promoted items in, and only then trims its own
buffer and advances its state and coin.
- `ensureEnoughSections()` allocates before it changes the section fields.
- If anything interrupts `compress()`, the catch block recomputes `retItems`
and `maxNomSize` from the compactors and rethrows. The sketch stays valid and
compresses again on the next update.
- `update()` stores min and max after the append.
- `FloatBuffer.ensureSpace()` is now package-private.
- `ReqSketch` class javadoc: a new paragraph, "Exceptions during update".
A merge can still leave part of the other sketch applied if it throws. This
PR leaves that as it is, as in #806.
## Testing
- New `ReqUpdateFailureTest`:
- `compactorUnchangedWhenPromotionFails`: the merge into the next level
fails (its buffer isn't sorted), and the compactor's image, coin and the next
buffer stay unchanged. Covers both HRA and LRA.
- `sketchConsistentWhenCompressionFails`: a `ReqDebug` throws while a
level is being added mid-compression. After that, N, min, retained count,
nominal size and iterator weight still agree, and the sketch keeps working and
round-trips. This one guards the catch path. It also passes on main, because no
hook can inject an `OutOfMemoryError` at the allocation itself.
- A temporary probe compared main and this branch over k ∈ {4, 6, 12, 50},
HRA and LRA, n up to 300,000, with and without a merge, using a fixed seed. All
112 cases matched: the serialized images (SHA-256), total buffer capacity,
retained count and nominal size.
- Full suite: 2,437 tests, 0 failures. `javac -Xlint:all
-Xdoclint:all,-missing` reports nothing in the changed files.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]