Skip to content

Fix executor scatter stats divide by zero issue#5895

Closed
mingjianliu wants to merge 3 commits intovitessio:masterfrom
mingjianliu:upstream1
Closed

Fix executor scatter stats divide by zero issue#5895
mingjianliu wants to merge 3 commits intovitessio:masterfrom
mingjianliu:upstream1

Conversation

@mingjianliu
Copy link
Copy Markdown

Fix a divide by zero bug
Signed-off-by: Mingjian Liu mingjianliu@pinterest.com

Signed-off-by: Mingjian Liu <mingjianliu@pinterest.com>
@mingjianliu mingjianliu requested a review from sougou as a code owner March 6, 2020 04:32
@saifalharthi
Copy link
Copy Markdown
Contributor

@bumbing Thanks for your contribution. Can you write a test for it?

Signed-off-by: Mingjian Liu <mingjianliu@pinterest.com>
@mingjianliu
Copy link
Copy Markdown
Author

@bumbing Thanks for your contribution. Can you write a test for it?

Added test, thanks!

AvgTimePerQuery: time.Duration(divideOrReturnZero(plan.ExecTime.Nanoseconds(), plan.ExecCount)),
PercentTimeOfReads: 100 * divideOrReturnZero(plan.ExecTime, readOnlyTime),
PercentTimeOfScatters: 100 * divideOrReturnZero(plan.ExecTime, scatterExecTime),
PercentCountOfReads: 100 * divideOrReturnZero(plan.ExecCount, readOnlyTime),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The change of readOnlyCount to readOnlyTime here looks unintentional?

PercentCountOfReads: float64(100 * plan.ExecCount / readOnlyCount),
PercentCountOfScatters: float64(100 * plan.ExecCount / scatterCount),
AvgTimePerQuery: time.Duration(divideOrReturnZero(plan.ExecTime.Nanoseconds(), plan.ExecCount)),
PercentTimeOfReads: 100 * divideOrReturnZero(plan.ExecTime, readOnlyTime),
Copy link
Copy Markdown
Collaborator

@dweitzman dweitzman Mar 7, 2020

Choose a reason for hiding this comment

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

Except for AvgTimePerQuery, seems like all of these are float64. You could just convert the arguments to float64 prior to division instead of after, which would avoid the panic since float64 has a concept of infinity and not-a-number.

If you do that, then for AvgTimePerQuery, maybe just add a one if-statement to check for a zero divisor inside this for-loop instead of a whole helper function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the comment. Let me close this one and simply make another one-line change for AvgTimePerQuery

Signed-off-by: Mingjian Liu <mingjianliu@pinterest.com>
@mingjianliu mingjianliu closed this Mar 8, 2020
@mingjianliu mingjianliu deleted the upstream1 branch March 8, 2020 04:59
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.

3 participants