prudhvigodithi opened a new pull request, #17027:
URL: https://github.com/apache/lucene/pull/17027

   ### Description
   
   **Background**
   
   Wildcard, regexp and fuzzy queries find their matching terms with 
`Terms#intersect`, which for the default codec walks the terms dictionary in 
`IntersectTermsEnum`. When the pattern matches few terms and can't skip parts 
of the dictionary, such as a leading wildcard like `*foo`, a single call to 
`next()` can scan most of the dictionary before it returns.
   
   `ExitableDirectoryReader` only checks its `QueryTimeout` between the terms 
that `next()` returns. During that one long call nothing is checked, so a query 
that has timed out or been cancelled keeps running until the scan ends, using a 
full CPU core the whole time. Under load these queries pile up and can saturate 
the CPU.
   
   **This change**
   
   `IntersectTermsEnum` now checks the timeout every 512 steps while it scans, 
so the scan stops shortly after the query times out or is cancelled. With no 
timeout set, behavior is unchanged. 
   
   The timeout is passed down with a new `Terms#intersect(CompiledAutomaton, 
BytesRef, QueryTimeout)`, which `ExitableDirectoryReader` calls. A new 
`QueryTimeout#throwIfShouldExit()` lets the caller choose which exception is 
thrown.
   
   This applies to `WildcardQuery`, `RegexpQuery`, `FuzzyQuery`, and other 
automaton queries, on the default block tree terms dictionary, including the 
older format in backward-codecs.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to