You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2017/09/13 05:17:30 UTC

hive git commit: HIVE-17410 : repl load task during subsequent DAG generation does not start from the last partition processed (Anishek Agarwal via Thejas Nair)

Repository: hive
Updated Branches:
  refs/heads/master 82370d167 -> 309e89110


HIVE-17410 : repl load task during subsequent DAG generation does not start from the last partition processed (Anishek Agarwal via Thejas Nair)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/309e8911
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/309e8911
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/309e8911

Branch: refs/heads/master
Commit: 309e89110f3ddf40e121c8a92edf273f4df8cc52
Parents: 82370d1
Author: Thejas M Nair <th...@hortonworks.com>
Authored: Tue Sep 12 22:17:19 2017 -0700
Committer: Thejas M Nair <th...@hortonworks.com>
Committed: Tue Sep 12 22:17:28 2017 -0700

----------------------------------------------------------------------
 ...TestReplicationScenariosAcrossInstances.java |   9 +-
 .../bootstrap/load/table/LoadPartitions.java    | 107 ++++++++++---------
 2 files changed, 64 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/309e8911/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java
index 2af728f..3dee0d2 100644
--- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java
+++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java
@@ -232,8 +232,8 @@ public class TestReplicationScenariosAcrossInstances {
         .run("create table t1 (id int)")
         .run("create table t2 (place string) partitioned by (country string)")
         .run("insert into table t2 partition(country='india') values ('bangalore')")
-        .run("insert into table t2 partition(country='india') values ('mumbai')")
-        .run("insert into table t2 partition(country='india') values ('delhi')")
+        .run("insert into table t2 partition(country='us') values ('austin')")
+        .run("insert into table t2 partition(country='france') values ('paris')")
         .run("create table t3 (rank int)")
         .dump(primaryDbName, null);
 
@@ -244,7 +244,8 @@ public class TestReplicationScenariosAcrossInstances {
         .run("show tables")
         .verifyResults(new String[] { "t1", "t2", "t3" })
         .run("repl status " + replicatedDbName)
-        .verifyResult(tuple.lastReplicationId);
-
+        .verifyResult(tuple.lastReplicationId)
+        .run("select country from t2 order by country")
+        .verifyResults(new String[] { "france", "india", "us" });
   }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/309e8911/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/table/LoadPartitions.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/table/LoadPartitions.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/table/LoadPartitions.java
index c944a13..e65ece1 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/table/LoadPartitions.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/table/LoadPartitions.java
@@ -27,9 +27,9 @@ import org.apache.hadoop.hive.ql.exec.Task;
 import org.apache.hadoop.hive.ql.exec.TaskFactory;
 import org.apache.hadoop.hive.ql.exec.Utilities;
 import org.apache.hadoop.hive.ql.exec.repl.ReplStateLogWork;
+import org.apache.hadoop.hive.ql.exec.repl.bootstrap.ReplLoadTask;
 import org.apache.hadoop.hive.ql.exec.repl.bootstrap.events.TableEvent;
 import org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.ReplicationState;
-import org.apache.hadoop.hive.ql.exec.repl.bootstrap.ReplLoadTask;
 import org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.TaskTracker;
 import org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.util.Context;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
@@ -44,12 +44,17 @@ import org.apache.hadoop.hive.ql.plan.DDLWork;
 import org.apache.hadoop.hive.ql.plan.ImportTableDesc;
 import org.apache.hadoop.hive.ql.plan.LoadTableDesc;
 import org.apache.hadoop.hive.ql.plan.MoveWork;
+import org.datanucleus.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import static org.apache.hadoop.hive.ql.exec.repl.bootstrap.load.ReplicationState.PartitionState;
 import static org.apache.hadoop.hive.ql.parse.ImportSemanticAnalyzer.isPartitioned;
@@ -173,21 +178,29 @@ public class LoadPartitions {
   private TaskTracker forNewTable() throws Exception {
     Iterator<AddPartitionDesc> iterator = event.partitionDescriptions(tableDesc).iterator();
     while (iterator.hasNext() && tracker.canAddMoreTasks()) {
-      AddPartitionDesc addPartitionDesc = iterator.next();
-      tracker.addTask(addSinglePartition(table, addPartitionDesc));
-      if (iterator.hasNext() && !tracker.canAddMoreTasks()) {
-        ReplicationState currentReplicationState =
-                new ReplicationState(new PartitionState(table.getTableName(), addPartitionDesc));
-        updateReplicationState(currentReplicationState);
-      }
+      AddPartitionDesc currentPartitionDesc = iterator.next();
+      /*
+       the currentPartitionDesc cannot be inlined as we need the hasNext() to be evaluated post the
+       current retrieved lastReplicatedPartition
+      */
+      addPartition(iterator.hasNext(), currentPartitionDesc);
     }
     return tracker;
   }
 
+  private void addPartition(boolean hasMorePartitions, AddPartitionDesc addPartitionDesc) throws Exception {
+    tracker.addTask(tasksForAddPartition(table, addPartitionDesc));
+    if (hasMorePartitions && !tracker.canAddMoreTasks()) {
+      ReplicationState currentReplicationState =
+          new ReplicationState(new PartitionState(table.getTableName(), addPartitionDesc));
+      updateReplicationState(currentReplicationState);
+    }
+  }
+
   /**
    * returns the root task for adding a partition
    */
-  private Task<? extends Serializable> addSinglePartition(Table table,
+  private Task<? extends Serializable> tasksForAddPartition(Table table,
       AddPartitionDesc addPartitionDesc) throws MetaException, IOException, HiveException {
     AddPartitionDesc.OnePartitionDesc partSpec = addPartitionDesc.getPartition(0);
     Path sourceWarehousePartitionLocation = new Path(partSpec.getLocation());
@@ -262,50 +275,48 @@ public class LoadPartitions {
 
   private TaskTracker forExistingTable(AddPartitionDesc lastPartitionReplicated) throws Exception {
     boolean encounteredTheLastReplicatedPartition = (lastPartitionReplicated == null);
+    Map<String, String> lastReplicatedPartSpec = null;
+    if (!encounteredTheLastReplicatedPartition) {
+      lastReplicatedPartSpec = lastPartitionReplicated.getPartition(0).getPartSpec();
+      LOG.info("Start processing from partition info spec : {}",
+          StringUtils.mapToString(lastReplicatedPartSpec));
+    }
+
     ReplicationSpec replicationSpec = event.replicationSpec();
-    LOG.debug("table partitioned");
+    Iterator<AddPartitionDesc> partitionIterator = event.partitionDescriptions(tableDesc).iterator();
+    while (!encounteredTheLastReplicatedPartition && partitionIterator.hasNext()) {
+      AddPartitionDesc addPartitionDesc = partitionIterator.next();
+      Map<String, String> currentSpec = addPartitionDesc.getPartition(0).getPartSpec();
+      encounteredTheLastReplicatedPartition = lastReplicatedPartSpec.equals(currentSpec);
+    }
 
-    Iterator<AddPartitionDesc> iterator = event.partitionDescriptions(tableDesc).iterator();
-    while (iterator.hasNext()) {
-      /*
-      encounteredTheLastReplicatedPartition will be set, when we break creation of partition tasks
-      for a table, as we have reached the limit of number of tasks we should create for execution.
-      in this case on the next run we have to iterate over the partitions desc to reach the last replicated
-      partition so that we can start replicating partitions after that.
-       */
-      AddPartitionDesc addPartitionDesc = iterator.next();
-      if (encounteredTheLastReplicatedPartition && tracker.canAddMoreTasks()) {
-        Map<String, String> partSpec = addPartitionDesc.getPartition(0).getPartSpec();
-        Partition ptn;
-
-        if ((ptn = context.hiveDb.getPartition(table, partSpec, false)) == null) {
-          if (!replicationSpec.isMetadataOnly()) {
-            forNewTable();
-          }
-        } else {
-          // If replicating, then the partition already existing means we need to replace, maybe, if
-          // the destination ptn's repl.last.id is older than the replacement's.
-          if (replicationSpec.allowReplacementInto(ptn.getParameters())) {
-            if (replicationSpec.isMetadataOnly()) {
-              tracker.addTask(alterSinglePartition(addPartitionDesc, replicationSpec, ptn));
-              if (iterator.hasNext() && !tracker.canAddMoreTasks()) {
-                tracker.setReplicationState(
-                    new ReplicationState(new PartitionState(table.getTableName(), addPartitionDesc)
-                    )
-                );
-              }
-            } else {
-              forNewTable();
+    while (partitionIterator.hasNext() && tracker.canAddMoreTasks()) {
+      AddPartitionDesc addPartitionDesc = partitionIterator.next();
+      Map<String, String> partSpec = addPartitionDesc.getPartition(0).getPartSpec();
+      Partition ptn = context.hiveDb.getPartition(table, partSpec, false);
+      if (ptn == null) {
+        if (!replicationSpec.isMetadataOnly()) {
+          addPartition(partitionIterator.hasNext(), addPartitionDesc);
+        }
+      } else {
+        // If replicating, then the partition already existing means we need to replace, maybe, if
+        // the destination ptn's repl.last.id is older than the replacement's.
+        if (replicationSpec.allowReplacementInto(ptn.getParameters())) {
+          if (replicationSpec.isMetadataOnly()) {
+            tracker.addTask(alterSinglePartition(addPartitionDesc, replicationSpec, ptn));
+            if (!tracker.canAddMoreTasks()) {
+              tracker.setReplicationState(
+                  new ReplicationState(
+                      new PartitionState(table.getTableName(), addPartitionDesc)
+                  )
+              );
             }
           } else {
-            // ignore this ptn, do nothing, not an error.
+            addPartition(partitionIterator.hasNext(), addPartitionDesc);
           }
+        } else {
+          // ignore this ptn, do nothing, not an error.
         }
-      } else {
-        Map<String, String> currentSpec = addPartitionDesc.getPartition(0).getPartSpec();
-        Map<String, String> lastReplicatedPartSpec =
-            lastPartitionReplicated.getPartition(0).getPartSpec();
-        encounteredTheLastReplicatedPartition = lastReplicatedPartSpec.equals(currentSpec);
       }
     }
     return tracker;