Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-4303

ZooKeeperServerEmbedded could auto-assign and expose ports

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.9.0
    • None

    Description

      There are several related issues here, not sure if this is best filed as a single upstream JIRA or multiple.

      In Apache Solr, we have lots of hackery to launch our own ZooKeeper service in process for unit tests.

      The current model for ZKSE is to explicitly specify a clientPort and/or clientPortAddress in the properties given and launch things that way. However, we run many tests in parallel, and launch many ZooKeeper servers in parallel. It is not feasible for us to select unique ports every time, and ensure that there are no port conflicts - operating systems have already solved this problem by allowing binding to port 0 and then providing an available port.

      In Solr we implement this by building our own ServerCnxnFactory and configuring it with the desired address (typically 0.0.0.0:0), and then using that to call cnxnFactory.startup (https://github.com/apache/solr/blob/main/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java#L345-L347).

      When trying the same with properties passed to ZKSE

       

      {{ properties.setProperty("clientPort", "0");
      properties.setProperty("clientPortAddress", "0.0.0.0");}}

      we get

       

      {{Caused by: java.lang.IllegalArgumentException: clientPortAddress is set but clientPort is not set
      at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:437)
      at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:194)}}

      Or otherwise we get logging about clientPort is not set and secureClientPort is not set.

      Feature request:

      1. Allow ZKSE to bind to port 0, either by directly specifying it on properties or via some other builder options.
      2. Provide getClientPort and getServerAddress methods on ZKSE to allow consuming applications to connect to the newly instantiated ZK.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mdrob Mike Drob
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 20m
                  2h 20m