{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/27533432","id":27533432,"diff_hunk":"@@ -0,0 +1,107 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.network.protocol;\n+\n+import java.io.IOException;\n+import java.nio.channels.WritableByteChannel;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.common.primitives.Ints;\n+import io.netty.buffer.ByteBuf;\n+import io.netty.channel.FileRegion;\n+import io.netty.util.AbstractReferenceCounted;\n+import io.netty.util.ReferenceCountUtil;\n+\n+/**\n+ * A wrapper message that holds two separate pieces (a header and a body) to avoid\n+ * copying the body's content.\n+ */\n+class MessageWithHeader extends AbstractReferenceCounted implements FileRegion {\n+\n+  private final ByteBuf header;\n+  private final int headerLength;\n+  private final Object body;\n+  private final long bodyLength;\n+  private int totalBytesTransferred;","path":"network/common/src/main/java/org/apache/spark/network/protocol/MessageWithHeader.java","position":40,"original_position":40,"commit_id":"9c888ac4cba21e7d5487a4fd2fffb2a5e84008c9","original_commit_id":"9c888ac4cba21e7d5487a4fd2fffb2a5e84008c9","user":{"login":"aarondav","id":1400247,"avatar_url":"https://avatars.githubusercontent.com/u/1400247?v=3","gravatar_id":"","url":"https://api.github.com/users/aarondav","html_url":"https://github.com/aarondav","followers_url":"https://api.github.com/users/aarondav/followers","following_url":"https://api.github.com/users/aarondav/following{/other_user}","gists_url":"https://api.github.com/users/aarondav/gists{/gist_id}","starred_url":"https://api.github.com/users/aarondav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aarondav/subscriptions","organizations_url":"https://api.github.com/users/aarondav/orgs","repos_url":"https://api.github.com/users/aarondav/repos","events_url":"https://api.github.com/users/aarondav/events{/privacy}","received_events_url":"https://api.github.com/users/aarondav/received_events","type":"User","site_admin":false},"body":"I think this should be a long","created_at":"2015-03-31T23:32:13Z","updated_at":"2015-03-31T23:32:13Z","html_url":"https://github.com/apache/spark/pull/5234#discussion_r27533432","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/5234","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/27533432"},"html":{"href":"https://github.com/apache/spark/pull/5234#discussion_r27533432"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/5234"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/5234","id":32139129,"html_url":"https://github.com/apache/spark/pull/5234","diff_url":"https://github.com/apache/spark/pull/5234.diff","patch_url":"https://github.com/apache/spark/pull/5234.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/5234","number":5234,"state":"open","locked":false,"title":"[SPARK-6578] [core] Fix thread-safety issue in outbound path of network library.","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":"While the inbound path of a netty pipeline is thread-safe, the outbound\r\npath is not. That means that multiple threads can compete to write messages\r\nto the next stage of the pipeline.\r\n\r\nThe network library sometimes breaks a single RPC message into multiple\r\nbuffers internally to avoid copying data (see MessageEncoder). This can\r\nresult in the following scenario (where \"FxBy\" means \"frame x, buffer y\"):\r\n\r\n               T1         F1B1            F1B2\r\n                            \\               \\\r\n                             \\               \\\r\n               socket        F1B1   F2B1    F1B2  F2B2\r\n                                     /             /\r\n                                    /             /\r\n               T2                  F2B1         F2B2\r\n\r\nAnd the frames now cannot be rebuilt on the receiving side because the\r\ndifferent messages have been mixed up on the wire.\r\n\r\nThe fix wraps these multi-buffer messages into a `FileRegion` object\r\nso that these messages are written \"atomically\" to the next pipeline handler.","created_at":"2015-03-27T19:47:58Z","updated_at":"2015-03-31T23:32:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c7be16edf8ef4af3a5236fedbd0108d324e9c7f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/5234/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/5234/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/5234/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/9c888ac4cba21e7d5487a4fd2fffb2a5e84008c9","head":{"label":"vanzin:SPARK-6578","ref":"SPARK-6578","sha":"9c888ac4cba21e7d5487a4fd2fffb2a5e84008c9","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":"2014-06-25T00:58:09Z","pushed_at":"2015-03-31T22:39:04Z","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":94614,"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":"fde6945417355ae57500b67d034c9cad4f20d240","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-03-31T23:19:42Z","pushed_at":"2015-03-31T23:29:03Z","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":1437956,"stargazers_count":3439,"watchers_count":3439,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2967,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":315,"forks":2967,"open_issues":315,"watchers":3439,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/5234"},"html":{"href":"https://github.com/apache/spark/pull/5234"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/5234"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/5234/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/5234/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/5234/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/9c888ac4cba21e7d5487a4fd2fffb2a5e84008c9"}}}}