You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Mike Drob (Jira)" <ji...@apache.org> on 2021/05/21 15:48:00 UTC

[jira] [Created] (ZOOKEEPER-4303) ZooKeeperServerEmbedded could auto-assign and expose ports

Mike Drob created ZOOKEEPER-4303:
------------------------------------

             Summary: ZooKeeperServerEmbedded could auto-assign and expose ports
                 Key: ZOOKEEPER-4303
                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4303
             Project: ZooKeeper
          Issue Type: Improvement
            Reporter: Mike Drob


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:
 # Allow ZKSE to bind to port 0, either by directly specifying it on properties or via some other builder options.
 # Provide getClientPort and getServerAddress methods on ZKSE to allow consuming applications to connect to the newly instantiated ZK.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)