@Override
  public Integer execute(MultiDataSourceJdbcResource jdbcResource) throws MetaException {
    if (txnids.isEmpty()) {
      return 0;
    }
    Configuration conf = jdbcResource.getConf();
    Collections.sort(txnids);    
    LOG.debug("Aborting {} transaction(s) {} due to {}", txnids.size(), txnids, txnErrorMsg);
    
    int maxBatchSize = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.JDBC_MAX_BATCH_SIZE);    
    jdbcResource.execute(new RemoveTxnsFromMinHistoryLevelCommand(txnids));
    jdbcResource.execute(new RemoveWriteIdsFromMinHistoryCommand(txnids));
    
    Connection dbConn = jdbcResource.getConnection();
    try {
      DatabaseProduct dbProduct = jdbcResource.getDatabaseProduct();
      //This is an update statement, thus at any Isolation level will take Write locks so will block
      //all other ops using S4U on TXNS row.
      List<String> queries = new ArrayList<>();
      StringBuilder prefix = new StringBuilder();
      StringBuilder suffix = new StringBuilder();

      // add update txns queries to query list
      prefix.append("UPDATE \"TXNS\" SET \"TXN_STATE\" = ").append(TxnStatus.ABORTED)
          .append(" , \"TXN_META_INFO\" = ").append(txnErrorMsg.toSqlString())
          .append(" WHERE \"TXN_STATE\" = ").append(TxnStatus.OPEN).append(" AND ");
      if (checkHeartbeat) {
        suffix.append(" AND \"TXN_LAST_HEARTBEAT\" < ")
            .append(getEpochFn(dbProduct)).append("-")
            .append(MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.TXN_TIMEOUT, TimeUnit.MILLISECONDS));
      }
      TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids, "\"TXN_ID\"", true, false);
      int numUpdateQueries = queries.size();

      // add delete hive locks queries to query list
      prefix.setLength(0);
      suffix.setLength(0);
      prefix.append("DELETE FROM \"HIVE_LOCKS\" WHERE ");
      TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids, "\"HL_TXNID\"", false, false);

      // add delete mv rebuild locks queries to query list
      prefix.setLength(0);
      suffix.setLength(0);
      prefix.append("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE ");
      TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids, "\"MRL_TXN_ID\"", false, false);


      //If this abort is for REPL_CREATED TXN initiated outside the replication flow, then clean the corresponding entry
      //from REPL_TXN_MAP and mark that database as replication incompatible.
      if (!isReplReplayed) {
        for (String database : getDbNamesForReplayedTxns(jdbcResource, dbConn, txnids)) {
          markDbAsReplIncompatible(jdbcResource, database);
        }
        // Delete mapping from REPL_TXN_MAP if it exists.
        prefix.setLength(0);
        suffix.setLength(0);
        prefix.append("DELETE FROM \"REPL_TXN_MAP\" WHERE ");
        TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids, "\"RTM_TARGET_TXN_ID\"", false, false);
      }

      int numAborted = 0;
      try (Statement stmt = dbConn.createStatement()) {
        // execute all queries in the list in one batch
        if (skipCount) {
          executeQueriesInBatchNoCount(dbProduct, stmt, queries, maxBatchSize);
        } else {
          List<Integer> affectedRowsByQuery = executeQueriesInBatch(stmt, queries, maxBatchSize);
          numAborted = getUpdateCount(numUpdateQueries, affectedRowsByQuery);
        }
      }

      if (MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.METASTORE_ACIDMETRICS_EXT_ON)) {
        Metrics.getOrCreateCounter(MetricsConstants.TOTAL_NUM_ABORTED_TXNS).inc(txnids.size());
      }
      LOG.warn("Aborted {} transaction(s) {} due to {}", txnids.size(), txnids, txnErrorMsg);
      return numAborted;
    } catch (SQLException e) {
      throw new UncategorizedSQLException(null, null, e);
    }
  }
@param jdbcResource A {@link MultiDataSourceJdbcResource} instance responsible for providing all the necessary 
                    resources to be able to perform transactional database calls.
@return 0 if skipCount is true, the number of aborted transactions otherwise
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/AbortTxnsFunction.java