public static void cleanDb(Configuration conf) throws Exception {
    LOG.info("Cleaning transactional tables");

    boolean success = true;
    Connection conn = null;
    Statement stmt = null;
    try {
      conn = getConnection(conf);
      stmt = conn.createStatement();
      if (!checkDbPrepared(stmt)){
        // Nothing to clean
        return;
      }

      // We want to try these, whether they succeed or fail.
      success &= truncateTable(conn, conf, stmt, "TXN_COMPONENTS");
      success &= truncateTable(conn, conf, stmt, "COMPLETED_TXN_COMPONENTS");
      success &= truncateTable(conn, conf, stmt, "MIN_HISTORY_WRITE_ID");
      success &= truncateTable(conn, conf, stmt, "TXNS");
      success &= truncateTable(conn, conf, stmt, "TXN_TO_WRITE_ID");
      success &= truncateTable(conn, conf, stmt, "NEXT_WRITE_ID");
      success &= truncateTable(conn, conf, stmt, "HIVE_LOCKS");
      success &= truncateTable(conn, conf, stmt, "NEXT_LOCK_ID");
      success &= truncateTable(conn, conf, stmt, "COMPACTION_QUEUE");
      success &= truncateTable(conn, conf, stmt, "NEXT_COMPACTION_QUEUE_ID");
      success &= truncateTable(conn, conf, stmt, "COMPLETED_COMPACTIONS");
      success &= truncateTable(conn, conf, stmt, "AUX_TABLE");
      success &= truncateTable(conn, conf, stmt, "WRITE_SET");
      success &= truncateTable(conn, conf, stmt, "REPL_TXN_MAP");
      success &= truncateTable(conn, conf, stmt, "MATERIALIZATION_REBUILD_LOCKS");
      success &= truncateTable(conn, conf, stmt, "MIN_HISTORY_LEVEL");
      success &= truncateTable(conn, conf, stmt, "COMPACTION_METRICS_CACHE");
      try {
        String dbProduct = conn.getMetaData().getDatabaseProductName();
        DatabaseProduct databaseProduct = determineDatabaseProduct(dbProduct, conf);
        try {
          resetTxnSequence(databaseProduct, stmt);
          stmt.executeUpdate("INSERT INTO \"NEXT_LOCK_ID\" VALUES(1)");
          stmt.executeUpdate("INSERT INTO \"NEXT_COMPACTION_QUEUE_ID\" VALUES(1)");
        } catch (SQLException e) {
          if (!databaseProduct.isTableNotExistsError(e)) {
            LOG.error("Error initializing sequence values", e);
            throw e;
          }
        }
      } catch (SQLException e) {
        LOG.error("Unable determine database product ", e);
        throw e;
      }
      /*
       * Don't drop NOTIFICATION_LOG, SEQUENCE_TABLE and NOTIFICATION_SEQUENCE as its used by other
       * table which are not txn related to generate primary key. So if these tables are dropped
       *  and other tables are not dropped, then it will create key duplicate error while inserting
       *  to other table.
       */
    } finally {
      closeResources(conn, stmt, null);
    }
    if(success) {
      return;
    }
    throw new RuntimeException("Failed to clean up txn tables");
  }
Prepares the metastore database for unit tests.
Runs the latest init schema against the database configured in the CONNECT_URL_KEY param.
Ignores any duplication (table, index etc.) So it can be called multiple times for the same database.
@param conf Metastore configuration
@throws Exception Initialization failure
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestTxnDbUtil.java