You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/12/01 14:46:52 UTC

[GitHub] [hive] kgyrtkirk opened a new pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

kgyrtkirk opened a new pull request #1724:
URL: https://github.com/apache/hive/pull/1724


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557431510



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -4355,17 +4376,20 @@ private int add_partitions_pspec_core(RawStore ms, String catName, String dbName
         success = ms.commitTransaction();
         return addedPartitions.size();
       } finally {
-        if (!success) {
-          ms.rollbackTransaction();
-          cleanupPartitionFolders(addedPartitions, db);
-        }
-
-        if (!listeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(listeners,
-                                                EventType.ADD_PARTITION,
-                                                new AddPartitionEvent(tbl, partitionSpecProxy, true, this),
-                                                null,
-                                                transactionalListenerResponses, ms);
+        try {
+          if (!success) {
+            ms.rollbackTransaction();
+            cleanupPartitionFolders(addedPartitions, db);
+          }
+          if (!listeners.isEmpty()) {

Review comment:
       these locks will only engage in case the same table is touched; I think its safer to also keep this inside the lock




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553312554



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",
+                               queryPlan.getQueryStr(),
+                               conf);
+
+    HiveLockObject lock = new HiveLockObject(baseTable,lockData);
+
+    for (HiveLockObj hiveLockObj : lockObjects) {

Review comment:
       minor: i would prefer stream api here, but you can ignore it..
   if (locks.stream().filter().anyMatch()){..}




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553313485



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",
+                               queryPlan.getQueryStr(),
+                               conf);
+
+    HiveLockObject lock = new HiveLockObject(baseTable,lockData);
+
+    for (HiveLockObj hiveLockObj : lockObjects) {
+      if (Arrays.equals(hiveLockObj.getObj().getPaths(), lock.getPaths())) {
+        HiveLockMode l = hiveLockObj.getMode();
+        if (l == HiveLockMode.EXCLUSIVE || l == HiveLockMode.SEMI_SHARED) {
+          // no need to lock ; already owns a more powerful one
+          return new LocalTableLock(Optional.empty());
+        }
+      }
+    }
+
+    return new LocalTableLock(Optional.of(lock));
+  }
+
   private boolean isSkewedStoredAsDirs(LoadTableDesc tbd) {
     return (tbd.getLbCtx() == null) ? false : tbd.getLbCtx()

Review comment:
       minor: tbd.getLbCtx() != null && tbd.getLbCtx().isSkewedStoredAsDir()




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553291067



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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 {

Review comment:
       I think, it would be more cleaner to have 0 and 1 argument constructors. Based on current usages of  LocalTableLock constructor you know for sure if lock if null or not.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557419112



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",

Review comment:
       no there isn't any - HiveLockObject has 5 string fields




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553305993



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {

Review comment:
       nit. space




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553294973



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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);

Review comment:
       should we lower log level to debug here to avoid extensive logging. 




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553308475



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",

Review comment:
       I assume we don't have enum for this.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553321185



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -281,6 +279,7 @@ public static boolean isRenameAllowed(Database srcDB, Database destDB) {
     static AtomicInteger databaseCount, tableCount, partCount;
 
     private Warehouse wh; // hdfs warehouse
+    private static Striped<Lock> tablelocks;

Review comment:
       i think, it doesn't have to be static




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553324429



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -4355,17 +4376,20 @@ private int add_partitions_pspec_core(RawStore ms, String catName, String dbName
         success = ms.commitTransaction();
         return addedPartitions.size();
       } finally {
-        if (!success) {
-          ms.rollbackTransaction();
-          cleanupPartitionFolders(addedPartitions, db);
-        }
-
-        if (!listeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(listeners,
-                                                EventType.ADD_PARTITION,
-                                                new AddPartitionEvent(tbl, partitionSpecProxy, true, this),
-                                                null,
-                                                transactionalListenerResponses, ms);
+        try {
+          if (!success) {
+            ms.rollbackTransaction();
+            cleanupPartitionFolders(addedPartitions, db);
+          }
+          if (!listeners.isEmpty()) {

Review comment:
       could we call unlock here, before even propagation?




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r540222494



##########
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:
       Would it be better to create enum instead of string literals?




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557413124



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ private void checkFileFormats(Hive db, LoadTableDesc tbd, Table table)
     }
   }
 
+  class LocalTableLock  implements Closeable{

Review comment:
       its non-static because it needs access to the txnmanager.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r558441940



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -281,6 +279,7 @@ public static boolean isRenameAllowed(Database srcDB, Database destDB) {
     static AtomicInteger databaseCount, tableCount, partCount;
 
     private Warehouse wh; // hdfs warehouse
+    private static Striped<Lock> tablelocks;

Review comment:
       oh, sorry, i missed that synchronization is done on class level not instance. 
   Note: there is a bug in synchronization, double checked locking should be used here or if check (threadPool == null) should be moved inside the critical section.  




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r558441940



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -281,6 +279,7 @@ public static boolean isRenameAllowed(Database srcDB, Database destDB) {
     static AtomicInteger databaseCount, tableCount, partCount;
 
     private Warehouse wh; // hdfs warehouse
+    private static Striped<Lock> tablelocks;

Review comment:
       oh, sorry, i missed that synchronization is done on class level not instance. 
   Note: there is a bug in synchronization, double checked locking should be used here or if check should be moved inside the critical section.  




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557427678



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -3461,7 +3474,7 @@ private Table getTableInternal(String catName, String dbname, String name,
               LOG.warn("Unexpected resultset size:" + ret.size());
               throw new MetaException("Unexpected result from metadata transformer:return list size is " + ret.size());
             }
-            t = (Table)(ret.keySet().iterator().next());
+            t = (ret.keySet().iterator().next());

Review comment:
       yeah..someone should teach that trick to my save-action :D




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r542238768



##########
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, I think, having enum in MoveTask should be ok.  Btw, should we allow to modify HIVE_LOCK_FILE_MOVE_MODE in runtime, if not, we can init this enum in constructor or so. 




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553315091



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLockManager.java
##########
@@ -429,9 +430,12 @@ private ZooKeeperHiveLock lockPrimitive(HiveLockObject key,
       if (child.startsWith(exLock)) {
         childSeq = getSequenceNumber(child, exLock);
       }
-      if ((mode == HiveLockMode.EXCLUSIVE) && child.startsWith(shLock)) {
+      if ((mode == HiveLockMode.EXCLUSIVE) && (child.startsWith(shLock))) {

Review comment:
       unnecessary brackets




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553321821



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -3461,7 +3474,7 @@ private Table getTableInternal(String catName, String dbname, String name,
               LOG.warn("Unexpected resultset size:" + ret.size());
               throw new MetaException("Unexpected result from metadata transformer:return list size is " + ret.size());
             }
-            t = (Table)(ret.keySet().iterator().next());
+            t = (ret.keySet().iterator().next());

Review comment:
       unnecessary brackets




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on pull request #1724:
URL: https://github.com/apache/hive/pull/1724#issuecomment-745286738


   @deniskuzZ I've added a test for the issue; there is an interesting aspects of this issue it only happens in case there is at least 1 known dimension of the dpp insert


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on pull request #1724:
URL: https://github.com/apache/hive/pull/1724#issuecomment-742562120


   @kgyrtkirk, does it affect only external tables? Also could you please add test that covers the issue with the concurrent add_partitions requests and moveTask. 


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553304345



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");

Review comment:
       + `lock` for correlation




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ merged pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ merged pull request #1724:
URL: https://github.com/apache/hive/pull/1724


   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553305432



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {

Review comment:
       could you please remove unneeded nesting here




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557416064



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;

Review comment:
       I kept it lowercase to align with the set values of the hiveconf.
   replaced it with uppercase ones




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r543338891



##########
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:
       the `MoveTask` is created in the `TaskFactory` - and the "work" is only set via `setWork` - I choose not to override that method and parsed the enum value right when its needed




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557422893



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",
+                               queryPlan.getQueryStr(),
+                               conf);
+
+    HiveLockObject lock = new HiveLockObject(baseTable,lockData);
+
+    for (HiveLockObj hiveLockObj : lockObjects) {

Review comment:
       I tried to use stream api a few times - and I'm a bit against it because:
   * it's somewhat unreadable
   * it's harder to read them when they eventually changed in a patch
   * not really debug friendly
   * they seem to fit "easy tasks" nicely; but if someone extends it later - it might become a really hard to read expression...
   
   instead of 2 complex lines; this is 7 simple - I would rather keep it




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on pull request #1724:
URL: https://github.com/apache/hive/pull/1724#issuecomment-760230795


   Thank you @deniskuzZ for taking a look!
   I've addressed and/or replied back to your comments - could you please take another look?


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553324429



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -4355,17 +4376,20 @@ private int add_partitions_pspec_core(RawStore ms, String catName, String dbName
         success = ms.commitTransaction();
         return addedPartitions.size();
       } finally {
-        if (!success) {
-          ms.rollbackTransaction();
-          cleanupPartitionFolders(addedPartitions, db);
-        }
-
-        if (!listeners.isEmpty()) {
-          MetaStoreListenerNotifier.notifyEvent(listeners,
-                                                EventType.ADD_PARTITION,
-                                                new AddPartitionEvent(tbl, partitionSpecProxy, true, this),
-                                                null,
-                                                transactionalListenerResponses, ms);
+        try {
+          if (!success) {
+            ms.rollbackTransaction();
+            cleanupPartitionFolders(addedPartitions, db);
+          }
+          if (!listeners.isEmpty()) {

Review comment:
       could we call unlock here?, before even propagation?




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553299687



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;

Review comment:
       please use uppercase literals




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553304345



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");

Review comment:
       '+' `lock` for correlation




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r557426325



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
##########
@@ -281,6 +279,7 @@ public static boolean isRenameAllowed(Database srcDB, Database destDB) {
     static AtomicInteger databaseCount, tableCount, partCount;
 
     private Warehouse wh; // hdfs warehouse
+    private static Striped<Lock> tablelocks;

Review comment:
       this field must be static - if it's not; then it could not impose exclusiveness.
   
   note that this field is [initialized alongside with the `threadPool` field](https://github.com/apache/hive/pull/1724/files/bc11bb62d3700b227f48b4683282b826b946f8bd#diff-00e70b6958060aa36762b21bf16676f83af01c1e09b56816aecc6abe7c8ac866R491)




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553299154



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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);

Review comment:
       should we lower log level to debug here to avoid extensive logging




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553312554



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ 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");
+    }
+
+  }
+
+  static enum LockFileMoveMode {
+    none, dp, all;
+
+    public static LockFileMoveMode fromConf(HiveConf conf) {
+      if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY)) {
+        return none;
+      }
+      String lockFileMoveMode = conf.getVar(HiveConf.ConfVars.HIVE_LOCK_FILE_MOVE_MODE);
+      return valueOf(lockFileMoveMode);
+    }
+  }
+
+  private LocalTableLock acquireLockForFileMove(LoadTableDesc loadTableWork) throws HiveException {
+    LockFileMoveMode mode = LockFileMoveMode.fromConf(conf);
+
+    if (mode == LockFileMoveMode.none) {
+      return new LocalTableLock(Optional.empty());
+    }
+    if (mode == LockFileMoveMode.dp) {
+      if (loadTableWork.getDPCtx() == null) {
+        return new LocalTableLock(Optional.empty());
+      }
+    }
+
+    WriteEntity output = context.getLoadTableOutputMap().get(loadTableWork);
+    List<HiveLockObj> lockObjects = context.getOutputLockObjects().get(output);
+    if (lockObjects == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+    TableDesc table = loadTableWork.getTable();
+    if(table == null) {
+      return new LocalTableLock(Optional.empty());
+    }
+
+    Hive db = getHive();
+    Table baseTable = db.getTable(loadTableWork.getTable().getTableName());
+
+    HiveLockObject.HiveLockObjectData lockData =
+        new HiveLockObject.HiveLockObjectData(queryPlan.getQueryId(),
+                               String.valueOf(System.currentTimeMillis()),
+                               "IMPLICIT",
+                               queryPlan.getQueryStr(),
+                               conf);
+
+    HiveLockObject lock = new HiveLockObject(baseTable,lockData);
+
+    for (HiveLockObj hiveLockObj : lockObjects) {

Review comment:
       minor: i would prefer stream api       
   if (locks.stream().filter().anyMatch()){..}




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [hive] deniskuzZ commented on a change in pull request #1724: HIVE-24428: Concurrent add_partitions requests may lead to data loss

Posted by GitBox <gi...@apache.org>.
deniskuzZ commented on a change in pull request #1724:
URL: https://github.com/apache/hive/pull/1724#discussion_r553294309



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
##########
@@ -774,6 +780,100 @@ private void checkFileFormats(Hive db, LoadTableDesc tbd, Table table)
     }
   }
 
+  class LocalTableLock  implements Closeable{

Review comment:
       Favor static member classes over non static




----------------------------------------------------------------
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:
users@infra.apache.org



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