kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r540313915



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -747,6 +753,92 @@ private void checkFileFormats(Hive db, LoadTableDesc tbd, 
Table table)
     }
   }
 
+  class LocalTableLock  implements Closeable{
+
+    private Optional<HiveLockObject> lock;
+    private HiveLock lockObj;
+
+    public LocalTableLock(Optional<HiveLockObject> lock) throws LockException {
+
+      this.lock = lock;
+      if(!lock.isPresent()) {
+        return;
+      }
+      LOG.info("LocalTableLock; locking: " + lock);
+      HiveLockManager lockMgr = context.getHiveTxnManager().getLockManager();
+      lockObj = lockMgr.lock(lock.get(), HiveLockMode.SEMI_SHARED, true);
+      LOG.info("LocalTableLock; locked: " + lock);
+    }
+
+    @Override
+    public void close() throws IOException {
+      if(!lock.isPresent()) {
+        return;
+      }
+      LOG.info("LocalTableLock; unlocking: "+lock);
+      HiveLockManager lockMgr;
+      try {
+        lockMgr = context.getHiveTxnManager().getLockManager();
+        lockMgr.unlock(lockObj);
+      } catch (LockException e1) {
+        throw new IOException(e1);
+      }
+      LOG.info("LocalTableLock; unlocked");
+    }
+
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) 
throws HiveException {
+    // nothing needs to be done
+    if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+      return new LocalTableLock(Optional.empty());
+    }
+    String lockFileMoveMode = 
conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+
+    if ("none".equalsIgnoreCase(lockFileMoveMode)) {

Review comment:
       yes...in that case I would prefer to have the `enum` inside `HiveConf` - 
which is not how the HiveConf was designed...because that's not possible I 
resorted to string literals...
   
   I don't have a good idea how to do this in a bulletproof way...
   ...or should I just declare an enum in this class - and parse the enum value 
into it and use that?
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to