[ 
https://issues.apache.org/jira/browse/HIVE-23671?focusedWorklogId=454918&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-454918
 ]

ASF GitHub Bot logged work on HIVE-23671:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Jul/20 15:54
            Start Date: 06/Jul/20 15:54
    Worklog Time Spent: 10m 
      Work Description: pvargacl commented on a change in pull request #1087:
URL: https://github.com/apache/hive/pull/1087#discussion_r450318970



##########
File path: ql/src/test/org/apache/hadoop/hive/ql/TxnCommandsBaseForTests.java
##########
@@ -162,9 +163,23 @@ protected String getWarehouseDir() {
    * takes raw data and turns it into a string as if from Driver.getResults()
    * sorts rows in dictionary order
    */
-  List<String> stringifyValues(int[][] rowsIn) {
-    return TestTxnCommands2.stringifyValues(rowsIn);
+  public static List<String> stringifyValues(int[][] rowsIn) {
+    assert rowsIn.length > 0;
+    int[][] rows = rowsIn.clone();
+    Arrays.sort(rows, new TestTxnCommands2.RowComp());

Review comment:
       fixed

##########
File path: 
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java
##########
@@ -252,37 +241,165 @@ public void testInvalidPartitionKeyName()
   @Test
   public void testSkipInvalidPartitionKeyName()
     throws HiveException, AlreadyExistsException, IOException, 
MetastoreException {
-    hive.getConf().set(HiveConf.ConfVars.HIVE_MSCK_PATH_VALIDATION.varname, 
"skip");
+    
hive.getConf().set(MetastoreConf.ConfVars.MSCK_PATH_VALIDATION.getVarname(), 
"skip");
     checker = new HiveMetaStoreChecker(msc, hive.getConf());
-    Table table = createTestTable();
+    Table table = createTestTable(false);
     List<Partition> partitions = hive.getPartitions(table);
     assertEquals(2, partitions.size());
     // add a fake partition dir on fs
     fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
-    Path fakePart =
-        new Path(table.getDataLocation().toString(), 
"fakedate=2009-01-01/fakecity=sanjose");
-    fs.mkdirs(fakePart);
-    fs.deleteOnExit(fakePart);
+    addFolderToPath(fs, 
table.getDataLocation().toString(),"fakedate=2009-01-01/fakecity=sanjose");
     createPartitionsDirectoriesOnFS(table, 2);
-    CheckResult result = new CheckResult();
-    checker.checkMetastore(catName, dbName, tableName, null, null, result);
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
     assertEquals(Collections.<String> emptySet(), result.getTablesNotInMs());
     assertEquals(Collections.<String> emptySet(), result.getTablesNotOnFs());
     assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
     // only 2 valid partitions should be added
     assertEquals(2, result.getPartitionsNotInMs().size());
   }
 
-  private Table createTestTable() throws HiveException, AlreadyExistsException 
{
+  /*
+   * Tests the case when we have normal delta_dirs in the partition folder
+   * does not throw HiveException
+   */
+  @Test
+  public void testAddPartitionNormalDeltas() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000010_0000010_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000101_0000101_0000");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(101, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(0, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+  /*
+   * Tests the case when we have normal delta_dirs in the partition folder
+   * does not throw HiveException
+   */
+  @Test
+  public void testAddPartitionCompactedDeltas() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000010_0000015_v0000067");
+    addFolderToPath(fs, newPart.toString(), "delta_0000101_0000120_v0000087");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(120, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(87, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+  @Test
+  public void testAddPartitionCompactedBase() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, newPart.toString(), "base_0000003_v0000200");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(3, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(200, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+
+  @Test
+  public void testAddPartitionMMBase() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, newPart.toString(), "base_0000004");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(4, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(0, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+
+  @Test
+  public void testNoNPartitionedTable() throws Exception {
+    Table table = createNonPartitionedTable();
+    // add a partition dir on fs
+    fs = table.getDataLocation().getFileSystem(hive.getConf());
+
+    Path tablePath = table.getDataLocation();
+
+    // Add a few deltas
+    addFolderToPath(fs, tablePath.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, tablePath.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, tablePath.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, tablePath.toString(), "base_0000003_v0000200");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotInMs());
+    // Found the highest writeId
+    assertEquals(3, result.getMaxWriteId());
+    assertEquals(200, result.getMaxTxnId());
+  }
+
+  private Path addFolderToPath(FileSystem fs, String rootPath, String folder) 
throws IOException{

Review comment:
       fixed




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 454918)
    Time Spent: 7h 50m  (was: 7h 40m)

> MSCK repair should handle transactional tables in certain usecases
> ------------------------------------------------------------------
>
>                 Key: HIVE-23671
>                 URL: https://issues.apache.org/jira/browse/HIVE-23671
>             Project: Hive
>          Issue Type: Improvement
>          Components: Metastore
>            Reporter: Peter Varga
>            Assignee: Peter Varga
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 7h 50m
>  Remaining Estimate: 0h
>
> The MSCK REPAIR tool does not handle transactional tables too well. It can 
> find and add new partitions the same way as for non-transactional tables, but 
> since the writeId differences are not handled, the data can not read back 
> from the new partitions.
> We could handle some usecases when the writeIds in the HMS and the underlying 
> data are not conflicting. If the HMS does not contains allocated writes for 
> the table we can seed the table with the writeIds read from the directory 
> structrure.
> Real life use cases could be:
>  * Copy data files from one cluster to another with different HMS, create the 
> table and call MSCK REPAIR
>  * If the HMS db is lost, recreate the table and call MSCK REPAIR
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to