Skip to content

Commit 0d95c6b

Browse files
authored
[server] Fix compatibility issue when only [coordinator|tablet-server].host is set (#907)
1 parent 253ba7d commit 0d95c6b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

fluss-common/src/main/java/com/alibaba/fluss/cluster/Endpoint.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,12 @@ && getHost(conf, serverType).isPresent()) {
106106
}
107107

108108
Optional<String> maybeHost = getHost(conf, serverType);
109-
Optional<String> maybePort = getPort(conf, serverType);
110109

111110
// backward compatibility
112-
if (maybeHost.isPresent() && maybePort.isPresent()) {
111+
if (maybeHost.isPresent()) {
112+
String port = getPort(conf, serverType);
113113
return Collections.singletonList(
114-
new Endpoint(
115-
maybeHost.get(),
116-
Integer.parseInt(maybePort.get()),
117-
DEFAULT_LISTENER_NAME));
114+
new Endpoint(maybeHost.get(), Integer.parseInt(port), DEFAULT_LISTENER_NAME));
118115
}
119116

120117
throw new IllegalArgumentException(
@@ -195,10 +192,10 @@ private static Optional<String> getHost(Configuration conf, ServerType serverTyp
195192
: conf.getOptional(ConfigOptions.TABLET_SERVER_HOST);
196193
}
197194

198-
private static Optional<String> getPort(Configuration conf, ServerType serverType) {
195+
private static String getPort(Configuration conf, ServerType serverType) {
199196
return serverType == ServerType.COORDINATOR
200-
? conf.getOptional(ConfigOptions.COORDINATOR_PORT)
201-
: conf.getOptional(ConfigOptions.TABLET_SERVER_PORT);
197+
? conf.get(ConfigOptions.COORDINATOR_PORT)
198+
: conf.get(ConfigOptions.TABLET_SERVER_PORT);
202199
}
203200

204201
/**

fluss-common/src/test/java/com/alibaba/fluss/cluster/EndpointTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,23 @@ void testCoordinatorEndpointsCompatibility(ServerType serverType) {
125125
Configuration configuration = new Configuration();
126126
assertThatThrownBy(() -> Endpoint.loadBindEndpoints(configuration, serverType))
127127
.hasMessageContaining("The 'bind.listeners' is not configured.");
128-
configuration.setString(ConfigOptions.INTERNAL_LISTENER_NAME, "INTERNAL");
128+
129+
// if bind.listeners is not set, use deprecated [coordinator|tablet.server].host config
130+
// options even though [coordinator|tablet.server].port is not set.
129131
configuration.setString(
130132
serverType == ServerType.COORDINATOR
131133
? ConfigOptions.COORDINATOR_HOST
132134
: ConfigOptions.TABLET_SERVER_HOST,
133135
"my_host");
136+
assertThat(Endpoint.loadBindEndpoints(configuration, serverType))
137+
.containsExactlyElementsOf(
138+
Collections.singletonList(
139+
new Endpoint(
140+
"my_host",
141+
serverType == ServerType.COORDINATOR ? 9123 : 0,
142+
"FLUSS")));
143+
144+
configuration.setString(ConfigOptions.INTERNAL_LISTENER_NAME, "INTERNAL");
134145
configuration.setString(
135146
serverType == ServerType.COORDINATOR
136147
? ConfigOptions.COORDINATOR_PORT

0 commit comments

Comments
 (0)