Skip to content

IllegalArgumentException when starting a QueryBatcher #1872

Closed

Description

@ralfhergert

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.

Activity

  1. rjrudin commented on Jan 2, 2026

    @rjrudin
    Contributor

    Thanks @ralfhergert for the report - which versions of the Java Client and MarkLogic are you using?

  2. ralfhergert commented on Jan 3, 2026

    @ralfhergert
    Author

    Hi @rjrudin we are using the marklogic-java-client in version 8.0.0 and the MarkLogic server in version 11.3.1

  3. rjrudin commented on Jan 5, 2026

    @rjrudin
    Contributor

    Thanks - can you also share the code you're using to construct a QueryBatcher, along with the number of forests in your database?

  4. rjrudin commented on Jan 5, 2026

    @rjrudin
    Contributor

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

  5. rjrudin commented on Jan 6, 2026

    @rjrudin
    Contributor

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

  6. ralfhergert commented on Jan 8, 2026

    @ralfhergert
    Author

    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:

    {
      "forests" : [ {
        "requestHost" : "localhost",
        "updatesAllowed" : "all",
        "alternateHost" : "localhost",
        "host" : "c620725f4551",
        "database" : "ContentHub-content-test",
        "name" : "ContentHub-content-test_p1_001",
        "id" : "8152853506606739064"
      } ],
      "maxDocToUriBatchRatio" : -1,
      "query" : {
        "ctsquery" : {
          "collectionQuery" : {
            "uris" : [ "blob-collection" ]
          }
        }
      },
      "defaultDocBatchSize" : 128,
      "maxUriBatchSize" : 2048
    }
    

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

  7. rjrudin commented on Jan 8, 2026

    @rjrudin
    Contributor

    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.

  8. ralfhergert commented on Jan 8, 2026

    @ralfhergert
    Author

    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.

  9. rjrudin commented on Mar 16, 2026

    @rjrudin
    Contributor

    Will be addressed in the soon-to-be-released 8.1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions