@@ -71,18 +71,32 @@ public class MasterRegistry extends AbstractRpcBasedConnectionRegistry {
7171
7272  private  static  final  String  MASTER_ADDRS_CONF_SEPARATOR  = "," ;
7373
74+   /** 
75+    * Supplies the default master port we should use given the provided configuration. 
76+    * @param conf Configuration to parse from. 
77+    */ 
78+   private  static  int  getDefaultMasterPort (Configuration  conf ) {
79+     final  int  port  = conf .getInt (HConstants .MASTER_PORT , HConstants .DEFAULT_MASTER_PORT );
80+     if  (port  == 0 ) {
81+       // Master port may be set to 0. We should substitute the default port in that case. 
82+       return  HConstants .DEFAULT_MASTER_PORT ;
83+     }
84+     return  port ;
85+   }
86+ 
7487  /** 
7588   * Parses the list of master addresses from the provided configuration. Supported format is comma 
7689   * separated host[:port] values. If no port number if specified, default master port is assumed. 
7790   * @param conf Configuration to parse from. 
7891   */ 
7992  public  static  Set <ServerName > parseMasterAddrs (Configuration  conf ) throws  UnknownHostException  {
80-     Set <ServerName > masterAddrs  = new  HashSet <>();
81-     String  configuredMasters  = getMasterAddr (conf );
93+     final  int  defaultPort  = getDefaultMasterPort (conf );
94+     final  Set <ServerName > masterAddrs  = new  HashSet <>();
95+     final  String  configuredMasters  = getMasterAddr (conf );
8296    for  (String  masterAddr  : Splitter .onPattern (MASTER_ADDRS_CONF_SEPARATOR )
8397      .split (configuredMasters )) {
84-       HostAndPort  masterHostPort  =
85-         HostAndPort .fromString (masterAddr .trim ()).withDefaultPort (HConstants . DEFAULT_MASTER_PORT );
98+       final   HostAndPort  masterHostPort  =
99+         HostAndPort .fromString (masterAddr .trim ()).withDefaultPort (defaultPort );
86100      masterAddrs .add (ServerName .valueOf (masterHostPort .toString (), ServerName .NON_STARTCODE ));
87101    }
88102    Preconditions .checkArgument (!masterAddrs .isEmpty (), "At least one master address is needed" );
0 commit comments