Search in sources :

Example 1 with DbLockManager

use of org.apache.hadoop.hive.ql.lockmgr.DbLockManager in project hive by apache.

the class DDLTask method showLocksNewFormat.

private int showLocksNewFormat(ShowLocksDesc showLocks, HiveLockManager lm) throws HiveException {
    DbLockManager lockMgr;
    if (!(lm instanceof DbLockManager)) {
        throw new RuntimeException("New lock format only supported with db lock manager.");
    }
    lockMgr = (DbLockManager) lm;
    String dbName = showLocks.getDbName();
    String tblName = showLocks.getTableName();
    Map<String, String> partSpec = showLocks.getPartSpec();
    if (dbName == null && tblName != null) {
        dbName = SessionState.get().getCurrentDatabase();
    }
    ShowLocksRequest rqst = new ShowLocksRequest();
    rqst.setDbname(dbName);
    rqst.setTablename(tblName);
    if (partSpec != null) {
        List<String> keyList = new ArrayList<String>();
        List<String> valList = new ArrayList<String>();
        for (String partKey : partSpec.keySet()) {
            String partVal = partSpec.remove(partKey);
            keyList.add(partKey);
            valList.add(partVal);
        }
        String partName = FileUtils.makePartName(keyList, valList);
        rqst.setPartname(partName);
    }
    ShowLocksResponse rsp = lockMgr.getLocks(rqst);
    // write the results in the file
    DataOutputStream os = getOutputStream(showLocks.getResFile());
    try {
        dumpLockInfo(os, rsp);
    } catch (FileNotFoundException e) {
        LOG.warn("show function: ", e);
        return 1;
    } catch (IOException e) {
        LOG.warn("show function: ", e);
        return 1;
    } catch (Exception e) {
        throw new HiveException(e.toString());
    } finally {
        IOUtils.closeStream(os);
    }
    return 0;
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) DbLockManager(org.apache.hadoop.hive.ql.lockmgr.DbLockManager) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException) ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse)

Example 2 with DbLockManager

use of org.apache.hadoop.hive.ql.lockmgr.DbLockManager in project hive by apache.

the class ReplDumpTask method isTxnPresentInHiveLocks.

/**
 * Get if there is an entry for the txn id in the hive locks table. It can be in waiting state or acquired state.
 * @param txnId
 * @return true if the entry for the txn id is present in hive locks.
 * @throws LockException
 */
private boolean isTxnPresentInHiveLocks(long txnId) throws LockException {
    ShowLocksRequest request = new ShowLocksRequest();
    request.setTxnid(txnId);
    HiveLockManager lockManager = getTxnMgr().getLockManager();
    ShowLocksResponse showLocksResponse = ((DbLockManager) lockManager).getLocks(request);
    return !showLocksResponse.getLocks().isEmpty();
}
Also used : ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) DbLockManager(org.apache.hadoop.hive.ql.lockmgr.DbLockManager) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse) HiveLockManager(org.apache.hadoop.hive.ql.lockmgr.HiveLockManager)

Example 3 with DbLockManager

use of org.apache.hadoop.hive.ql.lockmgr.DbLockManager in project hive by apache.

the class ReplDumpTask method getOpenTxns.

List<Long> getOpenTxns(ValidTxnList validTxnList, String dbName) throws LockException {
    HiveLockManager lockManager = getTxnMgr().getLockManager();
    long[] invalidTxns = validTxnList.getInvalidTransactions();
    List<Long> openTxns = new ArrayList<>();
    Set<Long> dbTxns = new HashSet<>();
    if (lockManager instanceof DbLockManager) {
        ShowLocksRequest request = new ShowLocksRequest();
        request.setDbname(dbName.toLowerCase());
        ShowLocksResponse showLocksResponse = ((DbLockManager) lockManager).getLocks(request);
        for (ShowLocksResponseElement showLocksResponseElement : showLocksResponse.getLocks()) {
            dbTxns.add(showLocksResponseElement.getTxnid());
        }
        for (long invalidTxn : invalidTxns) {
            if (dbTxns.contains(invalidTxn) && !validTxnList.isTxnAborted(invalidTxn)) {
                openTxns.add(invalidTxn);
            }
        }
    } else {
        for (long invalidTxn : invalidTxns) {
            if (!validTxnList.isTxnAborted(invalidTxn)) {
                openTxns.add(invalidTxn);
            }
        }
    }
    return openTxns;
}
Also used : ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) DbLockManager(org.apache.hadoop.hive.ql.lockmgr.DbLockManager) ArrayList(java.util.ArrayList) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse) HiveLockManager(org.apache.hadoop.hive.ql.lockmgr.HiveLockManager) HashSet(java.util.HashSet) ShowLocksResponseElement(org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)

Example 4 with DbLockManager

use of org.apache.hadoop.hive.ql.lockmgr.DbLockManager in project hive by apache.

the class ShowLocksOperation method getLocksForNewFormat.

private ShowLocksResponse getLocksForNewFormat(HiveLockManager lockMgr) throws HiveException, LockException {
    if (!(lockMgr instanceof DbLockManager)) {
        throw new HiveException("New lock format only supported with db lock manager.");
    }
    ShowLocksRequest request = new ShowLocksRequest();
    if (desc.getDbName() == null && desc.getTableName() != null) {
        request.setDbname(SessionState.get().getCurrentDatabase());
    } else {
        request.setDbname(desc.getDbName());
    }
    request.setTablename(desc.getTableName());
    if (desc.getPartSpec() != null) {
        List<String> keyList = new ArrayList<String>();
        List<String> valList = new ArrayList<String>();
        for (String partKey : desc.getPartSpec().keySet()) {
            String partVal = desc.getPartSpec().get(partKey);
            keyList.add(partKey);
            valList.add(partVal);
        }
        String partName = FileUtils.makePartName(keyList, valList);
        request.setPartname(partName);
    }
    return ((DbLockManager) lockMgr).getLocks(request);
}
Also used : ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) DbLockManager(org.apache.hadoop.hive.ql.lockmgr.DbLockManager) ArrayList(java.util.ArrayList)

Aggregations

ShowLocksRequest (org.apache.hadoop.hive.metastore.api.ShowLocksRequest)4 DbLockManager (org.apache.hadoop.hive.ql.lockmgr.DbLockManager)4 ArrayList (java.util.ArrayList)3 ShowLocksResponse (org.apache.hadoop.hive.metastore.api.ShowLocksResponse)3 HiveLockManager (org.apache.hadoop.hive.ql.lockmgr.HiveLockManager)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 DataOutputStream (java.io.DataOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)1