{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/44465685","id":44465685,"diff_hunk":"@@ -302,6 +325,138 @@ private[netty] class NettyRpcEnv(\n     }\n   }\n \n+  override def fileServer: RpcEnvFileServer = streamManager\n+\n+  override def openChannel(uri: String): ReadableByteChannel = {\n+    val parsedUri = new URI(uri)\n+    require(parsedUri.getHost() != null, \"Host name must be defined.\")\n+    require(parsedUri.getPort() > 0, \"Port must be defined.\")\n+    require(parsedUri.getPath() != null && parsedUri.getPath().nonEmpty, \"Path must be defined.\")\n+\n+    val pipe = Pipe.open()\n+    val source = new FileDownloadChannel(pipe.source())\n+    try {\n+      val client = fileDownloadClient(parsedUri.getHost(), parsedUri.getPort())\n+      val callback = new FileDownloadCallback(pipe.sink(), source, client)\n+      client.stream(parsedUri.getPath(), callback)\n+    } catch {\n+      case e: Exception =>\n+        pipe.sink().close()\n+        source.close()\n+        throw e\n+    }\n+\n+    source\n+  }\n+\n+  private def fileDownloadClient(host: String, port: Int): TransportClient = synchronized {\n+    if (stopped.get()) {\n+      throw new IllegalStateException(\"RpcEnv already stopped.\")\n+    }\n+\n+    val address = RpcAddress(host, port)\n+    val client = fileClients.get(address).filter(_.isActive()).getOrElse(newDownloadClient(address))\n+\n+    // Tell the timeout handler this client is in use. This will prevent the handler from\n+    // closing the client if the timeout even triggers before data starts flowing for this\n+    // download.\n+    client.synchronized {\n+      val timeoutHandler = client.getChannel().pipeline().get(classOf[TimeoutHandler])\n+      timeoutHandler.setInUse(true)\n+\n+      // After notifying the timeout handler, check that the client is really active, and if not,\n+      // create a new one.\n+      if (client.isActive()) client else newDownloadClient(address)\n+    }\n+  }\n+\n+  /**\n+   * Create a new client and install a handler that will respond to IdleStateEvent. The events\n+   * are generated by the IdleStateHandler installed by the TransportContext when creating\n+   * clients, and the timeout value is controlled by the transport configuration.\n+   */\n+  private def newDownloadClient(addr: RpcAddress): TransportClient = {\n+    val c = clientFactory.createUnmanagedClient(addr.host, addr.port)\n+    c.getChannel().pipeline().addLast(\"rpcEnvTimeoutHandler\", new TimeoutHandler(c))\n+    fileClients.put(addr, c)\n+    c\n+  }\n+\n+  private class TimeoutHandler(client: TransportClient) extends ChannelInboundHandlerAdapter {\n+\n+    @volatile private var inUse = true\n+\n+    def setInUse(inUse: Boolean): Unit = this.inUse = inUse\n+\n+    override def userEventTriggered(ctx: ChannelHandlerContext, evt: Object): Unit = {\n+      client.synchronized {\n+        if (!inUse && evt.isInstanceOf[IdleStateEvent] && client.isActive()) {\n+          logDebug(s\"Closing transport client $client after idle timeout.\")\n+          val socketAddr = client.getChannel().remoteAddress().asInstanceOf[InetSocketAddress]\n+          val address = RpcAddress(socketAddr.getHostName(), socketAddr.getPort())\n+          ctx.close()\n+          NettyRpcEnv.this.synchronized {","path":"core/src/main/scala/org/apache/spark/rpc/netty/NettyRpcEnv.scala","position":null,"original_position":150,"commit_id":"71ac0cfdb25d7bb29e180c704a8eac840c7fccd4","original_commit_id":"a89e6655e74209d9b89f5dcb2b1b8ed8e3399d42","user":{"login":"vanzin","id":1694083,"avatar_url":"https://avatars.githubusercontent.com/u/1694083?v=3","gravatar_id":"","url":"https://api.github.com/users/vanzin","html_url":"https://github.com/vanzin","followers_url":"https://api.github.com/users/vanzin/followers","following_url":"https://api.github.com/users/vanzin/following{/other_user}","gists_url":"https://api.github.com/users/vanzin/gists{/gist_id}","starred_url":"https://api.github.com/users/vanzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanzin/subscriptions","organizations_url":"https://api.github.com/users/vanzin/orgs","repos_url":"https://api.github.com/users/vanzin/repos","events_url":"https://api.github.com/users/vanzin/events{/privacy}","received_events_url":"https://api.github.com/users/vanzin/received_events","type":"User","site_admin":false},"body":"Good catch, fixed.","created_at":"2015-11-10T21:13:08Z","updated_at":"2015-11-10T21:13:08Z","html_url":"https://github.com/apache/spark/pull/9530#discussion_r44465685","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/9530","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/44465685"},"html":{"href":"https://github.com/apache/spark/pull/9530#discussion_r44465685"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/9530"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9530","id":50016853,"html_url":"https://github.com/apache/spark/pull/9530","diff_url":"https://github.com/apache/spark/pull/9530.diff","patch_url":"https://github.com/apache/spark/pull/9530.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/9530","number":9530,"state":"open","locked":false,"title":"[SPARK-11140] [core] Transfer files using network lib when using NettyRpcEnv.","user":{"login":"vanzin","id":1694083,"avatar_url":"https://avatars.githubusercontent.com/u/1694083?v=3","gravatar_id":"","url":"https://api.github.com/users/vanzin","html_url":"https://github.com/vanzin","followers_url":"https://api.github.com/users/vanzin/followers","following_url":"https://api.github.com/users/vanzin/following{/other_user}","gists_url":"https://api.github.com/users/vanzin/gists{/gist_id}","starred_url":"https://api.github.com/users/vanzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanzin/subscriptions","organizations_url":"https://api.github.com/users/vanzin/orgs","repos_url":"https://api.github.com/users/vanzin/repos","events_url":"https://api.github.com/users/vanzin/events{/privacy}","received_events_url":"https://api.github.com/users/vanzin/received_events","type":"User","site_admin":false},"body":"This change abstracts the code that serves jars / files to executors so that\r\neach RpcEnv can have its own implementation; the akka version uses the existing\r\nHTTP-based file serving mechanism, while the netty versions uses the new\r\nstream support added to the network lib, which makes file transfers benefit\r\nfrom the easier security configuration of the network library, and should also\r\nreduce overhead overall.\r\n\r\nThe change includes a small fix to TransportChannelHandler so that it propagates\r\nuser events to downstream handlers.","created_at":"2015-11-06T23:17:57Z","updated_at":"2015-11-10T21:13:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88374819cdcc33c31bef1e7364402905518da3ba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/9530/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/9530/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/9530/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/71ac0cfdb25d7bb29e180c704a8eac840c7fccd4","head":{"label":"vanzin:SPARK-11140","ref":"SPARK-11140","sha":"71ac0cfdb25d7bb29e180c704a8eac840c7fccd4","user":{"login":"vanzin","id":1694083,"avatar_url":"https://avatars.githubusercontent.com/u/1694083?v=3","gravatar_id":"","url":"https://api.github.com/users/vanzin","html_url":"https://github.com/vanzin","followers_url":"https://api.github.com/users/vanzin/followers","following_url":"https://api.github.com/users/vanzin/following{/other_user}","gists_url":"https://api.github.com/users/vanzin/gists{/gist_id}","starred_url":"https://api.github.com/users/vanzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanzin/subscriptions","organizations_url":"https://api.github.com/users/vanzin/orgs","repos_url":"https://api.github.com/users/vanzin/repos","events_url":"https://api.github.com/users/vanzin/events{/privacy}","received_events_url":"https://api.github.com/users/vanzin/received_events","type":"User","site_admin":false},"repo":{"id":18302272,"name":"spark","full_name":"vanzin/spark","owner":{"login":"vanzin","id":1694083,"avatar_url":"https://avatars.githubusercontent.com/u/1694083?v=3","gravatar_id":"","url":"https://api.github.com/users/vanzin","html_url":"https://github.com/vanzin","followers_url":"https://api.github.com/users/vanzin/followers","following_url":"https://api.github.com/users/vanzin/following{/other_user}","gists_url":"https://api.github.com/users/vanzin/gists{/gist_id}","starred_url":"https://api.github.com/users/vanzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanzin/subscriptions","organizations_url":"https://api.github.com/users/vanzin/orgs","repos_url":"https://api.github.com/users/vanzin/repos","events_url":"https://api.github.com/users/vanzin/events{/privacy}","received_events_url":"https://api.github.com/users/vanzin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vanzin/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/vanzin/spark","forks_url":"https://api.github.com/repos/vanzin/spark/forks","keys_url":"https://api.github.com/repos/vanzin/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vanzin/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vanzin/spark/teams","hooks_url":"https://api.github.com/repos/vanzin/spark/hooks","issue_events_url":"https://api.github.com/repos/vanzin/spark/issues/events{/number}","events_url":"https://api.github.com/repos/vanzin/spark/events","assignees_url":"https://api.github.com/repos/vanzin/spark/assignees{/user}","branches_url":"https://api.github.com/repos/vanzin/spark/branches{/branch}","tags_url":"https://api.github.com/repos/vanzin/spark/tags","blobs_url":"https://api.github.com/repos/vanzin/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vanzin/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vanzin/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/vanzin/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vanzin/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/vanzin/spark/languages","stargazers_url":"https://api.github.com/repos/vanzin/spark/stargazers","contributors_url":"https://api.github.com/repos/vanzin/spark/contributors","subscribers_url":"https://api.github.com/repos/vanzin/spark/subscribers","subscription_url":"https://api.github.com/repos/vanzin/spark/subscription","commits_url":"https://api.github.com/repos/vanzin/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/vanzin/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/vanzin/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/vanzin/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/vanzin/spark/contents/{+path}","compare_url":"https://api.github.com/repos/vanzin/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vanzin/spark/merges","archive_url":"https://api.github.com/repos/vanzin/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vanzin/spark/downloads","issues_url":"https://api.github.com/repos/vanzin/spark/issues{/number}","pulls_url":"https://api.github.com/repos/vanzin/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/vanzin/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/vanzin/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vanzin/spark/labels{/name}","releases_url":"https://api.github.com/repos/vanzin/spark/releases{/id}","created_at":"2014-03-31T17:49:25Z","updated_at":"2015-09-23T22:03:10Z","pushed_at":"2015-11-10T21:11:03Z","git_url":"git://github.com/vanzin/spark.git","ssh_url":"git@github.com:vanzin/spark.git","clone_url":"https://github.com/vanzin/spark.git","svn_url":"https://github.com/vanzin/spark","homepage":null,"size":122493,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"53600854c270d4c953fe95fbae528740b5cf6603","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-11-10T20:59:11Z","pushed_at":"2015-11-10T21:11:04Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1654904,"stargazers_count":6120,"watchers_count":6120,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5667,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":369,"forks":5667,"open_issues":369,"watchers":6120,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/9530"},"html":{"href":"https://github.com/apache/spark/pull/9530"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/9530"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/9530/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/9530/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/9530/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/71ac0cfdb25d7bb29e180c704a8eac840c7fccd4"}}}}