{"action":"created","comment":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/105280125","pull_request_review_id":26153768,"id":105280125,"diff_hunk":"@@ -0,0 +1,324 @@\n+/*\n+ * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0\n+ * (the \"License\"). You may not use this work except in compliance with the License, which is\n+ * available at www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * This software is distributed on an \"AS IS\" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\n+ * either express or implied, as more fully set forth in the License.\n+ *\n+ * See the NOTICE file distributed with this work for information regarding copyright ownership.\n+ */\n+\n+package alluxio.worker.block;\n+\n+import alluxio.Configuration;\n+import alluxio.PropertyKey;\n+import alluxio.StorageTierAssoc;\n+import alluxio.WorkerStorageTierAssoc;\n+import alluxio.exception.BlockAlreadyExistsException;\n+import alluxio.exception.BlockDoesNotExistException;\n+import alluxio.exception.ExceptionMessage;\n+import alluxio.exception.InvalidWorkerStateException;\n+import alluxio.exception.PreconditionMessage;\n+import alluxio.exception.WorkerOutOfSpaceException;\n+import alluxio.underfs.UnderFileSystem;\n+import alluxio.underfs.options.OpenOptions;\n+import alluxio.util.network.NetworkAddressUtils;\n+import alluxio.worker.block.io.BlockReader;\n+import alluxio.worker.block.io.LocalFileBlockWriter;\n+import alluxio.worker.block.meta.UnderFileSystemBlockMeta;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.common.io.Closer;\n+import io.netty.buffer.ByteBuf;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.nio.ByteBuffer;\n+import java.nio.channels.ReadableByteChannel;\n+\n+import javax.annotation.concurrent.NotThreadSafe;\n+\n+/**\n+ * This class implements a {@link BlockReader} to read a block directly from UFS, and optionally\n+ * cache the block to the Alluxio worker if the whole block it is read.\n+ */\n+@NotThreadSafe\n+public final class UnderFileSystemBlockReader implements BlockReader {\n+  private static final Logger LOG = LoggerFactory.getLogger(UnderFileSystemBlockReader.class);\n+\n+  /** An object storing the mapping of tier aliases to ordinals. */\n+  private final StorageTierAssoc mStorageTierAssoc = new WorkerStorageTierAssoc();\n+\n+  /** The initial size of the block allocated in Alluxio storage when the block is cached. */\n+  private final long mInitialBlockSize;\n+  /** The block metadata for the UFS block. */\n+  private final UnderFileSystemBlockMeta mBlockMeta;\n+  /** If set, do not cache the block. */\n+  private final boolean mNoCache;\n+  /** The Alluxio block store. It is used to interact with Alluxio. */\n+  private final BlockStore mAlluxioBlockStore;\n+\n+  /** The input stream to read from UFS. */\n+  private InputStream mUnderFileSystemInputStream;\n+  /** The block writer to write the block to Alluxio. */\n+  private LocalFileBlockWriter mBlockWriter;\n+  /** If set, the reader is closed and should not be used afterwards. */\n+  private boolean mClosed;\n+\n+  /**\n+   * The position of mUnderFileSystemInputStream (if not null) is blockStart + mInStreamPos.\n+   * When mUnderFileSystemInputStream is not set, this is set to -1 (an invalid state) to indicate\n+   * that the input stream is not initialized.\n+   */\n+  private long mInStreamPos;\n+\n+  /**\n+   * Creates an instance of {@link UnderFileSystemBlockReader} and initializes it with a reading\n+   * offset.\n+   *\n+   * @param blockMeta the block meta\n+   * @param offset the position within the block to start the read\n+   * @param noCache do not cache the block if set\n+   * @param alluxioBlockStore the Alluxio block store\n+   * @return the block reader\n+   * @throws BlockDoesNotExistException if the UFS block does not exist in the UFS block store\n+   * @throws IOException if an I/O related error occur\n+   */\n+  public static UnderFileSystemBlockReader create(UnderFileSystemBlockMeta blockMeta, long offset,\n+      boolean noCache, BlockStore alluxioBlockStore)\n+      throws BlockDoesNotExistException, IOException {\n+    UnderFileSystemBlockReader ufsBlockReader =\n+        new UnderFileSystemBlockReader(blockMeta, noCache, alluxioBlockStore);\n+    ufsBlockReader.init(offset);\n+    return ufsBlockReader;\n+  }\n+\n+  /**\n+   * Creates an instance of {@link UnderFileSystemBlockReader}.\n+   *\n+   * @param blockMeta the block meta\n+   * @param noCache do not cache the block\n+   * @param alluxioBlockStore the Alluxio block store\n+   */\n+  private UnderFileSystemBlockReader(UnderFileSystemBlockMeta blockMeta, boolean noCache,\n+      BlockStore alluxioBlockStore) {\n+    mInitialBlockSize = Configuration.getBytes(PropertyKey.WORKER_FILE_BUFFER_SIZE);\n+    mBlockMeta = blockMeta;\n+    mAlluxioBlockStore = alluxioBlockStore;\n+    mNoCache = noCache;\n+    mInStreamPos = -1;\n+  }\n+\n+  /**\n+   * Initializes the reader. This is only called in the factory method.\n+   *\n+   * @param offset the position within the block to start the read\n+   * @throws BlockDoesNotExistException if the UFS block does not exist in the UFS block store\n+   * @throws IOException if an I/O related error occur\n+   */\n+  private void init(long offset) throws BlockDoesNotExistException, IOException {","path":"core/server/worker/src/main/java/alluxio/worker/block/UnderFileSystemBlockReader.java","position":127,"original_position":122,"commit_id":"31ae26a3caae6e1dbd83f3d441d98a025feab5c2","original_commit_id":"f7d62f98dbec8d2b6b10a4c299405d607b9b337c","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars2.githubusercontent.com/u/18294241?v=3","gravatar_id":"","url":"https://api.github.com/users/peisun1115","html_url":"https://github.com/peisun1115","followers_url":"https://api.github.com/users/peisun1115/followers","following_url":"https://api.github.com/users/peisun1115/following{/other_user}","gists_url":"https://api.github.com/users/peisun1115/gists{/gist_id}","starred_url":"https://api.github.com/users/peisun1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peisun1115/subscriptions","organizations_url":"https://api.github.com/users/peisun1115/orgs","repos_url":"https://api.github.com/users/peisun1115/repos","events_url":"https://api.github.com/users/peisun1115/events{/privacy}","received_events_url":"https://api.github.com/users/peisun1115/received_events","type":"User","site_admin":false},"body":"That won't work since init needs to update the internal state of the class. That cannot be done in a static method.","created_at":"2017-03-09T21:52:17Z","updated_at":"2017-03-09T21:52:17Z","html_url":"https://github.com/Alluxio/alluxio/pull/4839#discussion_r105280125","pull_request_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839","_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/105280125"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/4839#discussion_r105280125"},"pull_request":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839"}}},"pull_request":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839","id":108635203,"html_url":"https://github.com/Alluxio/alluxio/pull/4839","diff_url":"https://github.com/Alluxio/alluxio/pull/4839.diff","patch_url":"https://github.com/Alluxio/alluxio/pull/4839.patch","issue_url":"https://api.github.com/repos/Alluxio/alluxio/issues/4839","number":4839,"state":"open","locked":false,"title":"[ALLUXIO-2565] Improve concurrent UFS read efficiency PR4","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars2.githubusercontent.com/u/18294241?v=3","gravatar_id":"","url":"https://api.github.com/users/peisun1115","html_url":"https://github.com/peisun1115","followers_url":"https://api.github.com/users/peisun1115/followers","following_url":"https://api.github.com/users/peisun1115/following{/other_user}","gists_url":"https://api.github.com/users/peisun1115/gists{/gist_id}","starred_url":"https://api.github.com/users/peisun1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peisun1115/subscriptions","organizations_url":"https://api.github.com/users/peisun1115/orgs","repos_url":"https://api.github.com/users/peisun1115/repos","events_url":"https://api.github.com/users/peisun1115/events{/privacy}","received_events_url":"https://api.github.com/users/peisun1115/received_events","type":"User","site_admin":false},"body":"PR4. see full PR #4799\r\n\r\nUFS block store\r\nUFS block meta\r\nUFS block reader\r\n\r\n(no writers)","created_at":"2017-03-01T21:43:38Z","updated_at":"2017-03-09T21:52:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c43e2370ff617020d4d4f1aa5d75cbf843c8cc4c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839/commits","review_comments_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839/comments","review_comment_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Alluxio/alluxio/issues/4839/comments","statuses_url":"https://api.github.com/repos/Alluxio/alluxio/statuses/31ae26a3caae6e1dbd83f3d441d98a025feab5c2","head":{"label":"peisun1115:th-4","ref":"th-4","sha":"31ae26a3caae6e1dbd83f3d441d98a025feab5c2","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars2.githubusercontent.com/u/18294241?v=3","gravatar_id":"","url":"https://api.github.com/users/peisun1115","html_url":"https://github.com/peisun1115","followers_url":"https://api.github.com/users/peisun1115/followers","following_url":"https://api.github.com/users/peisun1115/following{/other_user}","gists_url":"https://api.github.com/users/peisun1115/gists{/gist_id}","starred_url":"https://api.github.com/users/peisun1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peisun1115/subscriptions","organizations_url":"https://api.github.com/users/peisun1115/orgs","repos_url":"https://api.github.com/users/peisun1115/repos","events_url":"https://api.github.com/users/peisun1115/events{/privacy}","received_events_url":"https://api.github.com/users/peisun1115/received_events","type":"User","site_admin":false},"repo":{"id":55541423,"name":"alluxio","full_name":"peisun1115/alluxio","owner":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars2.githubusercontent.com/u/18294241?v=3","gravatar_id":"","url":"https://api.github.com/users/peisun1115","html_url":"https://github.com/peisun1115","followers_url":"https://api.github.com/users/peisun1115/followers","following_url":"https://api.github.com/users/peisun1115/following{/other_user}","gists_url":"https://api.github.com/users/peisun1115/gists{/gist_id}","starred_url":"https://api.github.com/users/peisun1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peisun1115/subscriptions","organizations_url":"https://api.github.com/users/peisun1115/orgs","repos_url":"https://api.github.com/users/peisun1115/repos","events_url":"https://api.github.com/users/peisun1115/events{/privacy}","received_events_url":"https://api.github.com/users/peisun1115/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peisun1115/alluxio","description":"Memory-Speed Virtual Distributed Storage System","fork":true,"url":"https://api.github.com/repos/peisun1115/alluxio","forks_url":"https://api.github.com/repos/peisun1115/alluxio/forks","keys_url":"https://api.github.com/repos/peisun1115/alluxio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peisun1115/alluxio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peisun1115/alluxio/teams","hooks_url":"https://api.github.com/repos/peisun1115/alluxio/hooks","issue_events_url":"https://api.github.com/repos/peisun1115/alluxio/issues/events{/number}","events_url":"https://api.github.com/repos/peisun1115/alluxio/events","assignees_url":"https://api.github.com/repos/peisun1115/alluxio/assignees{/user}","branches_url":"https://api.github.com/repos/peisun1115/alluxio/branches{/branch}","tags_url":"https://api.github.com/repos/peisun1115/alluxio/tags","blobs_url":"https://api.github.com/repos/peisun1115/alluxio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peisun1115/alluxio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peisun1115/alluxio/git/refs{/sha}","trees_url":"https://api.github.com/repos/peisun1115/alluxio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peisun1115/alluxio/statuses/{sha}","languages_url":"https://api.github.com/repos/peisun1115/alluxio/languages","stargazers_url":"https://api.github.com/repos/peisun1115/alluxio/stargazers","contributors_url":"https://api.github.com/repos/peisun1115/alluxio/contributors","subscribers_url":"https://api.github.com/repos/peisun1115/alluxio/subscribers","subscription_url":"https://api.github.com/repos/peisun1115/alluxio/subscription","commits_url":"https://api.github.com/repos/peisun1115/alluxio/commits{/sha}","git_commits_url":"https://api.github.com/repos/peisun1115/alluxio/git/commits{/sha}","comments_url":"https://api.github.com/repos/peisun1115/alluxio/comments{/number}","issue_comment_url":"https://api.github.com/repos/peisun1115/alluxio/issues/comments{/number}","contents_url":"https://api.github.com/repos/peisun1115/alluxio/contents/{+path}","compare_url":"https://api.github.com/repos/peisun1115/alluxio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peisun1115/alluxio/merges","archive_url":"https://api.github.com/repos/peisun1115/alluxio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peisun1115/alluxio/downloads","issues_url":"https://api.github.com/repos/peisun1115/alluxio/issues{/number}","pulls_url":"https://api.github.com/repos/peisun1115/alluxio/pulls{/number}","milestones_url":"https://api.github.com/repos/peisun1115/alluxio/milestones{/number}","notifications_url":"https://api.github.com/repos/peisun1115/alluxio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peisun1115/alluxio/labels{/name}","releases_url":"https://api.github.com/repos/peisun1115/alluxio/releases{/id}","deployments_url":"https://api.github.com/repos/peisun1115/alluxio/deployments","created_at":"2016-04-05T20:01:18Z","updated_at":"2016-04-05T20:01:22Z","pushed_at":"2017-03-09T21:50:03Z","git_url":"git://github.com/peisun1115/alluxio.git","ssh_url":"git@github.com:peisun1115/alluxio.git","clone_url":"https://github.com/peisun1115/alluxio.git","svn_url":"https://github.com/peisun1115/alluxio","homepage":"http://www.alluxio.org/","size":67067,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":8,"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"Alluxio:ufs-read","ref":"ufs-read","sha":"55825ec816779dd625ff3794c7bbe46d55cf6b82","user":{"login":"Alluxio","id":16203694,"avatar_url":"https://avatars3.githubusercontent.com/u/16203694?v=3","gravatar_id":"","url":"https://api.github.com/users/Alluxio","html_url":"https://github.com/Alluxio","followers_url":"https://api.github.com/users/Alluxio/followers","following_url":"https://api.github.com/users/Alluxio/following{/other_user}","gists_url":"https://api.github.com/users/Alluxio/gists{/gist_id}","starred_url":"https://api.github.com/users/Alluxio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alluxio/subscriptions","organizations_url":"https://api.github.com/users/Alluxio/orgs","repos_url":"https://api.github.com/users/Alluxio/repos","events_url":"https://api.github.com/users/Alluxio/events{/privacy}","received_events_url":"https://api.github.com/users/Alluxio/received_events","type":"Organization","site_admin":false},"repo":{"id":7276954,"name":"alluxio","full_name":"Alluxio/alluxio","owner":{"login":"Alluxio","id":16203694,"avatar_url":"https://avatars3.githubusercontent.com/u/16203694?v=3","gravatar_id":"","url":"https://api.github.com/users/Alluxio","html_url":"https://github.com/Alluxio","followers_url":"https://api.github.com/users/Alluxio/followers","following_url":"https://api.github.com/users/Alluxio/following{/other_user}","gists_url":"https://api.github.com/users/Alluxio/gists{/gist_id}","starred_url":"https://api.github.com/users/Alluxio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alluxio/subscriptions","organizations_url":"https://api.github.com/users/Alluxio/orgs","repos_url":"https://api.github.com/users/Alluxio/repos","events_url":"https://api.github.com/users/Alluxio/events{/privacy}","received_events_url":"https://api.github.com/users/Alluxio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Alluxio/alluxio","description":"Alluxio, formerly Tachyon, Unify Data at Memory Speed","fork":false,"url":"https://api.github.com/repos/Alluxio/alluxio","forks_url":"https://api.github.com/repos/Alluxio/alluxio/forks","keys_url":"https://api.github.com/repos/Alluxio/alluxio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Alluxio/alluxio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Alluxio/alluxio/teams","hooks_url":"https://api.github.com/repos/Alluxio/alluxio/hooks","issue_events_url":"https://api.github.com/repos/Alluxio/alluxio/issues/events{/number}","events_url":"https://api.github.com/repos/Alluxio/alluxio/events","assignees_url":"https://api.github.com/repos/Alluxio/alluxio/assignees{/user}","branches_url":"https://api.github.com/repos/Alluxio/alluxio/branches{/branch}","tags_url":"https://api.github.com/repos/Alluxio/alluxio/tags","blobs_url":"https://api.github.com/repos/Alluxio/alluxio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Alluxio/alluxio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Alluxio/alluxio/git/refs{/sha}","trees_url":"https://api.github.com/repos/Alluxio/alluxio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Alluxio/alluxio/statuses/{sha}","languages_url":"https://api.github.com/repos/Alluxio/alluxio/languages","stargazers_url":"https://api.github.com/repos/Alluxio/alluxio/stargazers","contributors_url":"https://api.github.com/repos/Alluxio/alluxio/contributors","subscribers_url":"https://api.github.com/repos/Alluxio/alluxio/subscribers","subscription_url":"https://api.github.com/repos/Alluxio/alluxio/subscription","commits_url":"https://api.github.com/repos/Alluxio/alluxio/commits{/sha}","git_commits_url":"https://api.github.com/repos/Alluxio/alluxio/git/commits{/sha}","comments_url":"https://api.github.com/repos/Alluxio/alluxio/comments{/number}","issue_comment_url":"https://api.github.com/repos/Alluxio/alluxio/issues/comments{/number}","contents_url":"https://api.github.com/repos/Alluxio/alluxio/contents/{+path}","compare_url":"https://api.github.com/repos/Alluxio/alluxio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Alluxio/alluxio/merges","archive_url":"https://api.github.com/repos/Alluxio/alluxio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Alluxio/alluxio/downloads","issues_url":"https://api.github.com/repos/Alluxio/alluxio/issues{/number}","pulls_url":"https://api.github.com/repos/Alluxio/alluxio/pulls{/number}","milestones_url":"https://api.github.com/repos/Alluxio/alluxio/milestones{/number}","notifications_url":"https://api.github.com/repos/Alluxio/alluxio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Alluxio/alluxio/labels{/name}","releases_url":"https://api.github.com/repos/Alluxio/alluxio/releases{/id}","deployments_url":"https://api.github.com/repos/Alluxio/alluxio/deployments","created_at":"2012-12-21T17:43:46Z","updated_at":"2017-03-09T12:53:51Z","pushed_at":"2017-03-09T21:50:07Z","git_url":"git://github.com/Alluxio/alluxio.git","ssh_url":"git@github.com:Alluxio/alluxio.git","clone_url":"https://github.com/Alluxio/alluxio.git","svn_url":"https://github.com/Alluxio/alluxio","homepage":"http://www.alluxio.org/","size":66616,"stargazers_count":2865,"watchers_count":2865,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1310,"mirror_url":null,"open_issues_count":30,"forks":1310,"open_issues":30,"watchers":2865,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/4839"},"issue":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/4839"},"comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/4839/comments"},"review_comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839/comments"},"review_comment":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/4839/commits"},"statuses":{"href":"https://api.github.com/repos/Alluxio/alluxio/statuses/31ae26a3caae6e1dbd83f3d441d98a025feab5c2"}}}}
{"actor":{"display_login":"peisun1115"}}