{"action":"created","comment":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/62274948","id":62274948,"diff_hunk":"@@ -404,4 +412,75 @@ private void updateBlockInStream(long blockId) throws IOException {\n       mShouldCacheCurrentBlock = mAlluxioStorageType.isStore();\n     }\n   }\n+\n+  /**\n+   * Seeks to a file position. Blocks are not cached unless they are fully read. This is only called\n+   * by {@link FileInStream#seek}.\n+   *\n+   * @param pos The position to seek to. It is guaranteed to be valid (pos >= 0 && pos != mPos &&\n+   *            pos <= mFileLength)\n+   * @throws IOException if the seek fails due to an error accessing the stream at the position\n+   */\n+  private void seekInternal(long pos) throws IOException {\n+    seekBlockInStream(pos);\n+    checkAndAdvanceBlockInStream();\n+    mCurrentBlockInStream.seek(mPos % mBlockSize);\n+  }\n+\n+  /**\n+   * Seeks to a file position. Blocks are cached even if they are not fully read. This is only\n+   * called by {@link FileInStream#seek}.\n+   * Invariant: if the current block is to be cached, [0, mPos) should have been cached already.\n+   *\n+   * @param pos The position to seek to. It is guaranteed to be valid (pos >= 0 && pos != mPos &&\n+   *            pos <= mFileLength).\n+   * @throws IOException if the seek fails due to an error accessing the stream at the position\n+   */\n+  private void seekInternalWithCachingIncompleteBlock(long pos) throws IOException {\n+    // Precompute this because mPos will be updated several times in this function.\n+    boolean isInCurrentBlock = pos / mBlockSize == mPos / mBlockSize;\n+\n+    if (mShouldCacheCurrentBlock) {\n+      // Cache till pos if seeking forward within the current block. Otheriwse cache the whole\n+      // block.\n+      readCurrentBlockTill(pos > mPos ? pos : mFileLength);\n+    }\n+\n+    // If seeks within the current block, directly seeks to pos if we are not yet there.\n+    // If seeks outside the current block, seek to the beginning of that block first, then\n+    // cache the prefix (pos % mBlockSize) of that block.\n+    if (isInCurrentBlock) {\n+      // We don't need to seek if we are at pos already. It won't work if you remove this early\n+      // return because SeekBlockInStream closes the current cache stream.\n+      if (mPos == pos) {\n+        return;\n+      }\n+\n+      seekBlockInStream(pos);\n+      mCurrentBlockInStream.seek(mPos % mBlockSize);\n+    } else {\n+      seekBlockInStream(pos / mBlockSize * mBlockSize);\n+      checkAndAdvanceBlockInStream();\n+      readCurrentBlockTill(pos);\n+    }\n+  }\n+\n+  /**\n+   * Reads till the file offset (mPos) equals pos or the end of the current block (whichever is\n+   * met first) if pos > mPos. Otherwise no-op.\n+   *\n+   * @param pos file offset\n+   * @throws IOException if read or cache write fails\n+   */\n+  private void readCurrentBlockTill(long pos) throws IOException {\n+    long len = Math.min(pos - mPos,\n+        mCurrentBlockInStream == null ? mBlockSize : mCurrentBlockInStream.remaining());\n+    if (len <= 0) {\n+      return;\n+    }\n+    Preconditions.checkState(len <= Integer.MAX_VALUE);","path":"core/client/src/main/java/alluxio/client/file/FileInStream.java","position":147,"original_position":147,"commit_id":"8827dd37d5b96934616e65aa7bdca87acc4c620f","original_commit_id":"8827dd37d5b96934616e65aa7bdca87acc4c620f","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars.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":"done","created_at":"2016-05-06T00:13:13Z","updated_at":"2016-05-06T00:13:13Z","html_url":"https://github.com/Alluxio/alluxio/pull/3089#discussion_r62274948","pull_request_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089","_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/62274948"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/3089#discussion_r62274948"},"pull_request":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089"}}},"pull_request":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089","id":67970823,"html_url":"https://github.com/Alluxio/alluxio/pull/3089","diff_url":"https://github.com/Alluxio/alluxio/pull/3089.diff","patch_url":"https://github.com/Alluxio/alluxio/pull/3089.patch","issue_url":"https://api.github.com/repos/Alluxio/alluxio/issues/3089","number":3089,"state":"open","locked":false,"title":"[ALLUXIO-262] Cache incomplete blocks during file seek","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars.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":"https://alluxio.atlassian.net/browse/ALLUXIO-262","created_at":"2016-04-26T22:48:20Z","updated_at":"2016-05-06T00:13:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5d4b9d1e6100fff14d9c2f2ef94c7e3eb663a31e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089/commits","review_comments_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089/comments","review_comment_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Alluxio/alluxio/issues/3089/comments","statuses_url":"https://api.github.com/repos/Alluxio/alluxio/statuses/8827dd37d5b96934616e65aa7bdca87acc4c620f","head":{"label":"peisun1115:CacheBlock","ref":"CacheBlock","sha":"8827dd37d5b96934616e65aa7bdca87acc4c620f","user":{"login":"peisun1115","id":18294241,"avatar_url":"https://avatars.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://avatars.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":"2016-05-05T19:35:38Z","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":48543,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Alluxio:master","ref":"master","sha":"2f5f7607613cabd66845ae396278d6b8183079ae","user":{"login":"Alluxio","id":16203694,"avatar_url":"https://avatars.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://avatars.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, Memory-Speed Virtual Distributed Storage System","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":"2016-05-05T20:06:09Z","pushed_at":"2016-05-05T22:55:48Z","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":80107,"stargazers_count":2326,"watchers_count":2326,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":914,"mirror_url":null,"open_issues_count":25,"forks":914,"open_issues":25,"watchers":2326,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/3089"},"issue":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/3089"},"comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/3089/comments"},"review_comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089/comments"},"review_comment":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/3089/commits"},"statuses":{"href":"https://api.github.com/repos/Alluxio/alluxio/statuses/8827dd37d5b96934616e65aa7bdca87acc4c620f"}}}}