@@ -100,17 +100,31 @@ public class MasterRegistry implements ConnectionRegistry {
100100
101101 protected final MasterAddressRefresher masterAddressRefresher ;
102102
103+ /**
104+ * Supplies the default master port we should use given the provided configuration.
105+ * @param conf Configuration to parse from.
106+ */
107+ private static int getDefaultMasterPort (Configuration conf ) {
108+ final int port = conf .getInt (HConstants .MASTER_PORT , HConstants .DEFAULT_MASTER_PORT );
109+ if (port == 0 ) {
110+ // Master port may be set to 0. We should substitute the default port in that case.
111+ return HConstants .DEFAULT_MASTER_PORT ;
112+ }
113+ return port ;
114+ }
115+
103116 /**
104117 * Parses the list of master addresses from the provided configuration. Supported format is comma
105118 * separated host[:port] values. If no port number if specified, default master port is assumed.
106119 * @param conf Configuration to parse from.
107120 */
108121 private static Set <ServerName > parseMasterAddrs (Configuration conf ) throws UnknownHostException {
109- Set <ServerName > masterAddrs = new HashSet <>();
110- String configuredMasters = getMasterAddr (conf );
122+ final int defaultPort = getDefaultMasterPort (conf );
123+ final Set <ServerName > masterAddrs = new HashSet <>();
124+ final String configuredMasters = getMasterAddr (conf );
111125 for (String masterAddr : configuredMasters .split (MASTER_ADDRS_CONF_SEPARATOR )) {
112- HostAndPort masterHostPort =
113- HostAndPort .fromString (masterAddr .trim ()).withDefaultPort (HConstants . DEFAULT_MASTER_PORT );
126+ final HostAndPort masterHostPort =
127+ HostAndPort .fromString (masterAddr .trim ()).withDefaultPort (defaultPort );
114128 masterAddrs .add (ServerName .valueOf (masterHostPort .toString (), ServerName .NON_STARTCODE ));
115129 }
116130 Preconditions .checkArgument (!masterAddrs .isEmpty (), "At least one master address is needed" );
0 commit comments