Search in sources :

Example 1 with GetValidWriteIdsResponse

use of org.apache.hadoop.hive.metastore.api.GetValidWriteIdsResponse in project hive by apache.

the class TxnHandler method getValidWriteIds.

@Override
@RetrySemantics.ReadOnly
public GetValidWriteIdsResponse getValidWriteIds(GetValidWriteIdsRequest rqst) throws NoSuchTxnException, MetaException {
    try {
        Connection dbConn = null;
        Statement stmt = null;
        ValidTxnList validTxnList;
        // required to get the current state of txns to make validTxnList
        if (rqst.isSetValidTxnList()) {
            validTxnList = new ValidReadTxnList(rqst.getValidTxnList());
        } else {
            // Passing 0 for currentTxn means, this validTxnList is not wrt to any txn
            validTxnList = TxnUtils.createValidReadTxnList(getOpenTxns(), 0);
        }
        try {
            /**
             * This runs at READ_COMMITTED for exactly the same reason as {@link #getOpenTxnsInfo()}
             */
            dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
            stmt = dbConn.createStatement();
            // Get the valid write id list for all the tables read by the current txn
            List<TableValidWriteIds> tblValidWriteIdsList = new ArrayList<>();
            for (String fullTableName : rqst.getFullTableNames()) {
                tblValidWriteIdsList.add(getValidWriteIdsForTable(stmt, fullTableName, validTxnList));
            }
            LOG.debug("Going to rollback");
            dbConn.rollback();
            GetValidWriteIdsResponse owr = new GetValidWriteIdsResponse(tblValidWriteIdsList);
            return owr;
        } catch (SQLException e) {
            LOG.debug("Going to rollback");
            rollbackDBConn(dbConn);
            checkRetryable(dbConn, e, "getValidWriteIds");
            throw new MetaException("Unable to select from transaction database, " + StringUtils.stringifyException(e));
        } finally {
            close(null, stmt, dbConn);
        }
    } catch (RetryException e) {
        return getValidWriteIds(rqst);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ValidTxnList(org.apache.hadoop.hive.common.ValidTxnList) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) GetValidWriteIdsResponse(org.apache.hadoop.hive.metastore.api.GetValidWriteIdsResponse) ValidReadTxnList(org.apache.hadoop.hive.common.ValidReadTxnList) TableValidWriteIds(org.apache.hadoop.hive.metastore.api.TableValidWriteIds) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 ValidReadTxnList (org.apache.hadoop.hive.common.ValidReadTxnList)1 ValidTxnList (org.apache.hadoop.hive.common.ValidTxnList)1 GetValidWriteIdsResponse (org.apache.hadoop.hive.metastore.api.GetValidWriteIdsResponse)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 TableValidWriteIds (org.apache.hadoop.hive.metastore.api.TableValidWriteIds)1