You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IllegalArgumentException when starting a QueryBatcher #1872
When we run our integration test-suite especially the tests using the DataMovementManager and a QueryBatcher. The LinkedBlockingQueue used in QueryBatcherImpl#QueryThreadPoolExecutor (QueryBatcherImpl line 1132) is throwing an IllegalArgumentException because the poolSize is calculated to be -1. The line in question is QueryBatcherImpl#1132:
new LinkedBlockingQueue<>((forestsLength * docToUriBatchRatio * 2) + threadCount)
with forestsLength=1, docToUriBatchRatio=-1, threadCount=1
It is wierd that docToUriBatchRatio is -1. Having a look at QueryBatcherImpl#withBatchSize (line 296), which is called in our case:
public QueryBatcher withBatchSize(int docBatchSize) {
if (docBatchSize > this.maxUriBatchSize) {
logger.debug("docBatchSize is beyond maxDocBatchSize, which is {}.", this.maxUriBatchSize);
}
if (docBatchSize < 1) {
throw new IllegalArgumentException("docBatchSize cannot be less than 1");
}
requireNotStarted();
super.withBatchSize(docBatchSize);
this.docToUriBatchRatio = Math.min(this.maxDocToUriBatchRatio, this.maxUriBatchSize / docBatchSize);
if (this.docToUriBatchRatio == 0) {
this.docToUriBatchRatio = 1;
}
return this;
}
it happens in line 305 due to maxDocToUriBatchRatio being -1. This -1 is taken from the forest-response given by the MarkLogic server in DataMovementServices#initConfig (line 64). (The else-branch in line 67 is not visited in our case.)
Solutions:
It feels like the maxDocToUriBatchRatio=-1 given by the MarkLogic server is supposed to mean something like "undefined" or "unlimited". Using the -1 in the calculation for the thread pool size seems oddly wrong. If so intended, we would appreciate a proper error message like "QueryBatcher can not be started ...". Currently just an IllegalArgumentException without any message is thrown by the Java's native LinkedBlockingQueue.
@ralfhergert The value of -1 originates from this code in the server:
let $maxDocToUriBatchRatio :=
floor(($availableHostCount * xdmp:server-max-threads(xdmp:server())) idiv count($forestIds)) - 1
My hunch is you have a large number of forests that ends up exceeding the server-max-threads value.
I'm able to reproduce the error with a test against a database having 3 forests - I adjust the "Threads" value in the Admin UI for the database to 2, and then I get the error.
Either the Java Client or server should definitely handle this so an error isn't thrown, but in the near term - I'm wondering if adjusting your Threads value for the server will get around the problem? Also curious what your Threads count and your forest count is.
@ralfhergert We may make a server fix for this, but in the near term, the 8.1.0 Java Client release will adjust the value from -1 to 1 when it receives -1 from the server. Testing has shown that this will avoid the problem in the scenario where the app server has fewer threads than the number of forests in the associated database.
Hi @rjrudin, sorry for the late response. (We had a public holiday.) I had a look on some of the values in my case: When the DataMovementServices tries to read the forest configuration it doesn't look so crazy. The response from the MarkLogic server is:
Having a look in the ML server's admin UI the number of forests on this test database appears to just be 1.
Executing xdmp:server-max-threads(xdmp:server()) in the qconsole gives me 32.
I'm running the MarkLogic server as a docker container (when building and running all tests on my local machine). Could it be that $availableHostCount is determined to be 0? I'm asking because the status page http://localhost:8001/host-status.xqy?section=host shows me:
This host is down. The following error occured while trying to contact it:
SVC-VOLSTAT: Volume status error: statfs64 '/var/opt/MarkLogic/Logs': Function not implemented
I'll try to fix the volume binding for the Logs directory and see what happens...
That host issue looks like a possible culprit, as availableHostCount being zero would produce the value of "-1" as well. I would hope that the fix of adjusting the server response from -1 to 1 would allow for the QueryBatcher to work.
Mmh, our build utilities (a gradle build) are to blame for the volume binding to get corrupted. We currently bind the Logsdirectory to a directory in one of the gradle-build dirs. Calling ./gradlew clean will wipe this directory and thus destroy the binding. This is for sure something we can/will fix on our side. - Still I would love to see the hardening of the calculation above being implemented.
Activity
rjrudin commentedon Jan 2, 2026
Thanks @ralfhergert for the report - which versions of the Java Client and MarkLogic are you using?
ralfhergert commentedon Jan 3, 2026
Hi @rjrudin we are using the marklogic-java-client in version 8.0.0 and the MarkLogic server in version 11.3.1
rjrudin commentedon Jan 5, 2026
Thanks - can you also share the code you're using to construct a QueryBatcher, along with the number of forests in your database?
rjrudin commentedon Jan 5, 2026
@ralfhergert The value of -1 originates from this code in the server:
My hunch is you have a large number of forests that ends up exceeding the server-max-threads value.
I'm able to reproduce the error with a test against a database having 3 forests - I adjust the "Threads" value in the Admin UI for the database to 2, and then I get the error.
Either the Java Client or server should definitely handle this so an error isn't thrown, but in the near term - I'm wondering if adjusting your Threads value for the server will get around the problem? Also curious what your Threads count and your forest count is.
rjrudin commentedon Jan 6, 2026
@ralfhergert We may make a server fix for this, but in the near term, the 8.1.0 Java Client release will adjust the value from -1 to 1 when it receives -1 from the server. Testing has shown that this will avoid the problem in the scenario where the app server has fewer threads than the number of forests in the associated database.
ralfhergert commentedon Jan 8, 2026
Hi @rjrudin, sorry for the late response. (We had a public holiday.) I had a look on some of the values in my case: When the DataMovementServices tries to read the forest configuration it doesn't look so crazy. The response from the MarkLogic server is:
Having a look in the ML server's admin UI the number of forests on this test database appears to just be 1.
Executing
xdmp:server-max-threads(xdmp:server())in the qconsole gives me 32.I'm running the MarkLogic server as a docker container (when building and running all tests on my local machine). Could it be that
$availableHostCountis determined to be 0? I'm asking because the status pagehttp://localhost:8001/host-status.xqy?section=hostshows me:I'll try to fix the volume binding for the Logs directory and see what happens...
rjrudin commentedon Jan 8, 2026
That host issue looks like a possible culprit, as availableHostCount being zero would produce the value of "-1" as well. I would hope that the fix of adjusting the server response from -1 to 1 would allow for the QueryBatcher to work.
ralfhergert commentedon Jan 8, 2026
Mmh, our build utilities (a gradle build) are to blame for the volume binding to get corrupted. We currently bind the
Logsdirectory to a directory in one of the gradle-build dirs. Calling./gradlew cleanwill wipe this directory and thus destroy the binding. This is for sure something we can/will fix on our side. - Still I would love to see the hardening of the calculation above being implemented.rjrudin commentedon Mar 16, 2026
Will be addressed in the soon-to-be-released 8.1.0 release.