Migrate from Yahoo DataSketches to Apache DataSketches 7.0.1 (KLL)#4774
Merged
Conversation
The com.yahoo.datasketches:sketches-core:0.8.3 dependency has been unmaintained since the project moved to Apache. Switch to the current org.apache.datasketches:datasketches-java:7.0.1 and adopt the KLL quantiles sketch, which the upstream maintainers recommend over the classic DoublesSketch for new code (faster, smaller, comparable accuracy at default K=200). DataSketchesOpStatsLogger changes: - On-heap throughout, matching the previous code (no off-heap usage). - KLL has no reset(); per-thread sketches are reassigned to a fresh newHeapInstance() under the existing StampedLock write lock. - KLL has no DoublesUnion; aggregation uses merge() directly into a freshly allocated KllDoublesSketch each rotation. - KllDoublesSketch.getQuantile() throws SketchesArgumentException on an empty sketch, so getQuantileValue() now guards with isEmpty() to preserve the prior NaN return. LICENSE bundles list datasketches-java-7.0.1.jar and the transitively required datasketches-memory-4.1.0.jar separately, since the two jars come from distinct upstream repositories.
Member
|
I previously submitted a similar PR (#4774), which wasn’t merged due to performance concerns at the time. This new PR seems to revisit that approach, so it might be worth taking another look. @merlimat @hangc0276 PTAL. |
Member
Author
@hezhangjian yes, I took your previous PR (#3264) into account. There's no reason to keep using the 10 year old dependency. |
merlimat
approved these changes
May 5, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
BookKeeper still depends on
com.yahoo.datasketches:sketches-core:0.8.3, which has been unmaintained since the project moved to the Apache Software Foundation and was renamed toorg.apache.datasketches:datasketches-java. A previous attempt to upgrade (#3264, May 2022) replaced the dependency 1:1 with the Apache classic-quantilesDoublesSketchbut never landed.Since #3264 two things have changed:
datasketches-java:7.0.1(which itself requires JDK ≥ 17).0.8.3datasketches-java#398 (comment). KLL is faster, more memory efficient, and has comparable accuracy at the default K. Migrating straight to KLL while we are touching this code avoids the near-term performance regression that Update datasketches version from 0.8.3 to 3.2.0 #3264 would have introduced.Changes
pom.xmlandstats/bookkeeper-stats-providers/prometheus-metrics-provider/pom.xml: dependency coordinate updated fromcom.yahoo.datasketches:sketches-core:0.8.3→org.apache.datasketches:datasketches-java:7.0.1.DataSketchesOpStatsLogger.java: ported toorg.apache.datasketches.kll.KllDoublesSketch.DoublesUnion; rotation aggregates withmerge()directly into a freshly allocatedKllDoublesSketch.newHeapInstance().reset(); per-thread sketches are reassigned to a freshnewHeapInstance()under the existingStampedLockwrite lock (the lock provides the happens-before edge that publishes the new reference safely).KllDoublesSketch.getQuantile()throwsSketchesArgumentExceptionon an empty sketch (vs the classic sketch returningNaN), sogetQuantileValue()now guards withisEmpty()to preserve the priorNaNreturn.LICENSE-all.bin.txt/LICENSE-server.bin.txt: listdatasketches-java-7.0.1.jarand the transitively-requireddatasketches-memory-4.1.0.jarseparately. The two jars are sourced from distinct Apache repositories (apache/datasketches-javaandapache/datasketches-memory), so each gets its own footnote —[25]retargeted to datasketches-java, and the previously-vacant[27]slot now references datasketches-memory.The CVE-2021-40531 OWASP suppression that #3264 added does not apply to 7.0.x, so no suppression is needed.
Verification
mvn -pl stats/bookkeeper-stats-providers/prometheus-metrics-provider -am dependency:tree -Dincludes=org.apache.datasketchesconfirms the resolved versions:datasketches-java:jar:7.0.1:compile→datasketches-memory:jar:4.1.0:compile(matches the LICENSE entries).mvn -pl stats/bookkeeper-stats-providers/prometheus-metrics-provider -am clean verifybuilds green; all 11 tests inTestPrometheusFormatterandTestPrometheusMetricsProviderpass.mvn -pl stats/bookkeeper-stats-providers/prometheus-metrics-provider -am spotbugs:check -DskipTests: no errors/warnings.