{"action":"created","comment":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/comments/33720021","id":33720021,"diff_hunk":"@@ -0,0 +1,432 @@\n+/*\n+ * Licensed to the University of California, Berkeley under one or more contributor license\n+ * agreements. See the NOTICE file distributed with this work for additional information regarding\n+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance with the License. You may obtain a\n+ * 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 distributed under the License\n+ * is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\n+ * or implied. See the License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+\n+package tachyon.worker.block;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.HashSet;\n+import java.util.List;\n+import java.util.Set;\n+import java.util.concurrent.locks.ReentrantReadWriteLock;\n+\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import com.google.common.base.Preconditions;\n+\n+import tachyon.Constants;\n+import tachyon.Pair;\n+import tachyon.conf.TachyonConf;\n+import tachyon.thrift.InvalidPathException;\n+import tachyon.util.CommonUtils;\n+import tachyon.worker.block.allocator.Allocator;\n+import tachyon.worker.block.allocator.AllocatorFactory;\n+import tachyon.worker.block.allocator.AllocatorType;\n+import tachyon.worker.block.evictor.EvictionPlan;\n+import tachyon.worker.block.evictor.Evictor;\n+import tachyon.worker.block.evictor.EvictorType;\n+import tachyon.worker.block.evictor.EvictorFactory;\n+import tachyon.worker.block.io.BlockReader;\n+import tachyon.worker.block.io.BlockWriter;\n+import tachyon.worker.block.io.LocalFileBlockReader;\n+import tachyon.worker.block.io.LocalFileBlockWriter;\n+import tachyon.worker.block.meta.BlockMeta;\n+import tachyon.worker.block.meta.TempBlockMeta;\n+\n+/**\n+ * This class represents an object store that manages all the blocks in the local tiered storage.\n+ * This store exposes simple public APIs to operate blocks. Inside this store, it creates an\n+ * Allocator to decide where to put a new block, an Evictor to decide where to evict a stale block,\n+ * a BlockMetadataManager to maintain the status of the tiered storage, and a LockManager to\n+ * coordinate read/write on the same block.\n+ * <p>\n+ * This class is thread-safe.\n+ */\n+public class TieredBlockStore implements BlockStore {\n+  private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);\n+\n+  private final TachyonConf mTachyonConf;\n+  private final BlockMetadataManager mMetaManager;\n+  private final BlockLockManager mLockManager;\n+  private final Allocator mAllocator;\n+  private final Evictor mEvictor;\n+  private List<BlockStoreEventListener> mBlockStoreEventListeners =\n+      new ArrayList<BlockStoreEventListener>();\n+\n+  /** A readwrite lock for meta data **/\n+  private final ReentrantReadWriteLock mEvictionLock = new ReentrantReadWriteLock();\n+\n+  public TieredBlockStore(TachyonConf tachyonConf) throws IOException {\n+    mTachyonConf = Preconditions.checkNotNull(tachyonConf);\n+    mMetaManager = BlockMetadataManager.newBlockMetadataManager(mTachyonConf);\n+    mLockManager = new BlockLockManager(mMetaManager);\n+\n+    AllocatorType allocatorType =\n+        mTachyonConf.getEnum(Constants.WORKER_ALLOCATE_STRATEGY_TYPE, AllocatorType.DEFAULT);\n+    mAllocator = AllocatorFactory.create(allocatorType, mMetaManager);\n+\n+    EvictorType evictorType =\n+        mTachyonConf.getEnum(Constants.WORKER_EVICT_STRATEGY_TYPE, EvictorType.DEFAULT);\n+    mEvictor = EvictorFactory.create(evictorType, mMetaManager);\n+    if (mEvictor instanceof BlockStoreEventListener) {\n+      registerBlockStoreEventListener((BlockStoreEventListener) mEvictor);\n+    }\n+  }\n+\n+  @Override\n+  public long lockBlock(long userId, long blockId) throws IOException {\n+    return mLockManager.lockBlock(userId, blockId, BlockLockType.READ);\n+  }\n+\n+  @Override\n+  public void unlockBlock(long lockId) throws IOException {\n+    mLockManager.unlockBlock(lockId);\n+  }\n+\n+  @Override\n+  public void unlockBlock(long userId, long blockId) throws IOException {\n+    mLockManager.unlockBlock(userId, blockId);\n+  }\n+\n+  @Override\n+  public BlockWriter getBlockWriter(long userId, long blockId) throws IOException {\n+    TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);\n+    return new LocalFileBlockWriter(tempBlockMeta);\n+  }\n+\n+  @Override\n+  public BlockReader getBlockReader(long userId, long blockId, long lockId) throws IOException {\n+    mLockManager.validateLockId(userId, blockId, lockId);\n+    BlockMeta blockMeta = mMetaManager.getBlockMeta(blockId);\n+    return new LocalFileBlockReader(blockMeta);\n+  }\n+\n+  @Override\n+  public TempBlockMeta createBlockMeta(long userId, long blockId, BlockStoreLocation location,\n+      long initialBlockSize) throws IOException {\n+    TempBlockMeta tempBlock;\n+    mEvictionLock.readLock().lock();\n+    try {\n+      tempBlock = createBlockMetaNoLock(userId, blockId, location, initialBlockSize);\n+    } finally {\n+      mEvictionLock.readLock().unlock();\n+    }\n+    return tempBlock;\n+  }\n+\n+  @Override\n+  public BlockMeta getBlockMeta(long userId, long blockId, long lockId) throws IOException {\n+    mLockManager.validateLockId(userId, blockId, lockId);\n+    return mMetaManager.getBlockMeta(blockId);\n+  }\n+\n+  @Override\n+  public void commitBlock(long userId, long blockId) throws IOException {\n+    mEvictionLock.readLock().lock();\n+    TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);","path":"servers/src/main/java/tachyon/worker/block/TieredBlockStore.java","position":140,"original_position":140,"commit_id":"4af88fed3b24e16efbf39ac31564264d64821d47","original_commit_id":"4af88fed3b24e16efbf39ac31564264d64821d47","user":{"login":"calvinjia","id":2223813,"avatar_url":"https://avatars.githubusercontent.com/u/2223813?v=3","gravatar_id":"","url":"https://api.github.com/users/calvinjia","html_url":"https://github.com/calvinjia","followers_url":"https://api.github.com/users/calvinjia/followers","following_url":"https://api.github.com/users/calvinjia/following{/other_user}","gists_url":"https://api.github.com/users/calvinjia/gists{/gist_id}","starred_url":"https://api.github.com/users/calvinjia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calvinjia/subscriptions","organizations_url":"https://api.github.com/users/calvinjia/orgs","repos_url":"https://api.github.com/users/calvinjia/repos","events_url":"https://api.github.com/users/calvinjia/events{/privacy}","received_events_url":"https://api.github.com/users/calvinjia/received_events","type":"User","site_admin":false},"body":"Should this line be in the try clause? Since it can throw an exception and leak the lock?","created_at":"2015-07-01T20:23:12Z","updated_at":"2015-07-01T20:23:12Z","html_url":"https://github.com/amplab/tachyon/pull/1017#discussion_r33720021","pull_request_url":"https://api.github.com/repos/amplab/tachyon/pulls/1017","_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments/33720021"},"html":{"href":"https://github.com/amplab/tachyon/pull/1017#discussion_r33720021"},"pull_request":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1017"}}},"pull_request":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/1017","id":38702106,"html_url":"https://github.com/amplab/tachyon/pull/1017","diff_url":"https://github.com/amplab/tachyon/pull/1017.diff","patch_url":"https://github.com/amplab/tachyon/pull/1017.patch","issue_url":"https://api.github.com/repos/amplab/tachyon/issues/1017","number":1017,"state":"open","locked":false,"title":"[WIP] [TACHYON-515] Tachyon Worker Improvement","user":{"login":"calvinjia","id":2223813,"avatar_url":"https://avatars.githubusercontent.com/u/2223813?v=3","gravatar_id":"","url":"https://api.github.com/users/calvinjia","html_url":"https://github.com/calvinjia","followers_url":"https://api.github.com/users/calvinjia/followers","following_url":"https://api.github.com/users/calvinjia/following{/other_user}","gists_url":"https://api.github.com/users/calvinjia/gists{/gist_id}","starred_url":"https://api.github.com/users/calvinjia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calvinjia/subscriptions","organizations_url":"https://api.github.com/users/calvinjia/orgs","repos_url":"https://api.github.com/users/calvinjia/repos","events_url":"https://api.github.com/users/calvinjia/events{/privacy}","received_events_url":"https://api.github.com/users/calvinjia/received_events","type":"User","site_admin":false},"body":"https://tachyon.atlassian.net/browse/TACHYON-515\r\n\r\nThis is a rebased version of the worker_wip branch.","created_at":"2015-06-27T02:02:10Z","updated_at":"2015-07-01T20:23:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b78ab3c87dd5bafb608ceb2c3e16020fe45d4b77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amplab/tachyon/pulls/1017/commits","review_comments_url":"https://api.github.com/repos/amplab/tachyon/pulls/1017/comments","review_comment_url":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amplab/tachyon/issues/1017/comments","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/4af88fed3b24e16efbf39ac31564264d64821d47","head":{"label":"amplab:rebased_worker_wip","ref":"rebased_worker_wip","sha":"4af88fed3b24e16efbf39ac31564264d64821d47","user":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"repo":{"id":7276954,"name":"tachyon","full_name":"amplab/tachyon","owner":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplab/tachyon","description":" A Reliable Memory Centric Distributed Storage System","fork":false,"url":"https://api.github.com/repos/amplab/tachyon","forks_url":"https://api.github.com/repos/amplab/tachyon/forks","keys_url":"https://api.github.com/repos/amplab/tachyon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplab/tachyon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplab/tachyon/teams","hooks_url":"https://api.github.com/repos/amplab/tachyon/hooks","issue_events_url":"https://api.github.com/repos/amplab/tachyon/issues/events{/number}","events_url":"https://api.github.com/repos/amplab/tachyon/events","assignees_url":"https://api.github.com/repos/amplab/tachyon/assignees{/user}","branches_url":"https://api.github.com/repos/amplab/tachyon/branches{/branch}","tags_url":"https://api.github.com/repos/amplab/tachyon/tags","blobs_url":"https://api.github.com/repos/amplab/tachyon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplab/tachyon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplab/tachyon/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplab/tachyon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/{sha}","languages_url":"https://api.github.com/repos/amplab/tachyon/languages","stargazers_url":"https://api.github.com/repos/amplab/tachyon/stargazers","contributors_url":"https://api.github.com/repos/amplab/tachyon/contributors","subscribers_url":"https://api.github.com/repos/amplab/tachyon/subscribers","subscription_url":"https://api.github.com/repos/amplab/tachyon/subscription","commits_url":"https://api.github.com/repos/amplab/tachyon/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplab/tachyon/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplab/tachyon/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplab/tachyon/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplab/tachyon/contents/{+path}","compare_url":"https://api.github.com/repos/amplab/tachyon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplab/tachyon/merges","archive_url":"https://api.github.com/repos/amplab/tachyon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplab/tachyon/downloads","issues_url":"https://api.github.com/repos/amplab/tachyon/issues{/number}","pulls_url":"https://api.github.com/repos/amplab/tachyon/pulls{/number}","milestones_url":"https://api.github.com/repos/amplab/tachyon/milestones{/number}","notifications_url":"https://api.github.com/repos/amplab/tachyon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplab/tachyon/labels{/name}","releases_url":"https://api.github.com/repos/amplab/tachyon/releases{/id}","created_at":"2012-12-21T17:43:46Z","updated_at":"2015-07-01T04:17:01Z","pushed_at":"2015-07-01T20:08:21Z","git_url":"git://github.com/amplab/tachyon.git","ssh_url":"git@github.com:amplab/tachyon.git","clone_url":"https://github.com/amplab/tachyon.git","svn_url":"https://github.com/amplab/tachyon","homepage":"http://tachyon-project.org","size":34278,"stargazers_count":1459,"watchers_count":1459,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":538,"mirror_url":null,"open_issues_count":18,"forks":538,"open_issues":18,"watchers":1459,"default_branch":"master"}},"base":{"label":"amplab:master","ref":"master","sha":"d6054a7be4506610280514f9c4192849f63e0d8d","user":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"repo":{"id":7276954,"name":"tachyon","full_name":"amplab/tachyon","owner":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplab/tachyon","description":" A Reliable Memory Centric Distributed Storage System","fork":false,"url":"https://api.github.com/repos/amplab/tachyon","forks_url":"https://api.github.com/repos/amplab/tachyon/forks","keys_url":"https://api.github.com/repos/amplab/tachyon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplab/tachyon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplab/tachyon/teams","hooks_url":"https://api.github.com/repos/amplab/tachyon/hooks","issue_events_url":"https://api.github.com/repos/amplab/tachyon/issues/events{/number}","events_url":"https://api.github.com/repos/amplab/tachyon/events","assignees_url":"https://api.github.com/repos/amplab/tachyon/assignees{/user}","branches_url":"https://api.github.com/repos/amplab/tachyon/branches{/branch}","tags_url":"https://api.github.com/repos/amplab/tachyon/tags","blobs_url":"https://api.github.com/repos/amplab/tachyon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplab/tachyon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplab/tachyon/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplab/tachyon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/{sha}","languages_url":"https://api.github.com/repos/amplab/tachyon/languages","stargazers_url":"https://api.github.com/repos/amplab/tachyon/stargazers","contributors_url":"https://api.github.com/repos/amplab/tachyon/contributors","subscribers_url":"https://api.github.com/repos/amplab/tachyon/subscribers","subscription_url":"https://api.github.com/repos/amplab/tachyon/subscription","commits_url":"https://api.github.com/repos/amplab/tachyon/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplab/tachyon/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplab/tachyon/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplab/tachyon/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplab/tachyon/contents/{+path}","compare_url":"https://api.github.com/repos/amplab/tachyon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplab/tachyon/merges","archive_url":"https://api.github.com/repos/amplab/tachyon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplab/tachyon/downloads","issues_url":"https://api.github.com/repos/amplab/tachyon/issues{/number}","pulls_url":"https://api.github.com/repos/amplab/tachyon/pulls{/number}","milestones_url":"https://api.github.com/repos/amplab/tachyon/milestones{/number}","notifications_url":"https://api.github.com/repos/amplab/tachyon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplab/tachyon/labels{/name}","releases_url":"https://api.github.com/repos/amplab/tachyon/releases{/id}","created_at":"2012-12-21T17:43:46Z","updated_at":"2015-07-01T04:17:01Z","pushed_at":"2015-07-01T20:08:21Z","git_url":"git://github.com/amplab/tachyon.git","ssh_url":"git@github.com:amplab/tachyon.git","clone_url":"https://github.com/amplab/tachyon.git","svn_url":"https://github.com/amplab/tachyon","homepage":"http://tachyon-project.org","size":34278,"stargazers_count":1459,"watchers_count":1459,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":538,"mirror_url":null,"open_issues_count":18,"forks":538,"open_issues":18,"watchers":1459,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1017"},"html":{"href":"https://github.com/amplab/tachyon/pull/1017"},"issue":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1017"},"comments":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1017/comments"},"review_comments":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1017/comments"},"review_comment":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1017/commits"},"statuses":{"href":"https://api.github.com/repos/amplab/tachyon/statuses/4af88fed3b24e16efbf39ac31564264d64821d47"}}}}