This is an automated email from the ASF dual-hosted git repository.
dkuzmenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 964eb54f98 HIVE-26106: Non blocking ADD, DROP constraint (Denys
Kuzmenko, reviewed by Laszlo Vegh)
964eb54f98 is described below
commit 964eb54f98970a35e35c43169083c09e1479b6e2
Author: Denys Kuzmenko <[email protected]>
AuthorDate: Tue May 3 14:30:23 2022 +0200
HIVE-26106: Non blocking ADD, DROP constraint (Denys Kuzmenko, reviewed by
Laszlo Vegh)
Closes #3165
---
.../drop/AlterTableDropConstraintAnalyzer.java | 2 +-
.../apache/hadoop/hive/ql/hooks/WriteEntity.java | 6 +++---
.../hadoop/hive/ql/lockmgr/TestDbTxnManager2.java | 25 ++++++++++++++++++++++
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/drop/AlterTableDropConstraintAnalyzer.java
b/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/drop/AlterTableDropConstraintAnalyzer.java
index 8392d310d5..98eecf3262 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/drop/AlterTableDropConstraintAnalyzer.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/drop/AlterTableDropConstraintAnalyzer.java
@@ -56,7 +56,7 @@ public class AlterTableDropConstraintAnalyzer extends
AbstractAlterTableAnalyzer
WriteEntity.WriteType writeType = null;
if (AcidUtils.isTransactionalTable(table)) {
setAcidDdlDesc(desc);
- writeType = WriteType.DDL_EXCLUSIVE;
+ writeType = WriteType.DDL_EXCL_WRITE;
} else {
writeType =
WriteEntity.determineAlterTableWriteType(AlterTableType.DROP_CONSTRAINT, table,
conf);
}
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/hooks/WriteEntity.java
b/ql/src/java/org/apache/hadoop/hive/ql/hooks/WriteEntity.java
index 8b5cf47d7d..28238ec6b6 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/hooks/WriteEntity.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/hooks/WriteEntity.java
@@ -226,11 +226,11 @@ public class WriteEntity extends Entity implements
Serializable {
case ADDCOLS:
case TRUNCATE:
case MERGEFILES:
- case ADD_CONSTRAINT:
- case DROP_CONSTRAINT:
case OWNER:
return WriteType.DDL_EXCLUSIVE;
-
+
+ case ADD_CONSTRAINT:
+ case DROP_CONSTRAINT:
case RENAME:
return AcidUtils.isLocklessReadsEnabled(table, conf) ?
WriteType.DDL_EXCL_WRITE : WriteType.DDL_EXCLUSIVE;
diff --git
a/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
b/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
index 78d7fbe345..613e3ab858 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
@@ -4003,4 +4003,29 @@ public class TestDbTxnManager2 extends
DbTxnManagerEndToEndTestBase{
LockState.ACQUIRED, database, null, null, locks);
}
}
+
+ @Test
+ public void testAddDropConstraintNonBlocking() throws Exception {
+ HiveConf.setBoolVar(conf,
HiveConf.ConfVars.HIVE_ACID_LOCKLESS_READS_ENABLED, true);
+ dropTable(new String[] {"tab_acid"});
+
+ driver.run("create table if not exists tab_acid (a int, b int) " +
+ "stored as orc TBLPROPERTIES ('transactional'='true')");
+ driver.run("insert into tab_acid (a,b) values(1,2),(3,4)");
+
+ driver.compileAndRespond("alter table tab_acid ADD CONSTRAINT a_PK PRIMARY
KEY (`a`) DISABLE NOVALIDATE");
+ driver.lockAndRespond();
+
+ List<ShowLocksResponseElement> locks = getLocks();
+ checkLock(LockType.EXCL_WRITE,
+ LockState.ACQUIRED, "default", "tab_acid", null, locks);
+ driver.close();
+
+ driver.compileAndRespond("alter table tab_acid DROP CONSTRAINT a_PK");
+ driver.lockAndRespond();
+
+ locks = getLocks();
+ checkLock(LockType.EXCL_WRITE,
+ LockState.ACQUIRED, "default", "tab_acid", null, locks);
+ }
}