diff --git ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java index fdb3603338..a3197a4cf3 100644 --- ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java +++ ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java @@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one import com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.metastore.IMetaStoreClient; +import org.apache.hadoop.hive.metastore.TableType; import org.apache.hadoop.hive.ql.io.AcidUtils; import org.apache.hadoop.hive.ql.plan.HiveOperation; import org.apache.hadoop.hive.ql.plan.LockDatabaseDesc; @@ -343,6 +344,18 @@ private boolean allowOperationInATransaction(QueryPlan queryPlan) { //todo: handle Insert Overwrite as well: HIVE-18154 return false; } + private boolean needsLock(Entity entity) { + if(entity.getType() == Entity.Type.TABLE) { + return isLockableTable(entity.getTable()); + } + if(entity.getType() == Entity.Type.PARTITION) { + return isLockableTable(entity.getPartition().getTable()); + } + return true; + } + private boolean isLockableTable(Table t) { + return t.getTableType() == TableType.MANAGED_TABLE && !t.isTemporary(); + } /** * 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 @@ -371,8 +384,7 @@ LockState acquireLocks(QueryPlan plan, Context ctx, String username, boolean isB // For each source to read, get a shared lock for (ReadEntity input : plan.getInputs()) { - if (!input.needsLock() || input.isUpdateOrDelete() || - (input.getType() == Entity.Type.TABLE && input.getTable().isTemporary())) { + if (!input.needsLock() || input.isUpdateOrDelete() || !needsLock(input)) { // We don't want to acquire read locks during update or delete as we'll be acquiring write // locks instead. Also, there's no need to lock temp tables since they're session wide continue; @@ -421,7 +433,7 @@ LockState acquireLocks(QueryPlan plan, Context ctx, String username, boolean isB for (WriteEntity output : plan.getOutputs()) { LOG.debug("output is null " + (output == null)); if (output.getType() == Entity.Type.DFS_DIR || output.getType() == Entity.Type.LOCAL_DIR || - (output.getType() == Entity.Type.TABLE && output.getTable().isTemporary())) { + !needsLock(output)) { // We don't lock files or directories. We also skip locking temp tables. continue; }