private int acquireLocksAndOpenTxn() {
PerfLogger perfLogger = PerfLogger.getPerfLogger();
perfLogger.PerfLogBegin(CLASS_NAME, PerfLogger.ACQUIRE_READ_WRITE_LOCKS);
SessionState ss = SessionState.get();
HiveTxnManager txnMgr = ss.getTxnMgr();
try {
// Don't use the userName member, as it may or may not have been set. Get the value from
// conf, which calls into getUGI to figure out who the process is running as.
String userFromUGI;
try {
userFromUGI = conf.getUser();
} catch (IOException e) {
errorMessage = "FAILED: Error in determining user while acquiring locks: " + e.getMessage();
SQLState = ErrorMsg.findSQLState(e.getMessage());
downstreamError = e;
console.printError(errorMessage,
"\n" + org.apache.hadoop.util.StringUtils.stringifyException(e));
return 10;
}
if (acidSinks != null && acidSinks.size() > 0) {
// We are writing to tables in an ACID compliant way, so we need to open a transaction
long txnId = ss.getCurrentTxn();
if (txnId == SessionState.NO_CURRENT_TXN) {
txnId = txnMgr.openTxn(userFromUGI);
ss.setCurrentTxn(txnId);
}
// Set the transaction id in all of the acid file sinks
if (acidSinks != null) {
for (FileSinkDesc desc : acidSinks) {
desc.setTransactionId(txnId);
}
}
// TODO Once we move to cross query transactions we need to add the open transaction to
// our list of valid transactions. We don't have a way to do that right now.
}
txnMgr.acquireLocks(plan, ctx, userFromUGI);
return 0;
} catch (LockException e) {
errorMessage = "FAILED: Error in acquiring locks: " + e.getMessage();
SQLState = ErrorMsg.findSQLState(e.getMessage());