pvary commented on code in PR #3220:
URL: https://github.com/apache/hive/pull/3220#discussion_r860668405


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/drop/DropDatabaseAnalyzer.java:
##########
@@ -49,28 +52,36 @@ public void analyzeInternal(ASTNode root) throws 
SemanticException {
     String databaseName = unescapeIdentifier(root.getChild(0).getText());
     boolean ifExists = root.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != 
null;
     boolean cascade = root.getFirstChildWithType(HiveParser.TOK_CASCADE) != 
null;
+    boolean isSoftDelete = HiveConf.getBoolVar(conf, 
HiveConf.ConfVars.HIVE_ACID_LOCKLESS_READS_ENABLED);
 
     Database database = getDatabase(databaseName, !ifExists);
     if (database == null) {
       return;
     }
-
     // if cascade=true, then we need to authorize the drop table action as 
well, and add the tables to the outputs
+    boolean allTablesWithSuffix = false;
     if (cascade) {
       try {
-        for (Table table : db.getAllTableObjects(databaseName)) {
-          // We want no lock here, as the database lock will cover the tables,
-          // and putting a lock will actually cause us to deadlock on 
ourselves.
-          outputs.add(new WriteEntity(table, 
WriteEntity.WriteType.DDL_NO_LOCK));
+        List<Table> tables = db.getAllTableObjects(databaseName);
+        allTablesWithSuffix = tables.stream().allMatch(
+            table -> AcidUtils.isTableSoftDeleteEnabled(table, conf));
+        for (Table table : tables) {
+          // Optimization used to limit number of requested locks. Check if 
table lock is needed or we could get away with single DB level lock,
+          boolean isTableLockNeeded = isSoftDelete && !allTablesWithSuffix;
+          outputs.add(new WriteEntity(table, isTableLockNeeded ?
+            AcidUtils.isTableSoftDeleteEnabled(table, conf) ?
+                WriteEntity.WriteType.DDL_EXCL_WRITE : 
WriteEntity.WriteType.DDL_EXCLUSIVE :
+            WriteEntity.WriteType.DDL_NO_LOCK));

Review Comment:
   Would this be better:
   ```
   LockType lockType = WriteEntity.WriteType.DDL_NO_LOCK;
   if (isTableLockNeeded) {
      lockType = AcidUtils.isTableSoftDeleteEnabled(table, conf) ?
                   WriteEntity.WriteType.DDL_EXCL_WRITE : 
WriteEntity.WriteType.DDL_EXCLUSIVE;
   }
   outputs.add(new WriteEntity(table, lockType));
   ```
   
   I think having too many `:` and `?` is really hard to read.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to