Repository navigation
Read Solr results larger than a page in growing pages - #5127
Merged
porunov merged 1 commit intoOct 24, 2026
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unlimited reads can continue chasing sustained concurrent inserts without reaching exhaustion.
1 open issue
What changed in this PR
This PR addresses #5126 by growing Solr result pages to reduce repeated offset-query work and revising termination checks to prevent reads from waiting indefinitely after deletions. It also prepares Solr for the broader mixed-index ordering use in #5125.
Changes:
- Adds configurable page growth while preserving query limits and explicit
rowsparameters. - Aligns direct-query pagination and totals with the effective
start. - Adds regression coverage and documents paging behavior and concurrent-update limitations.
| File | Description |
|---|---|
| janusgraph-solr/src/test/java/org/janusgraph/diskstorage/solr/SolrResultIteratorTest.java | Tests page growth, limits, and termination. |
| janusgraph-solr/src/test/java/org/janusgraph/diskstorage/solr/SolrIndexTest.java | Checks outgoing page requests and direct-query totals. |
| janusgraph-solr/src/test/java/org/janusgraph/diskstorage/solr/SolrIndexKerberosKeytabTest.java | Enables growing pages in Kerberos tests. |
| janusgraph-solr/src/test/java/org/janusgraph/diskstorage/solr/JanusGraphSolrContainer.java | Configures small growing pages for container tests. |
| janusgraph-solr/src/main/java/org/janusgraph/diskstorage/solr/SolrResultIterator.java | Implements growing pages and revised exhaustion checks. |
| janusgraph-solr/src/main/java/org/janusgraph/diskstorage/solr/SolrIndex.java | Wires the page cap and effective query offset. |
| janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java | Updates the batch-size option description. |
| janusgraph-backend-testutils/src/main/java/org/janusgraph/diskstorage/indexing/IndexProviderTest.java | Adds cross-backend pagination and concurrent-update tests. |
| docs/index-backend/solr.md | Explains paging settings and consistency limitations. |
| docs/configs/janusgraph-cfg.md | Documents the new option and revised batch behavior. |
| docs/changelog.md | Records pagination improvements and behavior changes. |
Review effort: Balanced
Fixes JanusGraph#5126 SolrIndex read a result larger than a page (max-result-set-size) in pages of that size at offsets. For each page, Solr collects and sorts every hit before its offset again, so a result read whole took time which grew with the square of its size: on Solr 9.10.1, g.V().has('name').order().by('name') read 31,846 hits in 5.9 s in pages of 50 and in 0.52 s in pages of 1,000. And SolrResultIterator read on until it had as many hits as its first page had found, asking for a page only where the hits read so far filled whole pages, so a read which fell short of that number, as where another transaction deleted some of its hits meanwhile, waited forever on its queue. The first page of a result still holds max-result-set-size hits, or the limit if that is less, so that a query which a page holds is one request as before. Every page after it now holds twice as many hits as the page before, up to the new option index.[X].solr.max-page-size, 10,000 by default, but never more than the limit leaves. The pages only grow while the result is read on, so a read which stops early asks for no more than twice the hits it takes, plus a first page. A value no larger than max-result-set-size reads every result in pages of that size, as before. A direct index query with a rows parameter, which reaches Solr as it is, is read in pages of its rows, but its later pages now ask for no more hits than its limit leaves. A start which a parameter sets now carries over to the later pages, and totals count the hits from it. The requests are otherwise those of master, with the same sort. A read still takes no more hits than its first page found after its start, as on master, so that hits which other transactions add meanwhile can't keep it going; its last page now asks for no more. And it now also ends with a page which comes back empty, or after which Solr found no more hits, as the count of that page says, where it waited forever for the hits which the first page found. A page may come back short while more hits remain: a distributed request leaves out a document which was deleted between its phases, and takes it off its count. A count which isn't exact, as where a request sets minExactCount, is a lower bound past the page, so it ends no read; and as the count of the first page may then be a lower bound too, it bounds no read of a query which sets minExactCount. Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com> Co-authored-by: Oleksandr Porunov <alexandr.porunov@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
porunov
force-pushed
the
solr-reads-results-in-growing-pages
branch
from
October 24, 2026 03:35
6705373 to
d958f68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #5126
On Solr, JanusGraph read a result larger than a page (
index.[X].max-result-set-size, 50 by default) in pages of that size, each at its offset:SolrResultIteratorasked for each page after the first withstartset to the number of hits before it. For each page, Solr collects and sorts every hit before its offset again, so a result read whole took time which grew with the square of its size. On Solr 9.10.1,g.V().has('name').order().by('name')read 31,846 hits in 5.9 s in pages of 50 and in 0.52 s in pages of 1,000, and itsrange(20000, 20010)took 2.9 s in pages of 50. Every read of a Solr result larger than a page paid it:has(key).order().by(key), an unorderedhas(key)read whole, a limit larger than a page, a direct index query without a limit.And such a read waited forever where another transaction deleted some of its hits meanwhile, as where a traversal reads on while another one removes some of the elements it finds:
SolrResultIteratorread on until it had as many hits as its first page had found, and asked for a page only where the hits read so far filled whole pages, so a read which fell short of that number waited on its empty queue for the rest.The first page of a result still holds
max-result-set-sizehits, or the limit if that is less, and every page after it now holds twice as many as the page before, up to the new optionindex.[X].solr.max-page-size(10,000 by default), but never more than the limit leaves: 50, 100, 200 and so on. A read still takes no more hits than its first page found, but now also ends with a page which comes back empty, or after which Solr found no more hits, as that page's count says. This removes a cost which the upcoming change #5125 would otherwise expose for plainorder().by(key)traversals on Solr.Changes
SolrIndex.MAX_PAGE_SIZE(new),index.[X].solr.max-page-size: the largest page, MASKABLE, positive, 10,000 by default, among the options of both modes. Its description says how the pages grow, what larger pages trade, why 10,000, and that a value no larger thanmax-result-set-sizereads every result in pages of that size, as before.SolrResultIteratorreads the next page once the hits before have left its queue empty, at the offset of the hits read so far (the query'sstartplus them), asking for twice the rows of the page before, up to the largest page, but no more than what the limit and the count of the first page leave. A largest page no larger than the first page keeps every page at the first page's size.numFound) is no larger than the offset after it. So a result which a page holds is one request, as before, and a result whose last page comes back full takes no further request.QueryComponent.regularFinishStage), and the read goes on from the offset of the hits read, as the deletion moved the hits after the deleted document one place forward.minExactCount, is a lower bound past the page, so it ends no read: Solr counts the hits exactly at least up to the end of the page.minExactCountisn't bounded by it, as that count may then be a lower bound.SolrIndex.query(IndexQuery …)andquery(RawQuery …)passmax-page-sizeas the largest page, except for a direct index query with arowsparameter, which reaches Solr as it is: such a query passes itsrows, and is read in pages of that size. No other parameter keeps the pages from growing: pages at offsets of any size go alike with the others, such asdefType, re-ranking (rq) ortimeAllowed. Two things change for direct index queries with parameters, as the iterator now sets the offset and the rows of every page: the later pages of one with arowsparameter ask for no more hits than its limit leaves (rows100 with a limit of 150 reads pages of 100 and 50, where master asked for 100 twice), and astartwhich a parameter sets carries over to the later pages, which master read at the query's offset plus the pages before. The requests are otherwise those of master, with the same sort, or none.SolrIndex.totalscounts the hits from the start of the query, which a parameter may set, as its read returns them, rather than from its offset: with astartparameter of 24 on 40 documents, 16 rather than 40. Master returned 40 hits for that read as well, those from 24 and then those from 3 on.index.[X].max-result-set-sizesays in its description that Solr reads the pages after the first larger, up tomax-page-size.docs/configs/janusgraph-cfg.mdhas its row and the new option's asConfigurationPrinterwrites them.max-page-size): 3, 6, 12, 12 and so on, so that every Solr test which reads more than a page reads growing pages, and those which read 21 hits or more reach the largest, as the count of the first page trims the last page.totals, and what a read sees while the index changes. No page described the paging of Solr before.Tests
SolrResultIteratorTest(new) reads from a mockedSolrClient, which answers each request with the ids of a list at its offset, as many as it asks for, with their count, and records the offset and the rows of each request. A test may change the list between pages, as other transactions change an index, and mark an id as lost between the phases of a request, which leaves it out of its page and of its count.pagesDoubleUpToTheLargestPage: 100 ids in pages of 3 up to 10 are read at (offset, rows)(0,3) (3,6) (9,10) (19,10) … (89,10) (99,1), the last page asking for the one id which the first page's count leaves.pagesStopAtTheLimit: from an offset of 5 with a limit of 20,(5,3) (8,6) (14,10) (24,1).pagesKeepTheQueryRowsWhereTheLargestPageIsNoLarger: a largest page of 2, with pages of 3, reads(0,3) (3,3) (6,3) (9,1).aReadEndsWithTheResultsWhichItsFirstPageFound: 3 ids take one request, 10 ids three, the last one(9,1), 9 ids two, and 3 ids from an offset of 17 of 20 one.thePageAfterWhichSolrFoundNoMoreIsTheLast: from an offset of 5 of 20 ids,d18andd19are deleted after the first page, so that the third page,(14,6), comes back with 4 ids and a count of 18, which ends the read withd5tod17and no further request.aPageWhichComesBackShortWhileMoreRemainIsNotTheLast: of 20 ids,d5is lost between the phases of the second page, which comes back with 5 ids and a count of 19; the read goes on at(8,10) (18,2)and returns the other 19.aPageWhichComesBackEmptyEndsTheRead: of 20 ids, the 6 of the second page are all lost between its phases, so that it comes back empty with a count of 14, which ends the read with the first 3 ids; asking for more once the read ended sends no request.aPageLargerThanTheLimitReturnsTheLimit: a page of 10 rows under a limit of 5, as the rows of a parameter make it, returns 5 ids, in one request.aReadWhichFindsFewerResultsThanItsFirstPageEnds: 2 of 10 ids, one read and one not, are deleted after the first page; the read, in pages of 3, ends within 10 s with 8 ids, having skippedd3, which the offsets moved past.aReadWhichFindsResultsAddedMeanwhileEnds: one id is added at the end of 20 for every one which the read takes, so that every page comes back full and its count stays beyond its end; the read ends within 10 s with the 20 ids which its first page found, at(0,3) (3,6) (9,10) (19,1).aCountWhichMayBeALowerBoundBoundsNoRead: withminExactCount, the mock counts exactly up to the end of each page and reports just past it beyond, the least which Solr may report, so that the first page finds 4 of 20 ids; the read isn't bounded by that count and takes all 20, at(0,3) (3,6) (9,10) (19,10).SolrIndexTest.resultsLargerThanAPageAreReadInGrowingPagesrecords the parameters of the searches which SolrJ sends, through a request interceptor ofHttpClientUtil, for 40 documents, in pages of 3 up to 12 as the tests' configuration has them:timeis read at(0,3) (3,6) (9,12) (21,12) (33,7), the last page asking for the 7 documents which the first page's count leaves, sorted bytime ascalone, and with a limit of 20 at(0,3) (3,6) (9,11); an unordered one in the same pages without a sort; a limit of 3 and a result of 3 documents are one request each;(2,3) (5,6) (11,12) (23,12) (35,5);rows,defType, it is read in growing pages too,(0,3) (3,6) (9,1)for 10 documents; withrows2 and a limit of 5 at(0,2) (2,2) (4,1); withrows10 and a limit of 5 at(0,10), returning 5; withstart24 at(24,3) (27,6) (33,7), returning 16; and itstotalstake one request, and count 40, or 16 from thatstart.IndexProviderTest.resultsOfSeveralPagesComeWholeInOneOrderWhateverTheirLimit(every index backend; pages of 3 on Elasticsearch and Solr, growing up to 12 on Solr). 20 documents with ties ontimeand onname, of which the second half is written first, in a transaction of its own.timeand byname, and by both: each returns every document once and in order, and with limits from 1 to 21 the start of its whole result.time:[0 TO *], without an order, ascending bytimeand descending byname, and oftext:(alpha beta)by relevance, where the second half holds both words and the first half one: offsets from 0 to 21 with limits from 1 to 7 or none return the slice of the whole result, whichtotalscounts; by relevance, the second half comes first.IndexProviderTest.readsOfSeveralPagesEndWhileDocumentsAreDeletedOrAdded(every index backend): a read of 10 documents, ordered bytimeand unordered, during which another transaction deletes the first document read and another one, and adds two in the middle of the order to the ordered read, ends within 60 s with documents of the result alone. Elasticsearch reads all its pages in the state of the index at the first one, and Lucene every hit at once; Solr reads each page at its offset in the state of the moment, which may skip or repeat a document.Mutations, each reverting or breaking one part of the change, run on Solr 9.10.1 in the JVM: 21 of 22 are caught, and the last one is equivalent.
(21,19)for(21,12) (33,7), and seven iterator testspagesStopAtTheLimit:(24,10)for(24,1)aPageWhichComesBackShortWhileMoreRemainIsNotTheLast: 8 ids of 19startthePageAfterWhichSolrFoundNoMoreIsTheLast: one more request,(18,2), from an offset of 5aPageWhichComesBackEmptyEndsTheRead: asking for more once the read ended reads onaReadWhichFindsResultsAddedMeanwhileEndstimes out after 10 s; the request test, 12 rows for 7; five other iterator testsminExactCountaCountWhichMayBeALowerBoundBoundsNoRead: 4 ids of 20thePageAfterWhichSolrFoundNoMoreIsTheLast,(14,10)for(14,6)startpagesKeepTheQueryRowsWhereTheLargestPageIsNoLarger:(3,2) (5,2) …aPageLargerThanTheLimitReturnsTheLimitand the request test: 10 for 5rowsparameter read in pages of one sizerowsparameter read in growing pages(2,3)for(2,2) (4,1)withrows2(3,3) (6,3) (9,1)for(3,6) (9,1)withdefTyperowsparameter read in pages ofmax-result-set-sizerather than theirrows(2,3)for(2,2) (4,1)withrows2(21,19)for(21,12) (33,7)totalscounted from the query's offset rather than from the start which a parameter setsrowsparameter given a largest page of 0 rather than theirrowsOn master, with these tests:
readsOfSeveralPagesEndWhileDocumentsAreDeletedOrAddedfails on Solr in the JVM: the unordered read, which loses two documents and gains none, times out after 60 s. The ordered one, which gains as many as it loses, passes.resultsLargerThanAPageAreReadInGrowingPagesfails at its first check: pages of 3,(0,3) (3,3) ….resultsOfSeveralPagesComeWholeInOneOrderWhateverTheirLimitpasses, as master reads every page at its offset in the same order.SolrResultIteratorTestcalls the iterator's new constructor.janusgraph-solrjar against Solr 9.10.1 in a container: with master's, it is still waiting after 30 s, having returned[n0, n1, n2, n4, n5, n6, n7, n8]; with this change, it returns[n0, n1, n2, n4, n5, n6, n7, n8, n9],n3skipped by the offsets.Locally, Java 11, on this change as it stands, with checkstyle (no violations):
SolrRunner's MiniSolrCloud, with pages of 3 growing up to 12 as in the tests' configuration:JanusGraphIndexTestasBerkeleySolrTestconfigures it (138, 1 skipped), with the harness'scollections.txtgiven thelistPropertyOrderingcollection, which the in-JVM harness lacks, andIndexProviderTestwithSolrIndexTest's tests asSolrIndexWithoutKerberosTestconfigures them (268, 117 skipped) pass, and so do the tests ofjanusgraph-solrwhich need no container:SolrResultIteratorTest(11),SolrIndexQueryFilterTest(10),SolrIndexCreateCollectionRequestTest(5),GeoToWktConverterTest(6),SolrIndexDateFormatTest(1) andStandardTokenizerTest(1). The three new tests andsingleStoreofSolrIndexKerberosKeytabTest, which CI leaves out, pass under Kerberos (4).-Psolr8) and on Solr 9.10.1 in a container,SolrIndexWithoutKerberosTest's three new tests,testScrollandsingleStore(5 on each), and eight tests ofBerkeleySolrTestwhich read results of several pages in order,testIndexing,testRawQueries,testRawQueriesWithParameters,testOrderingListProperty,testOrderByWithRange,testOrderLeavesOutTheElementsWithoutAKeyItOrdersBy,testMixedIndexOrdersElementsWithoutTheKeyLastandtestStringsAreOrderedByCodePoint(8 on each), pass.janusgraph-driver(132),janusgraph-core(245),janusgraph-inmemory(717, 85 skipped),janusgraph-test(1,132),janusgraph-berkeleyje(399, 12 skipped) andjanusgraph-lucene(472, 148 skipped), whose code this change leaves as it was but for the description ofmax-result-set-sizeand the two new tests ofIndexProviderTest, pass, and so do the two new tests,testScrollandsingleStoreofElasticsearchIndexTestagainst Elasticsearch 9.5.4 in a container (4).Notes
No cursor. An earlier version of this change read such results through a cursor (
cursorMark), each page after the last hit of the page before, which would also have kept the pages exact while other transactions change the index. A/B timings of that version showed its costs: on an index of one shard, a cursor page still visits every match, about 1 ms a page against about 10 ms for an offset page of 50, so the number of pages remains the lever; it read unsorted results 27–48% and a limit of two pages 79% more slowly than master; and a cursor needs a sort which ends with the uniqueKey, which the example schema (version 1.5,stringwithout docValues) makes Solr uninvert into the heap of every core, which can take a gigabyte or more per replica of a large collection. A cursor could follow where the key field has docValues, for exact reads under concurrent changes.Why 10,000. It is Elasticsearch's largest page by default (
index.max_result_window), and with it the 31,846 hits of the benchmark take 10 requests: 50, 100, …, 6,400, 10,000 and 9,096 hits, where master took 637 requests in pages of 50, and 32 in pages of 1,000, which read them in 0.52 s against 5.9 s. A larger value only saves pages on results of hundreds of thousands of hits, and costs responses of that size, which JanusGraph holds until they are read. Beyond 10,000, every page still costs Solr the hits before it: a million hits take about 100 such pages.Where a read ends. The count of the first page bounds the read, as on master, so that hits which other transactions add meanwhile can't keep it going; it may leave out some of them, or repeat one, as offsets allow. Within that bound, the count of each page decides whether another page follows, and an empty page ends the read whatever its count says. A result which a page holds is one request, as before, and so is the last page of a result which ends exactly with it. A page may come back short while more hits remain, where a distributed request (more than one shard, or a node with no active replica of the shard) left out a document deleted between its phases, and the read goes on. Where every hit of a page was deleted between its phases, the page comes back empty and ends the read early: that rare case is the price of a read which always ends. A count which isn't exact, as where a request sets
minExactCount, is a lower bound past the page, so it ends no read; SolrJ's streaming responses, which the read uses, don't report whether a count is exact anyway. As the first count of such a query may be a lower bound too, it bounds no read of a query which setsminExactCount, which graph queries never do: such a read ends by the counts of its pages alone.Pages at offsets under concurrent changes: a hit which another transaction deletes or adds ahead of the hits read moves the hits after it, so a page may skip or repeat one, as before;
readsOfSeveralPagesEndWhileDocumentsAreDeletedOrAddedchecks only that the read ends with documents of the result. The order of ties, and of results without an order, is Solr's, as before.The tests' configuration reads in pages of 3 growing up to 12 (
max-page-size) inJanusGraphSolrContainerandSolrIndexKerberosKeytabTest: every Solr test which reads more than a page reads growing pages, and those which read 21 hits or more reach pages of 12.index.[X].max-result-set-size's description inGraphDatabaseConfigurationchanges, sojanusgraph-cfg.mdchanges with it;ConfigurationPrinter, run throughjanusgraph-doc, writes both rows as they are here.Cost. An A/B of
janusgraph-solr, master's jar against this change's, both with master'sjanusgraph-core, on Solr 9.10.1 in a container with 31,846 vertices with a uniquenamein a mixed index, at pages of 50 and of 1,000, returns the same results with both jars. Each figure is the median of the medians of three passes a side, in alternating order, each in a JVM of its own on a freshly loaded graph, of three timed windows of 2 s after a warm-up, at 1 thread. They were measured on this change before its read was bounded by the count of its first page, which adds a comparison per page and asks the last page for no more rows than that count leaves, as 9,096 rather than 10,000 for the whole read of 31,846 hits; the same hits come back. A later run of this change as it stands, with the bound, took from 2.0% less to 4.6% more time than the table's figures for it on every traversal, as 0.23 s for the whole order and 0.15 s forrange(20000, 20010)at pages of 50, where master's own figures varied more between the runs, as 6.7 s against 5.9 s for the whole order.g.V().has('name').order().by('name'), 31,846 vertices… .limit(31846), the same vertices… .range(20000, 20010)g.V().has('name'), read whole, unsortedg.V().has('age').order().by('age'), ages of 0 to 99… .order().by('name').filter(values('uid').is(lt(400))).limit(10), which stops earlyg.V().has('name').order().by('name').limit(10), one page… .limit(100), two pages of 50… .order().by('name').count()g.V().has('name').limit(10), unsortedg.V().has('age').order().by('age').limit(10)g.V().has('name', textPrefix('n000010')), a page or less without a limit🤖 Generated with Claude Code