use of org.apache.hadoop.hive.metastore.LockRequestBuilder in project hive by apache.
the class TransactionBatch method createLockRequest.
private static LockRequest createLockRequest(final HiveStreamingConnection connection, String partNameForLock, String user, long txnId, String agentInfo) {
LockRequestBuilder requestBuilder = new LockRequestBuilder(agentInfo);
requestBuilder.setUser(user);
requestBuilder.setTransactionId(txnId);
LockComponentBuilder lockCompBuilder = new LockComponentBuilder().setDbName(connection.getDatabase()).setTableName(connection.getTable().getTableName()).setSharedRead().setOperationType(DataOperationType.INSERT);
if (connection.isDynamicPartitioning()) {
lockCompBuilder.setIsDynamicPartitionWrite(true);
}
if (partNameForLock != null && !partNameForLock.isEmpty()) {
lockCompBuilder.setPartitionName(partNameForLock);
}
requestBuilder.addLockComponent(lockCompBuilder.build());
return requestBuilder.build();
}
use of org.apache.hadoop.hive.metastore.LockRequestBuilder in project hive by apache.
the class Lock method buildLockRequest.
private LockRequest buildLockRequest(Long transactionId) {
if (transactionId == null && !sinks.isEmpty()) {
throw new IllegalArgumentException("Cannot sink to tables outside of a transaction: sinks=" + asStrings(sinks));
}
LockRequestBuilder requestBuilder = new LockRequestBuilder();
for (Table table : tables) {
LockComponentBuilder componentBuilder = new LockComponentBuilder().setDbName(table.getDbName()).setTableName(table.getTableName());
// and insert/select and if resource (that is written to) is ACID or not
if (sinks.contains(table)) {
componentBuilder.setSemiShared().setOperationType(DataOperationType.UPDATE).setIsTransactional(true);
} else {
componentBuilder.setShared().setOperationType(DataOperationType.INSERT).setIsTransactional(true);
}
LockComponent component = componentBuilder.build();
requestBuilder.addLockComponent(component);
}
if (transactionId != null) {
requestBuilder.setTransactionId(transactionId);
}
LockRequest request = requestBuilder.setUser(user).build();
return request;
}
use of org.apache.hadoop.hive.metastore.LockRequestBuilder in project hive by apache.
the class DbTxnManager method acquireLocks.
/**
* Normally client should call {@link #acquireLocks(org.apache.hadoop.hive.ql.QueryPlan, org.apache.hadoop.hive.ql.Context, String)}
* @param isBlocking if false, the method will return immediately; thus the locks may be in LockState.WAITING
* @return null if no locks were needed
*/
@VisibleForTesting
LockState acquireLocks(QueryPlan plan, Context ctx, String username, boolean isBlocking) throws LockException {
init();
// Make sure we've built the lock manager
getLockManager();
verifyState(plan);
queryId = plan.getQueryId();
switch(plan.getOperation()) {
case SET_AUTOCOMMIT:
/**
*This is here for documentation purposes. This TM doesn't support this - only has one
* mode of operation documented at {@link DbTxnManager#isExplicitTransaction}
*/
return null;
}
LockRequestBuilder rqstBuilder = new LockRequestBuilder(queryId);
// link queryId to txnId
LOG.info("Setting lock request transaction to " + JavaUtils.txnIdToString(txnId) + " for queryId=" + queryId);
rqstBuilder.setTransactionId(txnId).setUser(username);
rqstBuilder.setZeroWaitReadEnabled(!conf.getBoolVar(HiveConf.ConfVars.TXN_OVERWRITE_X_LOCK) || !conf.getBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK));
// this operation.
if (plan.getInputs().isEmpty() && plan.getOutputs().isEmpty()) {
LOG.debug("No locks needed for queryId=" + queryId);
return null;
}
List<LockComponent> lockComponents = AcidUtils.makeLockComponents(plan.getOutputs(), plan.getInputs(), ctx.getOperation(), conf);
lockComponents.addAll(getGlobalLocks(ctx.getConf()));
// It's possible there's nothing to lock even if we have w/r entities.
if (lockComponents.isEmpty()) {
LOG.debug("No locks needed for queryId=" + queryId);
return null;
}
rqstBuilder.addLockComponents(lockComponents);
List<HiveLock> locks = new ArrayList<HiveLock>(1);
LockState lockState = lockMgr.lock(rqstBuilder.build(), queryId, isBlocking, locks);
ctx.setHiveLocks(locks);
return lockState;
}
use of org.apache.hadoop.hive.metastore.LockRequestBuilder in project hive by apache.
the class CompactorThread method createLockRequest.
protected LockRequest createLockRequest(CompactionInfo ci, long txnId, LockType lockType, DataOperationType opType) {
String agentInfo = Thread.currentThread().getName();
LockRequestBuilder requestBuilder = new LockRequestBuilder(agentInfo);
requestBuilder.setUser(ci.runAs);
requestBuilder.setTransactionId(txnId);
LockComponentBuilder lockCompBuilder = new LockComponentBuilder().setLock(lockType).setOperationType(opType).setDbName(ci.dbname).setTableName(ci.tableName).setIsTransactional(true);
if (ci.partName != null) {
lockCompBuilder.setPartitionName(ci.partName);
}
requestBuilder.addLockComponent(lockCompBuilder.build());
requestBuilder.setZeroWaitReadEnabled(!conf.getBoolVar(HiveConf.ConfVars.TXN_OVERWRITE_X_LOCK) || !conf.getBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK));
return requestBuilder.build();
}
Aggregations