{"action":"created","comment":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/comments/34410596","id":34410596,"diff_hunk":"@@ -16,72 +16,92 @@\n package tachyon.worker.block.evictor;\n \n import java.io.IOException;\n-import java.util.ArrayList;\n-import java.util.Collections;\n import java.util.HashMap;\n-import java.util.List;\n import java.util.Map;\n \n import tachyon.Pair;\n import tachyon.worker.block.BlockMetadataManager;\n import tachyon.worker.block.BlockStoreLocation;\n import tachyon.worker.block.meta.BlockMeta;\n+import tachyon.worker.block.meta.StorageDir;\n \n public class EvictorUtils {\n   /**\n-   * Checks whether the plan is legal for an evictor with cascading eviction feature like\n+   * Checks whether the plan is valid for an evictor with cascading eviction feature like\n    * {@link LRUEvictor}. The plan is legal when the requested space can be satisfied, and there is\n    * enough space in lower tier to move in blocks from upper tier.\n    *\n    * @param bytesToBeAvailable requested bytes to be available after eviction\n-   * @param plan the eviction plan\n+   * @param plan the eviction plan, should not be empty\n    * @param metaManager the meta data manager\n    * @return true if the above requirements are satisfied, otherwise false.\n    */\n-  public static boolean legalCascadingPlan(long bytesToBeAvailable, EvictionPlan plan,\n+  public static boolean validCascadingPlan(long bytesToBeAvailable, EvictionPlan plan,\n       BlockMetadataManager metaManager) throws IOException {\n     // reassure the plan is feasible: enough free space to satisfy bytesToBeAvailable, and enough\n     // space in lower tier to move blocks in upper tier there\n-    Map<Integer, Long> bytesToBeAvailableInTier =\n-        new HashMap<Integer, Long>(metaManager.getTiers().size());\n-    List<Integer> tierAliases = new ArrayList<Integer>();\n \n-    List<Long> blockIds = new ArrayList<Long>(plan.toEvict().size() + plan.toMove().size());\n-    blockIds.addAll(plan.toEvict());\n-    for (Pair<Long, BlockStoreLocation> move : plan.toMove()) {\n-      blockIds.add(move.getFirst());\n+    // Map from dir to a pair of bytes to be available in this dir and bytes to move into this dir\n+    // after the plan taking action\n+    Map<StorageDir, Pair<Long, Long>> spaceInfoInDir = new HashMap<StorageDir, Pair<Long, Long>>();\n+\n+    for (long blockId : plan.toEvict()) {\n+      BlockMeta block = metaManager.getBlockMeta(blockId);\n+      StorageDir dir = block.getParentDir();\n+      if (spaceInfoInDir.containsKey(dir)) {\n+        Pair<Long, Long> spaceInfo = spaceInfoInDir.get(dir);\n+        spaceInfo.setFirst(spaceInfo.getFirst() + block.getBlockSize());\n+      } else {\n+        spaceInfoInDir.put(dir, new Pair<Long, Long>(\n+            dir.getAvailableBytes() + block.getBlockSize(), 0L));\n+      }\n     }\n \n-    for (long blockId : blockIds) {\n+    for (Pair<Long, BlockStoreLocation> move : plan.toMove()) {\n+      long blockId = move.getFirst();\n       BlockMeta block = metaManager.getBlockMeta(blockId);\n-      BlockStoreLocation blockDir = block.getBlockLocation();\n       long blockSize = block.getBlockSize();\n-      int tierAlias = blockDir.tierAlias();\n-      if (bytesToBeAvailableInTier.containsKey(tierAlias)) {\n-        bytesToBeAvailableInTier\n-            .put(tierAlias, bytesToBeAvailableInTier.get(tierAlias) + blockSize);\n+      StorageDir srcDir = block.getParentDir();\n+      StorageDir destDir = metaManager.getDir(move.getSecond());\n+\n+      if (spaceInfoInDir.containsKey(srcDir)) {\n+        Pair<Long, Long> spaceInfo = spaceInfoInDir.get(srcDir);\n+        spaceInfo.setFirst(spaceInfo.getFirst() + blockSize);\n+      } else {\n+        spaceInfoInDir\n+            .put(srcDir, new Pair<Long, Long>(srcDir.getAvailableBytes() + blockSize, 0L));\n+      }\n+\n+      if (spaceInfoInDir.containsKey(destDir)) {\n+        Pair<Long, Long> spaceInfo = spaceInfoInDir.get(destDir);\n+        spaceInfo.setSecond(spaceInfo.getSecond() + blockSize);\n       } else {\n-        tierAliases.add(tierAlias);\n-        bytesToBeAvailableInTier\n-            .put(tierAlias, metaManager.getAvailableBytes(blockDir) + blockSize);\n+        spaceInfoInDir.put(destDir, new Pair<Long, Long>(destDir.getAvailableBytes(), blockSize));\n+      }\n+    }\n+\n+    int firstTierAlias = Integer.MAX_VALUE;\n+    for (StorageDir dir : spaceInfoInDir.keySet()) {\n+      firstTierAlias = Math.min(firstTierAlias, dir.getParentTier().getTierAlias());\n+    }\n+    long maxSpace = Long.MIN_VALUE; // maximum bytes to be available in a dir in the first tier\n+    for (StorageDir dir : spaceInfoInDir.keySet()) {\n+      if (dir.getParentTier().getTierAlias() == firstTierAlias) {\n+        Pair<Long, Long> space = spaceInfoInDir.get(dir);\n+        maxSpace = Math.max(maxSpace, space.getFirst() - space.getSecond());\n       }\n     }\n+    if (maxSpace < bytesToBeAvailable) {\n+      return false;","path":"servers/src/main/java/tachyon/worker/block/evictor/EvictorUtils.java","position":102,"original_position":102,"commit_id":"a0d142e1f7ca75cb5db108e4c903a4c8fecbdc33","original_commit_id":"a0d142e1f7ca75cb5db108e4c903a4c8fecbdc33","user":{"login":"apc999","id":1413748,"avatar_url":"https://avatars.githubusercontent.com/u/1413748?v=3","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"body":"Comment on why this is an invalid plan","created_at":"2015-07-11T07:29:30Z","updated_at":"2015-07-11T07:29:30Z","html_url":"https://github.com/amplab/tachyon/pull/1093#discussion_r34410596","pull_request_url":"https://api.github.com/repos/amplab/tachyon/pulls/1093","_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments/34410596"},"html":{"href":"https://github.com/amplab/tachyon/pull/1093#discussion_r34410596"},"pull_request":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1093"}}},"pull_request":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/1093","id":39738739,"html_url":"https://github.com/amplab/tachyon/pull/1093","diff_url":"https://github.com/amplab/tachyon/pull/1093.diff","patch_url":"https://github.com/amplab/tachyon/pull/1093.patch","issue_url":"https://api.github.com/repos/amplab/tachyon/issues/1093","number":1093,"state":"open","locked":false,"title":"[TACHYON-619] Improve logic of legalCascadingPlan","user":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars.githubusercontent.com/u/3663941?v=3","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"body":"follow up PR https://github.com/amplab/tachyon/pull/1079","created_at":"2015-07-11T02:59:52Z","updated_at":"2015-07-11T07:29:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ea4a193d57ef348cdfaec4504bdf3c6b1e3c9fbb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amplab/tachyon/pulls/1093/commits","review_comments_url":"https://api.github.com/repos/amplab/tachyon/pulls/1093/comments","review_comment_url":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amplab/tachyon/issues/1093/comments","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/a0d142e1f7ca75cb5db108e4c903a4c8fecbdc33","head":{"label":"uronce-cc:cascading_lru","ref":"cascading_lru","sha":"a0d142e1f7ca75cb5db108e4c903a4c8fecbdc33","user":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars.githubusercontent.com/u/3663941?v=3","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"repo":{"id":21723448,"name":"tachyon","full_name":"uronce-cc/tachyon","owner":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars.githubusercontent.com/u/3663941?v=3","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/uronce-cc/tachyon","description":"Memory-centric Storage System for Big Data Analytics","fork":true,"url":"https://api.github.com/repos/uronce-cc/tachyon","forks_url":"https://api.github.com/repos/uronce-cc/tachyon/forks","keys_url":"https://api.github.com/repos/uronce-cc/tachyon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uronce-cc/tachyon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uronce-cc/tachyon/teams","hooks_url":"https://api.github.com/repos/uronce-cc/tachyon/hooks","issue_events_url":"https://api.github.com/repos/uronce-cc/tachyon/issues/events{/number}","events_url":"https://api.github.com/repos/uronce-cc/tachyon/events","assignees_url":"https://api.github.com/repos/uronce-cc/tachyon/assignees{/user}","branches_url":"https://api.github.com/repos/uronce-cc/tachyon/branches{/branch}","tags_url":"https://api.github.com/repos/uronce-cc/tachyon/tags","blobs_url":"https://api.github.com/repos/uronce-cc/tachyon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uronce-cc/tachyon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uronce-cc/tachyon/git/refs{/sha}","trees_url":"https://api.github.com/repos/uronce-cc/tachyon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uronce-cc/tachyon/statuses/{sha}","languages_url":"https://api.github.com/repos/uronce-cc/tachyon/languages","stargazers_url":"https://api.github.com/repos/uronce-cc/tachyon/stargazers","contributors_url":"https://api.github.com/repos/uronce-cc/tachyon/contributors","subscribers_url":"https://api.github.com/repos/uronce-cc/tachyon/subscribers","subscription_url":"https://api.github.com/repos/uronce-cc/tachyon/subscription","commits_url":"https://api.github.com/repos/uronce-cc/tachyon/commits{/sha}","git_commits_url":"https://api.github.com/repos/uronce-cc/tachyon/git/commits{/sha}","comments_url":"https://api.github.com/repos/uronce-cc/tachyon/comments{/number}","issue_comment_url":"https://api.github.com/repos/uronce-cc/tachyon/issues/comments{/number}","contents_url":"https://api.github.com/repos/uronce-cc/tachyon/contents/{+path}","compare_url":"https://api.github.com/repos/uronce-cc/tachyon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uronce-cc/tachyon/merges","archive_url":"https://api.github.com/repos/uronce-cc/tachyon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uronce-cc/tachyon/downloads","issues_url":"https://api.github.com/repos/uronce-cc/tachyon/issues{/number}","pulls_url":"https://api.github.com/repos/uronce-cc/tachyon/pulls{/number}","milestones_url":"https://api.github.com/repos/uronce-cc/tachyon/milestones{/number}","notifications_url":"https://api.github.com/repos/uronce-cc/tachyon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uronce-cc/tachyon/labels{/name}","releases_url":"https://api.github.com/repos/uronce-cc/tachyon/releases{/id}","created_at":"2014-07-11T05:40:12Z","updated_at":"2015-03-24T23:33:22Z","pushed_at":"2015-07-11T07:14:49Z","git_url":"git://github.com/uronce-cc/tachyon.git","ssh_url":"git@github.com:uronce-cc/tachyon.git","clone_url":"https://github.com/uronce-cc/tachyon.git","svn_url":"https://github.com/uronce-cc/tachyon","homepage":"http://tachyon-project.org","size":15476,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"amplab:master","ref":"master","sha":"a5fecac1926726eb817b6f61914c4553d9b17b5a","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-10T06:38:23Z","pushed_at":"2015-07-11T07:14:49Z","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":35108,"stargazers_count":1474,"watchers_count":1474,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":547,"mirror_url":null,"open_issues_count":20,"forks":547,"open_issues":20,"watchers":1474,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1093"},"html":{"href":"https://github.com/amplab/tachyon/pull/1093"},"issue":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1093"},"comments":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1093/comments"},"review_comments":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1093/comments"},"review_comment":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1093/commits"},"statuses":{"href":"https://api.github.com/repos/amplab/tachyon/statuses/a0d142e1f7ca75cb5db108e4c903a4c8fecbdc33"}}}}