kkewwei commented on issue #16495:
URL: https://github.com/apache/lucene/issues/16495#issuecomment-5237051851

   @sgup432 Yes, the idea is to `prewarm` query cache entries for newly created 
segments after segment merge.
   
   I think there are two main questions to answer:
   
   1. Which queries should be `prewarmed`?
   2. When should the `prewarming` happen?
   
   For the first question, we can select candidate queries from 
`uniqueCacheKeys`. This structure is backed by a `LinkedHashMap`, so it already 
preserves LRU ordering. We can derive the most recently used queries like this:
   
   ```java
   List<Query> queries = cachedQueries();
   Collections.reverse(queries);
   return queries.stream().distinct().limit(maxQueries).toList();
   ```
   
   This gives us a bounded set of recently used cached queries that are most 
likely to benefit from prewarming.
   
   For the second question, the best timing seems to be after the merged 
segment has been created but before `commitMerge`, using the existing 
`IndexWriter` merged segment warmer hook:
   
   ```java
   final IndexReaderWarmer mergedSegmentWarmer = 
config.getMergedSegmentWarmer();
   if (readerPool.isReaderPoolingEnabled() && mergedSegmentWarmer != null) {
     ...
     mergedSegmentWarmer.warm(sr);
   }
   ```
   
   At this point, the new `SegmentReader` is available, but the merged segment 
is not visible to searchers yet. This allows us to build query cache entries 
for the new segment before it starts serving queries.


-- 
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