[ 
https://issues.apache.org/jira/browse/OAK-4096?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15673865#comment-15673865
 ] 

Thomas Mueller commented on OAK-4096:
-------------------------------------

Not quite sure if I understand the requirement, should the query throw an 
exception or simply stop returning results if the limit is reached? Proposed 
patch (untested):

{noformat}
### Eclipse Workspace Patch 1.0
#P oak-lucene
Index: 
src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
===================================================================
--- 
src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java   
    (revision 1770130)
+++ 
src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java   
    (working copy)
@@ -164,6 +164,8 @@
     static final int LUCENE_QUERY_BATCH_SIZE = 50;
 
     static final boolean USE_PATH_RESTRICTION = 
Boolean.getBoolean("oak.luceneUsePath");
+    
+    static final int MAX_RELOAD_COUNT = 
Integer.getInteger("oak.luceneMaxReloadCount", 16);
 
     protected final IndexTracker tracker;
 
@@ -289,6 +291,7 @@
             private int nextBatchSize = LUCENE_QUERY_BATCH_SIZE;
             private boolean noDocs = false;
             private long lastSearchIndexerVersion;
+            private int reloadCount;
 
             @Override
             protected LuceneResultRow computeNext() {
@@ -351,7 +354,7 @@
                         TopDocs docs;
                         long time = System.currentTimeMillis();
                         checkForIndexVersionChange(searcher);
-                        while (true) {
+                        while (reloadCount < MAX_RELOAD_COUNT) {
                             if (lastDoc != null) {
                                 LOG.debug("loading the next {} entries for 
query {}", nextBatchSize, query);
                                 docs = searcher.searchAfter(lastDoc, query, 
nextBatchSize);
@@ -457,9 +460,10 @@
             private void checkForIndexVersionChange(IndexSearcher searcher) {
                 long currentVersion = LucenePropertyIndex.getVersion(searcher);
                 if (currentVersion != lastSearchIndexerVersion && lastDoc != 
null){
+                    reloadCount++;
                     lastDoc = null;
                     LOG.debug("Change in index version detected {} => {}. 
Query would be performed without " +
-                            "offset", currentVersion, 
lastSearchIndexerVersion);
+                            "offset; reload {}", currentVersion, 
lastSearchIndexerVersion, reloadCount);
                 }
                 this.lastSearchIndexerVersion = currentVersion;
             }

{noformat}

> Limit the number of times a LuceneResultRow based iterator get reset
> --------------------------------------------------------------------
>
>                 Key: OAK-4096
>                 URL: https://issues.apache.org/jira/browse/OAK-4096
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: lucene
>            Reporter: Chetan Mehrotra
>            Assignee: Thomas Mueller
>            Priority: Minor
>             Fix For: 1.6
>
>
> With changes done in OAK-2569 it can happen that the cursor returned by 
> {{LucenePropertyIndex}} gets reset multiple times as the index gets updated 
> for a long running query
> {noformat}
> 11697: 26.02.2016 16:12:16.296 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex ... took 3690 ms
> 47507: 26.02.2016 16:13:26.744 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex loading the next 
> 12800 entries for query :fulltext:foo
> 47513: 26.02.2016 16:13:30.486 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex ... took 3742 ms
> 55832: 26.02.2016 16:15:43.693 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex loading the next 
> 25600 entries for query :fulltext:foo
> 55835: 26.02.2016 16:15:51.261 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex ... took 7568 ms
> 59383: 26.02.2016 16:21:12.355 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex Change in index 
> version detected 4186634 => 4186631. Query would be performed without offset
> 59384: 26.02.2016 16:21:12.355 *DEBUG* [qtp567069427-14229] 
> org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndex loading the first 
> 51200 entries for query :fulltext:foo
> {noformat}
> If the index continuously gets updated then such a query would never finish 
> and would consume system resources.  For such case we should enforce some 
> limit



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to