/**
   * This will look through the completed_txn_components table and look for partitions or tables
   * that may be ready for compaction. Also, look through txns and txn_components tables for aborted
   * transactions that we should add to the list.
   *
   * @param maxAborted Maximum number of aborted queries to allow before marking this as a potential
   *     compaction.
   * @return list of CompactionInfo structs. These will not have id, type, or runAs set since these
   *     are only potential compactions not actual ones.
   */
  public Set<CompactionInfo> findPotentialCompactions(int maxAborted) throws MetaException {
    Connection dbConn = getDbConn();
    Set<CompactionInfo> response = new HashSet<CompactionInfo>();
    try {
      Statement stmt = dbConn.createStatement();
      // Check for completed transactions
      String s =
          "select distinct ctc_database, ctc_table, "
              + "ctc_partition from COMPLETED_TXN_COMPONENTS";
      LOG.debug("Going to execute query <" + s + ">");
      ResultSet rs = stmt.executeQuery(s);
      while (rs.next()) {
        CompactionInfo info = new CompactionInfo();
        info.dbname = rs.getString(1);
        info.tableName = rs.getString(2);
        info.partName = rs.getString(3);
        response.add(info);
      }

      // Check for aborted txns
      s =
          "select tc_database, tc_table, tc_partition "
              + "from TXNS, TXN_COMPONENTS "
              + "where txn_id = tc_txnid and txn_state = '"
              + TXN_ABORTED
              + "' "
              + "group by tc_database, tc_table, tc_partition "
              + "having count(*) > "
              + maxAborted;

      LOG.debug("Going to execute query <" + s + ">");
      rs = stmt.executeQuery(s);
      while (rs.next()) {
        CompactionInfo info = new CompactionInfo();
        info.dbname = rs.getString(1);
        info.tableName = rs.getString(2);
        info.partName = rs.getString(3);
        info.tooManyAborts = true;
        response.add(info);
      }

      LOG.debug("Going to rollback");
      dbConn.rollback();
    } catch (SQLException e) {
      LOG.error("Unable to connect to transaction database " + e.getMessage());
    } finally {
      closeDbConn(dbConn);
    }
    return response;
  }