{"action":"created","comment":{"url":"https://api.github.com/repos/apache/drill/pulls/comments/86074061","pull_request_review_id":6749624,"id":86074061,"diff_hunk":"@@ -0,0 +1,149 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ * <p/>\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ * <p/>\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+package org.apache.drill.exec.planner.fragment;\n+\n+import com.google.common.collect.Lists;\n+import org.apache.drill.exec.physical.EndpointAffinity;\n+import org.apache.drill.exec.physical.PhysicalOperatorSetupException;\n+import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;\n+\n+import java.util.Map;\n+import java.util.List;\n+import java.util.Collection;\n+import java.util.HashMap;\n+\n+\n+/**\n+ * Implementation of {@link FragmentParallelizer} where fragment has zero or more endpoints.\n+ * This is for Parquet Scan Fragments only. Fragment placement is done preferring strict\n+ * data locality.\n+ */\n+public class LocalAffinityFragmentParallelizer implements FragmentParallelizer {\n+    public static final LocalAffinityFragmentParallelizer INSTANCE = new LocalAffinityFragmentParallelizer();\n+\n+    @Override\n+    public void parallelizeFragment(final Wrapper fragmentWrapper, final ParallelizationParameters parameters, final Collection<DrillbitEndpoint> activeEndpoints) throws PhysicalOperatorSetupException {\n+\n+        // Find the parallelization width of fragment\n+        final Stats stats = fragmentWrapper.getStats();\n+        final ParallelizationInfo parallelizationInfo = stats.getParallelizationInfo();\n+\n+        // 1. Find the parallelization based on cost. Use max cost of all operators in this fragment; this is consistent\n+        //    with the calculation that ExcessiveExchangeRemover uses.\n+        int width = (int) Math.ceil(stats.getMaxCost() / parameters.getSliceTarget());\n+\n+        // 2. Cap the parallelization width by fragment level width limit and system level per query width limit\n+        width = Math.min(width, Math.min(parallelizationInfo.getMaxWidth(), parameters.getMaxGlobalWidth()));\n+\n+        // 3. Cap the parallelization width by system level per node width limit\n+        width = Math.min(width, parameters.getMaxWidthPerNode() * activeEndpoints.size());\n+\n+        // 4. Make sure width is at least the min width enforced by operators\n+        width = Math.max(parallelizationInfo.getMinWidth(), width);\n+\n+        // 5. Make sure width is at most the max width enforced by operators\n+        width = Math.min(parallelizationInfo.getMaxWidth(), width);\n+\n+        // 6: Finally make sure the width is at least one\n+        width = Math.max(1, width);\n+\n+        List<DrillbitEndpoint> endpointPool = Lists.newArrayList();\n+        List<DrillbitEndpoint> assignedEndPoints = Lists.newArrayList();\n+\n+        Map<DrillbitEndpoint, EndpointAffinity> endpointAffinityMap =\n+            fragmentWrapper.getStats().getParallelizationInfo().getEndpointAffinityMap();\n+\n+        int totalAssigned = 0;\n+        int totalWorkUnits = 0;\n+\n+        // Get the total number of work units and list of endPoints to schedule fragments on\n+        for (Map.Entry<DrillbitEndpoint, EndpointAffinity> epAff : endpointAffinityMap.entrySet()) {\n+            if (epAff.getValue().getNumLocalWorkUnits() > 0) {\n+                totalWorkUnits += epAff.getValue().getNumLocalWorkUnits();\n+                endpointPool.add(epAff.getKey());\n+            }\n+        }\n+\n+        // Keep track of number of fragments allocated to each endpoint.\n+        Map<DrillbitEndpoint, Integer> endpointAssignments = new HashMap<>();\n+\n+        // Keep track of how many more to assign to each endpoint.\n+        Map<DrillbitEndpoint, Integer> remainingEndpointAssignments = new HashMap<>();\n+\n+        // Calculate the target allocation for each endPoint based on work it has to do\n+        // Assign one fragment (minimum) to all the endPoints in the pool.\n+        for (DrillbitEndpoint ep : endpointPool) {\n+            int targetAllocation = (int) Math.ceil(endpointAffinityMap.get(ep).getNumLocalWorkUnits() * width / parallelizationInfo.getMaxWidth());\n+            assignedEndPoints.add(ep);\n+            totalAssigned++;\n+            remainingEndpointAssignments.put(ep, targetAllocation-1);\n+            endpointAssignments.put(ep, 1);\n+        }\n+\n+        // Keep allocating from endpoints in a round robin fashion upto\n+        // max(targetAllocation, maxwidthPerNode) for each endpoint and\n+        // upto width for all together.\n+        while(totalAssigned < width) {\n+            int assignedThisRound = 0;\n+            for (DrillbitEndpoint ep : endpointPool) {\n+                if (remainingEndpointAssignments.get(ep) > 0 &&\n+                    remainingEndpointAssignments.get(ep) < parameters.getMaxWidthPerNode()) {\n+                    assignedEndPoints.add(ep);\n+                    remainingEndpointAssignments.put(ep, remainingEndpointAssignments.get(ep) - 1);\n+                    totalAssigned++;\n+                    assignedThisRound++;\n+                    endpointAssignments.put(ep, endpointAssignments.get(ep) + 1);\n+                }\n+                if (totalAssigned == width) {\n+                    break;\n+                }\n+            }\n+            if (assignedThisRound == 0) {\n+                break;\n+            }\n+        }\n+\n+        // This is for the case where drillbits are not running on endPoints which have data.\n+        // Allocate them from the active endpoint pool.\n+        int totalUnAssigned =","path":"exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/LocalAffinityFragmentParallelizer.java","position":123,"original_position":123,"commit_id":"7a2305c24a0f3158b660b9fbe1c5860fadec23b4","original_commit_id":"7a2305c24a0f3158b660b9fbe1c5860fadec23b4","user":{"login":"sudheeshkatkam","id":3272600,"avatar_url":"https://avatars.githubusercontent.com/u/3272600?v=3","gravatar_id":"","url":"https://api.github.com/users/sudheeshkatkam","html_url":"https://github.com/sudheeshkatkam","followers_url":"https://api.github.com/users/sudheeshkatkam/followers","following_url":"https://api.github.com/users/sudheeshkatkam/following{/other_user}","gists_url":"https://api.github.com/users/sudheeshkatkam/gists{/gist_id}","starred_url":"https://api.github.com/users/sudheeshkatkam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sudheeshkatkam/subscriptions","organizations_url":"https://api.github.com/users/sudheeshkatkam/orgs","repos_url":"https://api.github.com/users/sudheeshkatkam/repos","events_url":"https://api.github.com/users/sudheeshkatkam/events{/privacy}","received_events_url":"https://api.github.com/users/sudheeshkatkam/received_events","type":"User","site_admin":false},"body":"So this parallelizer is not strictly local? Why not fail?","created_at":"2016-11-02T05:07:18Z","updated_at":"2016-11-02T05:28:31Z","html_url":"https://github.com/apache/drill/pull/639#discussion_r86074061","pull_request_url":"https://api.github.com/repos/apache/drill/pulls/639","_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/comments/86074061"},"html":{"href":"https://github.com/apache/drill/pull/639#discussion_r86074061"},"pull_request":{"href":"https://api.github.com/repos/apache/drill/pulls/639"}}},"pull_request":{"url":"https://api.github.com/repos/apache/drill/pulls/639","id":91641248,"html_url":"https://github.com/apache/drill/pull/639","diff_url":"https://github.com/apache/drill/pull/639.diff","patch_url":"https://github.com/apache/drill/pull/639.patch","issue_url":"https://api.github.com/repos/apache/drill/issues/639","number":639,"state":"open","locked":false,"title":"DRILL-4706: Fragment planning causes Drillbits to read remote chunks when local copies are available. ","user":{"login":"ppadma","id":1904860,"avatar_url":"https://avatars.githubusercontent.com/u/1904860?v=3","gravatar_id":"","url":"https://api.github.com/users/ppadma","html_url":"https://github.com/ppadma","followers_url":"https://api.github.com/users/ppadma/followers","following_url":"https://api.github.com/users/ppadma/following{/other_user}","gists_url":"https://api.github.com/users/ppadma/gists{/gist_id}","starred_url":"https://api.github.com/users/ppadma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppadma/subscriptions","organizations_url":"https://api.github.com/users/ppadma/orgs","repos_url":"https://api.github.com/users/ppadma/repos","events_url":"https://api.github.com/users/ppadma/events{/privacy}","received_events_url":"https://api.github.com/users/ppadma/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-31T16:24:13Z","updated_at":"2016-11-02T05:28:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c75f1375e1e776cf5ea4f4cb06ff13698812de6a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/drill/pulls/639/commits","review_comments_url":"https://api.github.com/repos/apache/drill/pulls/639/comments","review_comment_url":"https://api.github.com/repos/apache/drill/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/drill/issues/639/comments","statuses_url":"https://api.github.com/repos/apache/drill/statuses/7a2305c24a0f3158b660b9fbe1c5860fadec23b4","head":{"label":"ppadma:DRILL-4706","ref":"DRILL-4706","sha":"7a2305c24a0f3158b660b9fbe1c5860fadec23b4","user":{"login":"ppadma","id":1904860,"avatar_url":"https://avatars.githubusercontent.com/u/1904860?v=3","gravatar_id":"","url":"https://api.github.com/users/ppadma","html_url":"https://github.com/ppadma","followers_url":"https://api.github.com/users/ppadma/followers","following_url":"https://api.github.com/users/ppadma/following{/other_user}","gists_url":"https://api.github.com/users/ppadma/gists{/gist_id}","starred_url":"https://api.github.com/users/ppadma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppadma/subscriptions","organizations_url":"https://api.github.com/users/ppadma/orgs","repos_url":"https://api.github.com/users/ppadma/repos","events_url":"https://api.github.com/users/ppadma/events{/privacy}","received_events_url":"https://api.github.com/users/ppadma/received_events","type":"User","site_admin":false},"repo":{"id":62423374,"name":"drill","full_name":"ppadma/drill","owner":{"login":"ppadma","id":1904860,"avatar_url":"https://avatars.githubusercontent.com/u/1904860?v=3","gravatar_id":"","url":"https://api.github.com/users/ppadma","html_url":"https://github.com/ppadma","followers_url":"https://api.github.com/users/ppadma/followers","following_url":"https://api.github.com/users/ppadma/following{/other_user}","gists_url":"https://api.github.com/users/ppadma/gists{/gist_id}","starred_url":"https://api.github.com/users/ppadma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppadma/subscriptions","organizations_url":"https://api.github.com/users/ppadma/orgs","repos_url":"https://api.github.com/users/ppadma/repos","events_url":"https://api.github.com/users/ppadma/events{/privacy}","received_events_url":"https://api.github.com/users/ppadma/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ppadma/drill","description":"Mirror of Apache Drill","fork":true,"url":"https://api.github.com/repos/ppadma/drill","forks_url":"https://api.github.com/repos/ppadma/drill/forks","keys_url":"https://api.github.com/repos/ppadma/drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ppadma/drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ppadma/drill/teams","hooks_url":"https://api.github.com/repos/ppadma/drill/hooks","issue_events_url":"https://api.github.com/repos/ppadma/drill/issues/events{/number}","events_url":"https://api.github.com/repos/ppadma/drill/events","assignees_url":"https://api.github.com/repos/ppadma/drill/assignees{/user}","branches_url":"https://api.github.com/repos/ppadma/drill/branches{/branch}","tags_url":"https://api.github.com/repos/ppadma/drill/tags","blobs_url":"https://api.github.com/repos/ppadma/drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ppadma/drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ppadma/drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/ppadma/drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ppadma/drill/statuses/{sha}","languages_url":"https://api.github.com/repos/ppadma/drill/languages","stargazers_url":"https://api.github.com/repos/ppadma/drill/stargazers","contributors_url":"https://api.github.com/repos/ppadma/drill/contributors","subscribers_url":"https://api.github.com/repos/ppadma/drill/subscribers","subscription_url":"https://api.github.com/repos/ppadma/drill/subscription","commits_url":"https://api.github.com/repos/ppadma/drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/ppadma/drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/ppadma/drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/ppadma/drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/ppadma/drill/contents/{+path}","compare_url":"https://api.github.com/repos/ppadma/drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ppadma/drill/merges","archive_url":"https://api.github.com/repos/ppadma/drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ppadma/drill/downloads","issues_url":"https://api.github.com/repos/ppadma/drill/issues{/number}","pulls_url":"https://api.github.com/repos/ppadma/drill/pulls{/number}","milestones_url":"https://api.github.com/repos/ppadma/drill/milestones{/number}","notifications_url":"https://api.github.com/repos/ppadma/drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ppadma/drill/labels{/name}","releases_url":"https://api.github.com/repos/ppadma/drill/releases{/id}","deployments_url":"https://api.github.com/repos/ppadma/drill/deployments","created_at":"2016-07-01T22:38:58Z","updated_at":"2016-07-01T22:39:07Z","pushed_at":"2016-11-01T23:32:34Z","git_url":"git://github.com/ppadma/drill.git","ssh_url":"git@github.com:ppadma/drill.git","clone_url":"https://github.com/ppadma/drill.git","svn_url":"https://github.com/ppadma/drill","homepage":"","size":42752,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"1e6fa00cd4b0b1db41614749f6d12c03f0ca7990","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":5683653,"name":"drill","full_name":"apache/drill","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/drill","description":"Mirror of Apache Drill","fork":false,"url":"https://api.github.com/repos/apache/drill","forks_url":"https://api.github.com/repos/apache/drill/forks","keys_url":"https://api.github.com/repos/apache/drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/drill/teams","hooks_url":"https://api.github.com/repos/apache/drill/hooks","issue_events_url":"https://api.github.com/repos/apache/drill/issues/events{/number}","events_url":"https://api.github.com/repos/apache/drill/events","assignees_url":"https://api.github.com/repos/apache/drill/assignees{/user}","branches_url":"https://api.github.com/repos/apache/drill/branches{/branch}","tags_url":"https://api.github.com/repos/apache/drill/tags","blobs_url":"https://api.github.com/repos/apache/drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/drill/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/drill/languages","stargazers_url":"https://api.github.com/repos/apache/drill/stargazers","contributors_url":"https://api.github.com/repos/apache/drill/contributors","subscribers_url":"https://api.github.com/repos/apache/drill/subscribers","subscription_url":"https://api.github.com/repos/apache/drill/subscription","commits_url":"https://api.github.com/repos/apache/drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/drill/contents/{+path}","compare_url":"https://api.github.com/repos/apache/drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/drill/merges","archive_url":"https://api.github.com/repos/apache/drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/drill/downloads","issues_url":"https://api.github.com/repos/apache/drill/issues{/number}","pulls_url":"https://api.github.com/repos/apache/drill/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/drill/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/drill/labels{/name}","releases_url":"https://api.github.com/repos/apache/drill/releases{/id}","deployments_url":"https://api.github.com/repos/apache/drill/deployments","created_at":"2012-09-05T07:00:26Z","updated_at":"2016-11-01T11:04:34Z","pushed_at":"2016-11-02T03:50:28Z","git_url":"git://github.com/apache/drill.git","ssh_url":"git@github.com:apache/drill.git","clone_url":"https://github.com/apache/drill.git","svn_url":"https://github.com/apache/drill","homepage":"","size":52527,"stargazers_count":707,"watchers_count":707,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":485,"mirror_url":"git://git.apache.org/drill.git","open_issues_count":125,"forks":485,"open_issues":125,"watchers":707,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/639"},"html":{"href":"https://github.com/apache/drill/pull/639"},"issue":{"href":"https://api.github.com/repos/apache/drill/issues/639"},"comments":{"href":"https://api.github.com/repos/apache/drill/issues/639/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/drill/pulls/639/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/drill/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/drill/pulls/639/commits"},"statuses":{"href":"https://api.github.com/repos/apache/drill/statuses/7a2305c24a0f3158b660b9fbe1c5860fadec23b4"}}}}
{"actor":{"display_login":"sudheeshkatkam"}}