private void rollbackCommit(Thread thread, TransactionImpl tx)
      throws HeuristicMixedException, RollbackException, SystemException {
    try {
      tx.doRollback();
    } catch (XAException e) {
      log.log(
          Level.SEVERE,
          "Unable to rollback marked transaction. "
              + "Some resources may be commited others not. "
              + "Neo4j kernel should be SHUTDOWN for "
              + "resource maintance and transaction recovery ---->",
          e);
      setTmNotOk(e);
      throw logAndReturn(
          "TM error tx rollback commit",
          Exceptions.withCause(
              new HeuristicMixedException(
                  "Unable to rollback " + " ---> error code for rollback: " + e.errorCode),
              e));
    }

    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
      if (tx.isGlobalStartRecordWritten()) {
        getTxLog().txDone(tx.getGlobalId());
      }
    } catch (IOException e) {
      log.log(Level.SEVERE, "Error writing transaction log", e);
      setTmNotOk(e);
      throw logAndReturn(
          "TM error tx rollback commit",
          Exceptions.withCause(
              new SystemException("TM encountered a problem, " + " error writing transaction log"),
              e));
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
    RollbackException rollbackException =
        new RollbackException("Failed to commit, transaction rolledback");
    ExceptionCauseSetter.setCause(rollbackException, tx.getRollbackCause());
    throw rollbackException;
  }