@Test
  public void testAddPartitionHighVisibilityId() throws Exception {

    runStatementOnDriver("drop table if exists " + acidTblPartMsck);

    // Insert few rows
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(1,1,'p1'),(2,2,'p1'),(3,3,'p1')");
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(4,4,'p1')");
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(1,2,'p2'),(2,3,'p2'),(3,4,'p2')");

    //run Compaction
    runStatementOnDriver("alter table " + Table.ACIDTBLPART + " partition (p='p1') compact 'minor'");
    runWorker(hiveConf);
    runCleaner(hiveConf);

    List<String> r = runStatementOnDriver("select a, b from " + Table.ACIDTBLPART + " order by a, b");
    int[][] expected = { { 1, 1 }, { 1, 2 }, { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 4 }, { 4, 4 } };
    Assert.assertEquals(stringifyValues(expected), r);
    // Create target table
    runStatementOnDriver("create table " + acidTblPartMsck
        + " (a int, b int) partitioned by (p string) clustered by (a) into 2 buckets"
        + " stored as orc TBLPROPERTIES ('transactional'='true')");

    // copy files on fs
    FileSystem fs = FileSystem.get(hiveConf);
    FileUtil.copy(fs, new Path(getWarehouseDir() + "/" + Table.ACIDTBLPART.toString().toLowerCase() + "/p=p1"), fs,
        new Path(getWarehouseDir(), acidTblPartMsck), false, hiveConf);
    FileUtil.copy(fs, new Path(getWarehouseDir() + "/" + Table.ACIDTBLPART.toString().toLowerCase() + "/p=p2"), fs,
        new Path(getWarehouseDir(), acidTblPartMsck), false, hiveConf);

    FileStatus[] fileStatuses = fs.listStatus(new Path(getWarehouseDir(), acidTblPartMsck + "/p=p1"));
    // one compacted delta
    Assert.assertEquals(1, fileStatuses.length);
    // Rename the deltaDir to add a higher visibility transactionId
    Path deltaDir = fileStatuses[0].getPath();
    ParsedDeltaLight parsedDelta =  ParsedDeltaLight.parse(deltaDir);
    long oldTxnId = parsedDelta.getVisibilityTxnId();
    String newDeltaDir = AcidUtils.addVisibilitySuffix(deltaDir.toString().substring(0, deltaDir.toString().length() - 9), oldTxnId + 100);
    fs.rename(deltaDir, new Path(newDeltaDir));

    // call msk repair
    runStatementOnDriver("msck repair table " + acidTblPartMsck);

    Long nextTxnId = txnHandler.openTxns(new OpenTxnRequest(1, "localhost", "me")).getTxn_ids().get(0);
    Assert.assertTrue("TxnId should be incremented", nextTxnId > (oldTxnId + 100));
    txnHandler.abortTxn(new AbortTxnRequest(nextTxnId));
    // We have to wait for the MetastoreConf.TXN_OPENTXN_TIMEOUT otherwise our hypothetical txnId in the visibilityTxnId
    // will be considered open and we will not read the folder
    Thread.sleep(1000);
    r = runStatementOnDriver("select a, b from " + acidTblPartMsck + " order by a, b");
    Assert.assertEquals(stringifyValues(expected), r);

    runStatementOnDriver("drop table if exists " + acidTblPartMsck);
  }
Add a new partition to the table that contains a compacted folder with the visibilityTxnId
higher than the HighWaterMark in the HMS. This could happen if the HMS data was lost and we try to
repair the metadata. The system will set the txnId forward in the HMS.
@throws Exception
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMSCKRepairOnAcid.java