Skip to content

TDigest backed sketch aggregators#7331

Merged
jihoonson merged 6 commits intoapache:masterfrom
samarthjain:tdigestsketch
May 10, 2019
Merged

TDigest backed sketch aggregators#7331
jihoonson merged 6 commits intoapache:masterfrom
samarthjain:tdigestsketch

Conversation

@samarthjain
Copy link
Copy Markdown
Contributor

No description provided.

@samarthjain
Copy link
Copy Markdown
Contributor Author

samarthjain commented Mar 25, 2019

@jihoonson, @gianm - would one of you have some bandwidth to review this PR?

@jihoonson
Copy link
Copy Markdown
Contributor

Hi @samarthjain, I'm currently trying to finalize 0.14.0 release. I will take a look after the release.

@samarthjain
Copy link
Copy Markdown
Contributor Author

@jihoonson - would you have bandwidth now to review this PR?

@jihoonson
Copy link
Copy Markdown
Contributor

@samarthjain ah sorry. I forgot about this PR. Will take a look soon.

Comment thread distribution/pom.xml Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be org.apache.druid.extensions.contrib now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I initially built this against 0.12.2 since that is what we use at my day job. Fixed.

@jihoonson
Copy link
Copy Markdown
Contributor

Hi @samarthjain, now I'm reviewing your PR. Will leave some comments soon.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samarthjain sorry for the delayed review! Just left some comments. Also would you please resolve conflicts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should say "Casting to float type is not supported". Similar for getLong().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @Nullable for compression.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMRESSION -> COMPRESSION

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it different from TDigestBuildSketchAggregator.DEFAULT_COMPRESSION?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please raise an issue for this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you had a chance to file a Github issue for this? We usually do to track each issue correctly. I don't see any issues about this: https://github.com/apache/incubator-druid/issues/created_by/samarthjain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BufferAggregator doesn't have to be synchronized because it's not used in incremental index.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jihoonson - unfortunately the documentation on the base classes/interfaces doesn't clearly mention which methods could be called in a multi-threaded fashion. So I ended up following what the DataSketches implementation does.
For ex -
https://github.com/apache/incubator-druid/blob/master/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchBuildBufferAggregator.java#L54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's lame that the doc is missing about what should be synchronized. I think DataSketches implementations are wrong. It doesn't have to be synchronized because concurrent reads and writes can happen only in incremental index. You would see other BufferAggregator implementations of druid-core or druid-extensions-core don't do it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, when building an incremental index, are aggregators invoked? And is that BufferedAggregator or Aggregator. From your comments it sounds like we needn't worry about thread safety for BufferedAggregators but what about Aggregators? Looking at HistogramAggregator or HistogramBufferAggregator, I don't see any kind of synchronization.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a query is issued while a stream ingestion task is running, then the query would be routed to that task. This is when concurrent reads and writes can happen. Since only OnHeapIncrementalIndex is used at ingestion time which uses Aggregator, we need to consider if there's any concurrency issue between get() and aggregate(). Check out these comments: #5002 (comment), #5148 (comment)

I'm not sure why HistogramAggregator is not synchronized even though it looks to have to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have made the change to synchronize access for get() and aggregate()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems not necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be final.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. You don't have to synchronize these methods.

@jihoonson
Copy link
Copy Markdown
Contributor

I missed one more comment. Would you please add a document for this extension?

@jihoonson
Copy link
Copy Markdown
Contributor

Hi @samarthjain thank you for updating the PR. It looks that the PR is somehow messed up. Would you check it again please?

@samarthjain
Copy link
Copy Markdown
Contributor Author

@jihoonson - sorry about that. Looks like I pushed the garbage that Intellij generated. Fixed the commit by removing all the intellij related changes. I still haven't written the docs yet for tdigest. Working on them now.

@jihoonson
Copy link
Copy Markdown
Contributor

@samarthjain thanks for fixing it quickly! I'll take another look.


|property|description|required?|
|--------|-----------|---------|
|type|This String should always be "buildTDigestSketch"|yes|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be quantilesFromTDigestSketch

@Override
public synchronized Object get(final ByteBuffer buffer, final int position)
{
return sketches.get(buffer).get(position);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get() on the buffer aggregator needs to return a snapshot copy of the sketch to avoid use-after-free issues (see recently updated javadocs on get() and #7464)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for calling out this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we don't need to create a copy since sketches is an IdentityHashMap where buffer's reference only is used for equality purposes (i.e. it isn't effected by changes in the actual object). I have added a comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah, it makes sense since MergingDigest is stored on heap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to use an off-heap implementation in the future. Seems like there's no off-heap implementation currently.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest change looks good to me. +1 after CI.
Thanks @samarthjain!

@jihoonson jihoonson merged commit b542bb9 into apache:master May 10, 2019
@samarthjain
Copy link
Copy Markdown
Contributor Author

Thanks a lot for your reviews, @jihoonson . Would it be possible to merge this feature to 0.15-incubating branch as well? It is a new feature and since it is already reviewed and merged to master, I think it could make sense to include it in the next-to-be-out release as well. Further, this is a standalone module to so it won't be effecting the stability of the overall 0.15 release, either.

@jihoonson
Copy link
Copy Markdown
Contributor

Hi @samarthjain, our current release policy is time based release and we are branching out every 3 months. Once the branch is created, we are backporting only release blockers such as regression bug fixes, security bug fixes, or wrong license. Since the 0.15.0 branch was created on last Tuesday, this PR would be in 0.16.0 instead.

But I understand your concern. People usually expect their works to be included in the next release, but currently they are not in many cases. I think slow review is one of the reasons causing this issue. We may need to try to make the whole review process faster.

@fjy
Copy link
Copy Markdown
Contributor

fjy commented May 13, 2019

@jihoonson we should be tagging the release milestone to every merged PR

@jihoonson jihoonson added this to the 0.16.0 milestone May 13, 2019
@jihoonson
Copy link
Copy Markdown
Contributor

@fjy just tagged. Thanks.

jihoonson pushed a commit to implydata/druid-public that referenced this pull request Jun 26, 2019
* First set of changes for tDigest histogram

* Add license

* Address code review comments

* Add a doc page for new T-Digest sketch aggregators. Minor code cleanup and comments.

* Remove synchronization from BufferAggregators. Address code review comments

* Fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants