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

Fix nanos to millis conversion for tests #11856

Merged
merged 6 commits into from
Oct 29, 2022
Merged

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Oct 17, 2022

  • Fix some wrong division to calculate millis from nanos in tests,
    after commit that removes System.currentTimeMillis() calls.

    Follows: fb40a43
    Follows: Remove usages of System.currentTimeMillis() from tests #11749

  • Replace all sec, ms, ns calculations with TimeUnit conversion methods

  • Rename msec and millis to ms to have consistency across the code base

"ModCount: "
+ modCounts[j]
+ " Two fields took "
+ (finish - start) / 1_000_000
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could be less old-fashioned and just use TimeUnit.seconds(1).toNanos() here and in other places?....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean maybe: TimeUnit.NANOSECONDS.toMillis(finish-start) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way (constant to nanos or the value from nanos to millis).

@matriv matriv force-pushed the mt/fix-nanos-millis branch 2 times, most recently from aeec5aa to cc3e2e4 Compare October 17, 2022 11:53
@rmuir
Copy link
Member

rmuir commented Oct 17, 2022

thank you @matriv for following up here. I like the use of TimeUnit conversion (thanks @dweiss), very easy to read.

@matriv
Copy link
Contributor Author

matriv commented Oct 17, 2022

I pushed only for the wrong calculations, will let you know once I've converted all such divisions to use TimeUnit instead.

@@ -4190,7 +4190,7 @@ private static Status.SoftDeletsStatus checkSoftDeletes(
}

private static double nsToSec(long ns) {
return ns / 1000000000.0;
return ns / (double) TimeUnit.SECONDS.toNanos(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heads up for such changes in production code, could this potentially add overhead?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you're concerned about it, move it to a constant? I think it'll be negligible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestion for a "central" place to put this?

Copy link
Member

Choose a reason for hiding this comment

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

Nothing calls this gazillions of times, its only called once per "message" printed from checkindex, after it does a ton of work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx, Could you please check the PR?

Fix some wrong division to calculate millis from nanos in tests,
after commit that removes System.currentTimeMillis() calls.

Follows: fb40a43
Avoid error prone division with literals, in favour of TimeUnit
conversion methods.
For consistency, use `ms` instead of `msec` or `millis` everywhere
in the code base.
@matriv matriv requested review from rmuir and dweiss and removed request for rmuir and dweiss October 19, 2022 20:06
@dweiss
Copy link
Contributor

dweiss commented Oct 28, 2022

I think this is ready to be merged, sorry for the delay. One thing - could you add an appropriate lucene/CHANGES.txt entry?

@dweiss dweiss added this to the 9.5.0 milestone Oct 29, 2022
@dweiss dweiss self-assigned this Oct 29, 2022
@dweiss dweiss merged commit 3210a42 into apache:main Oct 29, 2022
dweiss pushed a commit to dweiss/lucene that referenced this pull request Oct 29, 2022
@matriv
Copy link
Contributor Author

matriv commented Nov 1, 2022

I think this is ready to be merged, sorry for the delay. One thing - could you add an appropriate lucene/CHANGES.txt entry?

@dweiss Thanks a lot for taking care, apologies, I was not online for the last few days and missed your message.

@dweiss
Copy link
Contributor

dweiss commented Nov 1, 2022

No worries. I added the missing entry manually. Thank you!

jpountz added a commit to mikemccand/luceneutil that referenced this pull request Nov 14, 2022
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