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

Optimise rejection of out-of-range long values #40325

Conversation

DaveCTurner
Copy link
Contributor

Today if you try and insert a very large number like 1e9999999 into a long
field we first construct this number as a BigDecimal, convert this to a
BigInteger and then reject it because it is out of range. Unfortunately
making such a large BigInteger is rather expensive.

We can avoid this expense by performing a (weaker) range check on the
BigDecimal representation of incoming longs too.

Relates #26137
Closes #40323

Today if you try and insert a very large number like `1e9999999` into a long
field we first construct this number as a `BigDecimal`, convert this to a
`BigInteger` and then reject it because it is out of range. Unfortunately
making such a large `BigInteger` is rather expensive.

We can avoid this expense by performing a (weaker) range check on the
`BigDecimal` representation of incoming `long`s too.

Relates elastic#26137
Closes elastic#40323
@DaveCTurner DaveCTurner added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0 v8.0.0 v7.2.0 labels Mar 21, 2019
@DaveCTurner DaveCTurner requested a review from jpountz March 21, 2019 17:25
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

Good catch. The change looks good to me. I'm wondering whether the timeouts on tests are left-overs?

@@ -27,19 +28,26 @@

public class NumbersTests extends ESTestCase {

@Timeout(millis = 10000)
Copy link
Contributor

Choose a reason for hiding this comment

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

does it take that long?

@@ -367,17 +368,20 @@ public void testEmptyName() throws IOException {
}
}

@Timeout(millis = 30000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it taking that long?

@DaveCTurner
Copy link
Contributor Author

I was unsure about whether to include these timeouts. The tests complete in milliseconds today with the fix, but I'm nervous about short timeouts adding to CI flakiness. Without the fix or the timeout these tests take a very long time to fail which I think isn't great either. I don't feel strongly, however, and will take them out if you think it better.

@DaveCTurner DaveCTurner merged commit f63ac13 into elastic:master Mar 28, 2019
@DaveCTurner DaveCTurner deleted the 2019-03-21-40323-avoid-big-integer-if-possible branch March 28, 2019 12:13
DaveCTurner added a commit that referenced this pull request Mar 28, 2019
Today if you try and insert a very large number like `1e9999999` into a long
field we first construct this number as a `BigDecimal`, convert this to a
`BigInteger` and then reject it because it is out of range. Unfortunately
making such a large `BigInteger` is rather expensive.

We can avoid this expense by performing a (weaker) range check on the
`BigDecimal` representation of incoming `long`s too.

Relates #26137
Closes #40323
DaveCTurner added a commit that referenced this pull request Mar 28, 2019
Today if you try and insert a very large number like `1e9999999` into a long
field we first construct this number as a `BigDecimal`, convert this to a
`BigInteger` and then reject it because it is out of range. Unfortunately
making such a large `BigInteger` is rather expensive.

We can avoid this expense by performing a (weaker) range check on the
`BigDecimal` representation of incoming `long`s too.

Relates #26137
Closes #40323
jasontedor added a commit to rjernst/elasticsearch that referenced this pull request Mar 28, 2019
* master: (25 commits)
  [DOCS] Correct keystore commands for Email and Jira actions in Watcher (elastic#40417)
  [DOCS] Document common settings for snapshot repository plugins (elastic#40475)
  Remove with(out)-system-key tests (elastic#40547)
  Geo Point parse error fix (elastic#40447)
  Handle null retention leases in WaitForNoFollowersStep (elastic#40477)
  [DOCS] Adds anchors for ruby client (elastic#39867)
  Mute DataFrameAuditorIT#testAuditorWritesAudits
  Disable integTest when Docker is not available (elastic#40585)
  Add randomScore function in script_score query (elastic#40186)
  Test fixtures krb5 (elastic#40297)
  Correct ILM metadata minimum compatibility version (elastic#40569)
  SQL: Centralize SQL test dependencies version handling (elastic#40551)
  Mute testTracerLog
  Mute testHttpInput
  Include functions' aliases in the list of functions (elastic#40584)
  Optimise rejection of out-of-range `long` values (elastic#40325)
  Add docs for cluster.remote.*.proxy setting (elastic#40281)
  Migrate systemd packaging tests from bats to java (elastic#39954)
  Move top-level pipeline aggs out of QuerySearchResult (elastic#40319)
  Use openjdk 12 in packer cache script (elastic#40498)
  ...
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Mar 29, 2019
* elastic/7.0: (50 commits)
  Fix more broken links in plugins docs
  Fix archives links in plugins docs
  Disable integTest when Docker is not available (elastic#40585)
  Add docs for bundled jdk (elastic#40487)
  [DOCS] Correct keystore commands for Email and Jira actions in Watcher (elastic#40417) (elastic#40613)
  Add usage indicators for the bundled JDK (elastic#40616)
  Add ability to mute and mute flaky fixture (elastic#40630)
  Test fixtures krb5 (elastic#40297)
  Update docs for the DFR similarity (elastic#40579)
  Update ingest jdocs that a null return value will drop the current document. (elastic#40359)
  [DOCS] Document common settings for snapshot repository plugins (elastic#40475) (elastic#40607)
  [DOCS] Fixes formatting in breaking changes
  Handle null retention leases in WaitForNoFollowersStep (elastic#40477)
  Correct ILM metadata minimum compatibility version (elastic#40569)
  Mute SpecificMasterNodesIT.testElectOnlyBetweenMasterNodes()
  Mute testHttpInput
  Include functions' aliases in the list of functions (elastic#40584)
  Optimise rejection of out-of-range `long` values (elastic#40325)
  Add docs for cluster.remote.*.proxy setting (elastic#40281)
  Mute WatchAckTests.testAckAllActions
  ...
DaveCTurner added a commit that referenced this pull request Apr 5, 2019
Today if you try and insert a very large number like `1e9999999` into a long
field we first construct this number as a `BigDecimal`, convert this to a
`BigInteger` and then reject it because it is out of range. Unfortunately
making such a large `BigInteger` is rather expensive.

We can avoid this expense by performing a (weaker) range check on the
`BigDecimal` representation of incoming `long`s too.

Relates #26137
Closes #40323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v6.7.2 v7.0.0-rc2 v7.2.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feeding non-numeric data into a long field may consume excessive CPU
4 participants