private void abortImpl(boolean abortAllRemaining) throws StreamingException {
    if (minTxnId == null) {
      return;
    }

    transactionLock.lock();
    try {
      if (abortAllRemaining) {
        // we are aborting all txns in the current batch, so no need to heartbeat
        minTxnId.set(-1);
        //when last txn finished (abortTransaction/commitTransaction) the currentTxnIndex is pointing at that txn
        //so we need to start from next one, if any.  Also if batch was created but
        //fetchTransactionBatch() was never called, we want to start with first txn
        int minOpenTxnIndex = Math.max(currentTxnIndex +
            (state == HiveStreamingConnection.TxnState.ABORTED
                || state == HiveStreamingConnection.TxnState.COMMITTED
                ? 1 : 0), 0);
        for (currentTxnIndex = minOpenTxnIndex;
             currentTxnIndex < txnToWriteIds.size(); currentTxnIndex++) {
          AbortTxnRequest abortTxnRequest = new AbortTxnRequest(txnToWriteIds.get(currentTxnIndex).getTxnId());
          abortTxnRequest.setErrorCode(TxnErrorMsg.ABORT_ROLLBACK.getErrorCode());
          conn.getMSC().rollbackTxn(abortTxnRequest);
          txnStatus[currentTxnIndex] = HiveStreamingConnection.TxnState.ABORTED;
        }
        currentTxnIndex--; //since the loop left it == txnToWriteIds.size()
      } else {
        // we are aborting only the current transaction, so move the min range for heartbeat or disable heartbeat
        // if the current txn is last in the batch.
        if (currentTxnIndex + 1 < txnToWriteIds.size()) {
          minTxnId.set(txnToWriteIds.get(currentTxnIndex + 1).getTxnId());
        } else {
          // exhausted the batch, no longer have to heartbeat
          minTxnId.set(-1);
        }
        long currTxnId = getCurrentTxnId();
        if (currTxnId > 0) {
          AbortTxnRequest abortTxnRequest = new AbortTxnRequest(currTxnId);
          abortTxnRequest.setErrorCode(TxnErrorMsg.ABORT_ROLLBACK.getErrorCode());
          conn.getMSC().rollbackTxn(abortTxnRequest);
          txnStatus[currentTxnIndex] = HiveStreamingConnection.TxnState.ABORTED;
        }
      }
      state = HiveStreamingConnection.TxnState.ABORTED;
    } catch (NoSuchTxnException e) {
      throw new TransactionError("Unable to abort invalid transaction id : "
          + getCurrentTxnId(), e);
    } catch (TException e) {
      throw new TransactionError("Unable to abort transaction id : "
          + getCurrentTxnId(), e);
    } finally {
      transactionLock.unlock();
    }
  }
Represents a batch of transactions acquired from MetaStore.

@param conn - hive streaming connection
@throws StreamingException if failed to create new RecordUpdater for batch
streaming/src/java/org/apache/hive/streaming/TransactionBatch.java