[ 
https://issues.apache.org/jira/browse/FLINK-9153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16452107#comment-16452107
 ] 

ASF GitHub Bot commented on FLINK-9153:
---------------------------------------

Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/5834#discussion_r184030230
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
 ---
    @@ -355,13 +359,53 @@ public static RpcService createRpcService(
                                taskManagerHostname, 
taskManagerAddress.getHostAddress());
                }
     
    -           final int rpcPort = 
configuration.getInteger(ConfigConstants.TASK_MANAGER_IPC_PORT_KEY, 0);
    +           final String portRangeDefinition = 
configuration.getString(TaskManagerOptions.RPC_PORT, "0");
     
    -           checkState(rpcPort >= 0 && rpcPort <= 65535, "Invalid value for 
" +
    -                           "'%s' (port for the TaskManager actor system) : 
%d - Leave config parameter empty or " +
    -                           "use 0 to let the system choose port 
automatically.",
    -                   ConfigConstants.TASK_MANAGER_IPC_PORT_KEY, rpcPort);
    +           // parse port range definition and create port iterator
    +           Iterator<Integer> portsIterator;
    +           try {
    +                   portsIterator = 
NetUtils.getPortRangeFromString(portRangeDefinition);
    +           } catch (Exception e) {
    +                   throw new IllegalArgumentException("Invalid port range 
definition: " + portRangeDefinition);
    +           }
    +
    +           while (portsIterator.hasNext()) {
    +                   // first, we check if the port is available by opening 
a socket
    +                   // if the actor system fails to start on the port, we 
try further
    +                   ServerSocket availableSocket = 
NetUtils.createSocketFromPorts(
    +                           portsIterator,
    +                           new NetUtils.SocketFactory() {
    +                                   @Override
    +                                   public ServerSocket createSocket(int 
port) throws IOException {
    +                                           return new ServerSocket(port);
    +                                   }
    +                           });
    +
    +                   int port;
    +                   if (availableSocket == null) {
    +                           throw new BindException("Unable to allocate 
further port in port range: " + portRangeDefinition);
    +                   } else {
    +                           port = availableSocket.getLocalPort();
    +                           try {
    +                                   availableSocket.close();
    +                           } catch (IOException ignored) {}
    +                   }
    +
    +                   try {
    +                           return 
AkkaRpcServiceUtils.createRpcService(taskManagerHostname, port, configuration);
    +                   }
    +                   catch (Exception e) {
    +                           // we can continue to try if this contains a 
netty channel exception
    +                           Throwable cause = e.getCause();
    +                           if (!(cause instanceof 
org.jboss.netty.channel.ChannelException ||
    +                                   cause instanceof 
java.net.BindException)) {
    +                                   throw e;
    +                           } // else fall through the loop and try the 
next port
    +                   }
    +           }
     
    -           return 
AkkaRpcServiceUtils.createRpcService(taskManagerHostname, rpcPort, 
configuration);
    +           // if we come here, we have exhausted the port range
    +           throw new BindException("Could not start actor system on any 
port in port range "
    --- End diff --
    
    should not mention actor system but taskmanager instead


> TaskManagerRunner should support rpc port range
> -----------------------------------------------
>
>                 Key: FLINK-9153
>                 URL: https://issues.apache.org/jira/browse/FLINK-9153
>             Project: Flink
>          Issue Type: Bug
>          Components: TaskManager
>    Affects Versions: 1.4.0, 1.5.0
>            Reporter: vinoyang
>            Assignee: vinoyang
>            Priority: Major
>             Fix For: 1.5.0
>
>
> TaskManagerRunner current just support one specific port :
> {code:java}
> final int rpcPort = 
> configuration.getInteger(ConfigConstants.TASK_MANAGER_IPC_PORT_KEY, 0);
> {code}
> It should support port range as the document described : 
> https://ci.apache.org/projects/flink/flink-docs-master/ops/config.html#taskmanager-rpc-port
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to