msokolov commented on a change in pull request #1235: LUCENE-8929: parallel early termination sharing counts and max scores across leaves URL: https://github.com/apache/lucene-solr/pull/1235#discussion_r374969554
########## File path: lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java ########## @@ -690,4 +697,94 @@ public void testRandomMinCompetitiveScore() throws Exception { dir.close(); } + public void testConcurrentScoreboardTermination() throws Exception { + try(Directory dir = newDirectory(); + IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE))) { + Document doc = new Document(); + w.addDocuments(Arrays.asList(doc, doc, doc, doc, doc)); + w.flush(); + w.addDocuments(Arrays.asList(doc, doc, doc, doc, doc, doc)); + w.flush(); + w.addDocuments(Arrays.asList(doc, doc)); + w.flush(); + try (IndexReader reader = DirectoryReader.open(w)) { + assertEquals(3, reader.leaves().size()); + + Sort sort = new Sort(SortField.FIELD_DOC); + CollectorManager<TopFieldCollector, TopFieldDocs> manager = + TopFieldCollector.createSharedManager(sort, 2, null, 0); + TopFieldCollector collector = manager.newCollector(); + TopFieldCollector collector2 = manager.newCollector(); + assertNotNull(collector.maxScoreTerminator); + assertSame(collector.maxScoreTerminator, collector2.maxScoreTerminator); + assertEquals(0, collector.maxScoreTerminator.totalCollected); + assertEquals(2, collector.maxScoreTerminator.totalToCollect); + collector.maxScoreTerminator.setIntervalBits(0); + + LeafCollector leafCollector0 = collector.getLeafCollector(reader.leaves().get(0)); + LeafCollector leafCollector1 = collector2.getLeafCollector(reader.leaves().get(1)); + LeafCollector leafCollector2 = collector2.getLeafCollector(reader.leaves().get(2)); + + leafCollector1.collect(0); + leafCollector0.collect(0); // we have collected numHits=2 docs, but there are better ones remaining + expectThrows(CollectionTerminatedException.class, () -> leafCollector1.collect(1)); + expectThrows(CollectionTerminatedException.class, () -> leafCollector0.collect(1)); // now we have all the top docs + expectThrows(CollectionTerminatedException.class, () -> leafCollector2.collect(0)); + } + } + } + + public void testRandomMaxScoreTermination() throws Exception { Review comment: Good idea - I'll try it! There is definitely the potential for a lurking bug here. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org