You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2021/02/15 04:58:01 UTC

[GitHub] [hbase] anoopsjohn commented on a change in pull request #2947: HBASE-25566 RoundRobinTableInputFormat

anoopsjohn commented on a change in pull request #2947:
URL: https://github.com/apache/hbase/pull/2947#discussion_r575942942



##########
File path: hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/RoundRobinTableInputFormat.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.mapreduce;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.io.RawComparator;
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.JobID;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.mapreduce.OutputFormat;
+import org.apache.hadoop.mapreduce.Partitioner;
+import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.hadoop.mapreduce.task.JobContextImpl;
+import org.apache.hadoop.security.Credentials;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Process the lists that come back from {@link TableInputFormat} reordering so splits don't
+ * clump around Servers; try and spread the splits around the cluster.
+ * TIF returns splits in hbase:meta table order. Adjacent or near-adjacent
+ * Regions could be hosted on the same RegionServer. Task placement therefore
+ * could be lumpy with some RegionServers serving lots of inputs where other
+ * servers could be serving few or idle. See the below helpful Flipkart blog post for
+ * a description and from where the base of this code comes from.
+ * @see https://tech.flipkart.com/is-data-locality-always-out-of-the-box-in-hadoop-not-really-2ae9c95163cb
+ */
+@InterfaceAudience.Public
+public class RoundRobinTableInputFormat extends TableInputFormat {
+  @Override
+  public List<InputSplit> getSplits(JobContext context) throws IOException {
+    List<InputSplit> inputSplits = super.getSplits(context);
+    List<InputSplit> roundRobinInputSplits = new ArrayList<>();
+    Map<String, List<InputSplit>> regionServersInputSplits = new HashMap<>();
+    // Prepare a hashmap with each region server as key and list of Input Splits as value
+    if (inputSplits != null && !inputSplits.isEmpty()) {
+      for (InputSplit inputSplit : inputSplits) {
+        if (inputSplit instanceof TableSplit) {
+          String regionServer = ((TableSplit)inputSplit).getRegionLocation();
+          if (regionServer != null && !regionServer.isEmpty()) {
+            regionServersInputSplits.computeIfAbsent(regionServer,
+              k -> new LinkedList<>()).add(inputSplit);
+            continue;
+          }
+        }
+        // If TableSplit or region server not found, add it.
+        roundRobinInputSplits.add(inputSplit);
+      }
+    }
+    while (!regionServersInputSplits.isEmpty()) {
+      Iterator<String> iterator = regionServersInputSplits.keySet().iterator();
+      while (iterator.hasNext()) {
+        String regionServer = iterator.next();
+        List<InputSplit> inputSplitListForRegion = regionServersInputSplits.get(regionServer);

Review comment:
       If it was entrySet iterator, we can avoid this get call.  May be we can change it to be forEach() based simpler loop?  Much lesser code.  or you want keep the code as is in the original blog @saintstack ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org