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

[BUG] Sorted Order Assertion in LongHashSet.java is incorrect #17206

Open
Shailesh-Kumar-Singh opened this issue Jan 30, 2025 · 0 comments · May be fixed by #17207
Open

[BUG] Sorted Order Assertion in LongHashSet.java is incorrect #17206

Shailesh-Kumar-Singh opened this issue Jan 30, 2025 · 0 comments · May be fixed by #17207
Labels
bug Something isn't working Search Search query, autocomplete ...etc

Comments

@Shailesh-Kumar-Singh
Copy link
Contributor

Describe the bug

The assertion logic in LongHashSet.java assumes signed long values, which leads to incorrect validation when dealing with unsigned long values. The sorted order check fails because value >= previousValue does not correctly handle unsigned comparisons.

Related component

Search

To Reproduce

  1. Run ./gradlew run
  2. Create the Index
    PUT test_index
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "stat": {
        "type": "unsigned_long"
      },
      "latency": {
        "type": "long"
      }
    }
  }
}
  1. Ingest sample documents
  2. Run Query -
    POST test_index/_search
{
  "query": {
    "terms": {
      "stat": [
        "9223372036854775814",
        "9223372036854775812",
        "9223372036854775811",
        "1"
      ]
    }
  },
  "aggs": {
    "sum_size": {
      "sum": {
        "field": "latency"
      }
    }
  }
}
  1. We get - [Please check Additional Details below for Stack trace]
»  fatal error in thread [opensearch[runTask-0][search][T#1]], exiting
»  java.lang.AssertionError: values must be provided in sorted order
FAILURE: Build failed with an exception. 

Expected behavior

In the normal flow, the query should correctly apply Terms aggregations without assertion errors.

Additional Details

Stack Trace

»  java.lang.AssertionError: values must be provided in sorted order
»       at org.apache.lucene.util.LongHashSet.assertBasedOnDataType(LongHashSet.java:68)
»       at org.apache.lucene.util.LongHashSet.<init>(LongHashSet.java:55)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery.<init>(SortedUnsignedLongDocValuesSetQuery.java:48)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery$2.<init>(SortedUnsignedLongDocValuesSetQuery.java:150)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery.newSlowSetQuery(SortedUnsignedLongDocValuesSetQuery.java:150)
»       at org.opensearch.index.mapper.NumberFieldMapper$NumberType$8.termsQuery(NumberFieldMapper.java:1168)
»       at org.opensearch.index.mapper.NumberFieldMapper$NumberFieldType.termsQuery(NumberFieldMapper.java:1577)
»       at org.opensearch.index.query.TermsQueryBuilder.doToQuery(TermsQueryBuilder.java:556)
»       at org.opensearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:117)
»       at org.opensearch.index.query.QueryShardContext.lambda$toQuery$3(QueryShardContext.java:575)
»       at org.opensearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:587)
»       at org.opensearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:574)
»       at org.opensearch.search.SearchService.parseSource(SearchService.java:1374)
»       at org.opensearch.search.SearchService.createContext(SearchService.java:1110)
»       at org.opensearch.search.SearchService.executeQueryPhase(SearchService.java:707)
»       at org.opensearch.search.SearchService$2.lambda$onResponse$0(SearchService.java:680)
»       at org.opensearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:74)
»       at org.opensearch.action.ActionRunnable$2.doRun(ActionRunnable.java:89)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59)
»       at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:994)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
»       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
»       at java.base/java.lang.Thread.run(Thread.java:1583)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Search Search query, autocomplete ...etc
Projects
Status: 🆕 New
2 participants