found this by wrongly set hostname to "broker-", while using docker to do some test, not sure if this is a bug in java.net.URI.
while after change hostname to "broker-1", it worked fine to get 6650.
In this part of code,
public BrokerService(PulsarService pulsar) throws Exception {
this.pulsar = pulsar;
this.managedLedgerFactory = pulsar.getManagedLedgerFactory();
this.port = new URI(pulsar.getBrokerServiceUrl()).getPort();
this.tlsPort = new URI(pulsar.getBrokerServiceUrlTls()).getPort();
...
URI("pulsar://broker-:6650").getPort() should return 6650
URI("pulsar://broker-:6650").getPort() will return "-1"
set hostname to "broker-", start broker on this host, it will report wrong port:
2018-01-03 02:13:14,778 - INFO - [main:DistributedIdGenerator@79] - Created sequential node at /counters/producer-name/-0000000000 -- Generator Id is test_zj-0
2018-01-03 02:13:14,781 - ERROR - [main:PulsarService@345] - port out of range:-1
java.lang.IllegalArgumentException: port out of range:-1
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:224)
at org.apache.pulsar.broker.service.BrokerService.start(BrokerService.java:285)
at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:270)
at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.start(PulsarBrokerStarter.java:190)
the docker command that I wrongly set hostname is this:
docker run -it\
--network pulsar_network \
--volume /tmp/test_bk/broker-/journal:/data/journal \
--volume /tmp/test_bk/broker-/ledger:/data/ledger \
--volume /tmp/test_bk/broker-/index:/data/index \
--name "broker-" \
--hostname "broker-" \
--env zkServers=192.168.123.71:2181 \
--env zookeeperServers=192.168.123.71:2181 \
--env globalZookeeperServers=192.168.123.71:2181 \
--env clusterName=test_zhaijia \
--env statsProviderClass=org.apache.bookkeeper.stats.NullStatsProvider \
--env zkLedgersRootPath=/ledgers \
bin/apply-config-from-env.py conf/broker.conf && bin/apply-config-from-env.py conf/pulsar_env.sh && bin/apply-config-from-env.py conf/bookkeeper.conf && bin/pulsar broker
as discussed, we might consider documenting what special characters can't be used in pulsar service uri.
let's try improve error handling and produce meaningful message if we can't get around with the java URL api.
@zhaijack can you work on this? since it has been there for a while. it should be a simple fix.
It seems I cannot use '_' in host.
(new URI("pulsar://tkiot_pulsar1:6650")).getPort() returns -1
I found this useful link.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=5049974
@ppgoml yes it is a problem from java's URI
Closed this issue since it is a problem in the URI.
Most helpful comment
as discussed, we might consider documenting what special characters can't be used in pulsar service uri.