Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7C1B32009FB for ; Fri, 6 May 2016 22:42:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7ABCD160A13; Fri, 6 May 2016 20:42:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 29946160A0D for ; Fri, 6 May 2016 22:42:34 +0200 (CEST) Received: (qmail 63260 invoked by uid 500); 6 May 2016 20:42:32 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 62791 invoked by uid 99); 6 May 2016 20:42:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2016 20:42:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6A4ACE03CE; Fri, 6 May 2016 20:42:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spena@apache.org To: commits@hive.apache.org Date: Fri, 06 May 2016 20:42:36 -0000 Message-Id: <38112cfee4c34c4db351e69c9bcb1821@git.apache.org> In-Reply-To: <2de9c59c4bf045ed9e182b0d3c4f9eee@git.apache.org> References: <2de9c59c4bf045ed9e182b0d3c4f9eee@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/50] [abbrv] hive git commit: HIVE-11848 - tables in subqueries don't get locked (Eugene Koifman, reviewed by Wei Zheng) archived-at: Fri, 06 May 2016 20:42:35 -0000 HIVE-11848 - tables in subqueries don't get locked (Eugene Koifman, reviewed by Wei Zheng) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/47bf055c Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/47bf055c Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/47bf055c Branch: refs/heads/java8 Commit: 47bf055c02990272753105b917b487c5bbfe9208 Parents: 868e5e1 Author: Eugene Koifman Authored: Tue May 3 13:33:42 2016 -0700 Committer: Eugene Koifman Committed: Tue May 3 13:53:02 2016 -0700 ---------------------------------------------------------------------- .../ql/parse/UpdateDeleteSemanticAnalyzer.java | 16 +++++++++- .../hive/ql/lockmgr/TestDbTxnManager2.java | 33 ++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/47bf055c/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java index b8771d2..33fbffe 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java @@ -329,7 +329,9 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer { // Walk through all our inputs and set them to note that this read is part of an update or a // delete. for (ReadEntity input : inputs) { - input.setUpdateOrDelete(true); + if(isWritten(input)) { + input.setUpdateOrDelete(true); + } } if (inputIsPartitioned(inputs)) { @@ -377,6 +379,18 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer { } } + /** + * Check that {@code readEntity} is also being written + */ + private boolean isWritten(Entity readEntity) { + for(Entity writeEntity : outputs) { + //make sure to compare them as Entity, i.e. that it's the same table or partition, etc + if(writeEntity.toString().equalsIgnoreCase(readEntity.toString())) { + return true; + } + } + return false; + } private String operation() { if (updating()) return "update"; else if (deleting()) return "delete"; http://git-wip-us.apache.org/repos/asf/hive/blob/47bf055c/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java ---------------------------------------------------------------------- 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 836b507..6e2cf30 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 @@ -71,6 +71,39 @@ public class TestDbTxnManager2 { TxnDbUtil.prepDb(); } @Test + public void testLocksInSubquery() throws Exception { + checkCmdOnDriver(driver.run("create table if not exists T (a int, b int)")); + checkCmdOnDriver(driver.run("create table if not exists S (a int, b int) clustered by(b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')")); + checkCmdOnDriver(driver.run("create table if not exists R (a int, b int) clustered by(b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')")); + + checkCmdOnDriver(driver.compileAndRespond("delete from S where a in (select a from T where b = 1)")); + txnMgr.openTxn("one"); + txnMgr.acquireLocks(driver.getPlan(), ctx, "one"); + List locks = getLocks(); + Assert.assertEquals("Unexpected lock count", 2, locks.size()); + checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0)); + checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "S", null, locks.get(1)); + txnMgr.rollbackTxn(); + + checkCmdOnDriver(driver.compileAndRespond("update S set a = 7 where a in (select a from T where b = 1)")); + txnMgr.openTxn("one"); + txnMgr.acquireLocks(driver.getPlan(), ctx, "one"); + locks = getLocks(); + Assert.assertEquals("Unexpected lock count", 2, locks.size()); + checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0)); + checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "S", null, locks.get(1)); + txnMgr.rollbackTxn(); + + checkCmdOnDriver(driver.compileAndRespond("insert into R select * from S where a in (select a from T where b = 1)")); + txnMgr.openTxn("three"); + txnMgr.acquireLocks(driver.getPlan(), ctx, "three"); + locks = getLocks(); + Assert.assertEquals("Unexpected lock count", 3, locks.size()); + checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0)); + checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "S", null, locks.get(1)); + checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "R", null, locks.get(2)); + } + @Test public void createTable() throws Exception { CommandProcessorResponse cpr = driver.compileAndRespond("create table if not exists T (a int, b int)"); checkCmdOnDriver(cpr);