Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use count_hll for 'show series cardinality' queries #20745

Merged
merged 1 commit into from
Feb 10, 2021

Conversation

lesam
Copy link
Contributor

@lesam lesam commented Feb 10, 2021

Closes #20614

In addition to the query rewrites, fix a recent bug in seriesKey iteration exposed by the cardinality tests,
and add an extra tests for the recent ingress metric work.

@@ -2001,7 +2008,7 @@ func (is IndexSet) MeasurementSeriesKeyByExprIterator(name []byte, expr influxql
}
if ids == nil {
release()
return nil, nil
release = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For us to successfully use a nil measurementSeriesKeyByExprIterator, we would have to return a boxed nil, which is ugly.

Instead just set the ids to nil and the methods can check that.

Closes: influxdata#20614

Also fix nil pointer for seriesKey iterator

Fix for bug in: influxdata#20543

Also add a test for ingress metrics
@lesam lesam requested a review from davidby-influx February 10, 2021 19:21
@lesam lesam force-pushed the fix-nil-pointer-series-iterator branch from 62301f3 to 6711ca6 Compare February 10, 2021 19:21
@@ -202,6 +202,30 @@ func rewriteShowSeriesCardinalityStatement(stmt *influxql.ShowSeriesCardinalityS
}
}

// do hll estimation for per-measurement queries
if !stmt.Exact && stmt.Dimensions == nil && stmt.Limit == 0 && stmt.Offset == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could take these conditions off (except exact) but I think it would muddy the waters.

count_hll works for any kind of query, but the optimized series iteration only works for no dimension/limit/offset.

Copy link
Contributor

@davidby-influx davidby-influx left a comment

Choose a reason for hiding this comment

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

Minor questions about defensive programming.

@@ -1982,7 +1982,8 @@ func (itr *measurementSeriesKeyByExprIterator) Next() ([]byte, error) {
}

func (itr *measurementSeriesKeyByExprIterator) Close() error {
if itr == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to get rid of the itr == nil check? Would that be impossible? Having both seems more defensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd prefer the panic - nobody should be using a nil, and we usually don't check it I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dave Cheney is on my side here, which is good enough for me:

https://dave.cheney.net/practical-go/presentations/gophercon-singapore-2019.html#_never_use_nil_to_indicate_failure

Tip: Don’t check for a nil receiver, employ high test coverage and vet/lint tools to spot unhandled error conditions resulting in nil receivers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, we have that panic happening, and I have to figure it out. It looks like a failed cleanup from the creation of multiple iterators, which are all then closed, and some are nil while others were created.....

@@ -1933,7 +1933,7 @@ type measurementSeriesKeyByExprIterator struct {
}

func (itr *measurementSeriesKeyByExprIterator) Next() ([]byte, error) {
if itr == nil {
if itr.ids == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

As below on Close() - perhaps check for itr == nil as well.

@lesam lesam merged commit de1a0eb into influxdata:master-1.x Feb 10, 2021
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.

2 participants