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;
}
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();
}
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;
}
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);
}
Aggregations