@@ -71,18 +71,32 @@ public class MasterRegistry extends AbstractRpcBasedConnectionRegistry {
71
71
72
72
private static final String MASTER_ADDRS_CONF_SEPARATOR = "," ;
73
73
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
+
74
87
/**
75
88
* Parses the list of master addresses from the provided configuration. Supported format is comma
76
89
* separated host[:port] values. If no port number if specified, default master port is assumed.
77
90
* @param conf Configuration to parse from.
78
91
*/
79
92
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 );
82
96
for (String masterAddr : Splitter .onPattern (MASTER_ADDRS_CONF_SEPARATOR )
83
97
.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 );
86
100
masterAddrs .add (ServerName .valueOf (masterHostPort .toString (), ServerName .NON_STARTCODE ));
87
101
}
88
102
Preconditions .checkArgument (!masterAddrs .isEmpty (), "At least one master address is needed" );
0 commit comments