This is an automated email from the ASF dual-hosted git repository.
krisztiankasa 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 b4dd5cfba41 HIVE-28416: Another process is rebuilding the materialized
view is thrown for subsequent MV rebuilds when the current MV rebuild is
aborted for the same MV. (Dayakar M, reviewed by Krisztian Kasa, Zsolt
Miskolczi, Zoltan Ratkai, Dmitriy Fingerman)
b4dd5cfba41 is described below
commit b4dd5cfba418097f69ff533e3a57da4f2c95fc46
Author: Dayakar M <[email protected]>
AuthorDate: Wed Oct 16 14:54:58 2024 +0530
HIVE-28416: Another process is rebuilding the materialized view is thrown
for subsequent MV rebuilds when the current MV rebuild is aborted for the same
MV. (Dayakar M, reviewed by Krisztian Kasa, Zsolt Miskolczi, Zoltan Ratkai,
Dmitriy Fingerman)
---
.../hadoop/hive/ql/lockmgr/TestDbTxnManager2.java | 38 ++++++++++++++++++++++
.../txn/jdbc/functions/AbortTxnsFunction.java | 7 ++++
2 files changed, 45 insertions(+)
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 42be09529d3..89b1b2a13ec 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
@@ -4696,4 +4696,42 @@ public class TestDbTxnManager2 extends
DbTxnManagerEndToEndTestBase {
txnMgr.rollbackTxn();
driver.run("drop materialized view mv_tab_acid");
}
+
+ @Test
+ public void testMaterializedViewRebuildLockForSameMV() throws Exception {
+ driver.run("drop materialized view if exists mv_tab_acid");
+ dropTable(new String[] { "tab_acid" });
+
+ driver.run("create table if not exists tab_acid (a int, b int) partitioned
by (p string) " +
+ "stored as orc TBLPROPERTIES ('transactional'='true')");
+ driver.run("insert into tab_acid partition(p) (a,b,p)
values(1,2,'foo'),(3,4,'bar')");
+
+ driver.run("create materialized view mv_tab_acid partitioned on (p) " +
+ "stored as orc TBLPROPERTIES ('transactional'='true') as select a,
p from tab_acid where b > 1");
+
+ driver.run("insert into tab_acid partition(p) (a,b,p)
values(1,2,'foo'),(3,4,'bar')");
+
+ // execute MV Rebuild SQL for mv_tab_acid table
+ driver.compileAndRespond("alter materialized view mv_tab_acid rebuild");
+ driver.lockAndRespond();
+ // Corresponding MV Rebuild lock entry should be present in
MATERIALIZATION_REBUILD_LOCKS table
+ Assert.assertEquals("One lock should be there as MV Rebuild is
in-progress", 1, TestTxnDbUtil.countQueryAgent(conf,
+ "select count(*) from MATERIALIZATION_REBUILD_LOCKS where
MRL_TBL_NAME='mv_tab_acid'"));
+
+ // rollback the transaction
+ txnMgr.rollbackTxn();
+ // As transaction is rollback there should not be any MV Rebuild lock
entry for mv_tab_acid table.
+ Assert.assertEquals("There should not be any MV Rebuild lock as Txn is
rollback.", 0,
+ TestTxnDbUtil.countQueryAgent(conf,
+ "select count(*) from MATERIALIZATION_REBUILD_LOCKS where
MRL_TBL_NAME='mv_tab_acid'"));
+
+ // re-execute MV Rebuild SQL for mv_tab_acid table
+ driver.compileAndRespond("alter materialized view mv_tab_acid rebuild");
+ // Should be able to execute MV Rebuild and corresponding MV Rebuild lock
entry should be present for mv_tab_acid table.
+ Assert.assertEquals("One lock should be there as MV Rebuild is
re-triggered", 1, TestTxnDbUtil.countQueryAgent(conf,
+ "select count(*) from MATERIALIZATION_REBUILD_LOCKS where
MRL_TBL_NAME='mv_tab_acid'"));
+
+ // cleanup
+ driver.run("drop materialized view mv_tab_acid");
+ }
}
diff --git
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/AbortTxnsFunction.java
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/AbortTxnsFunction.java
index c280b85222c..f81df0eacaa 100644
---
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/AbortTxnsFunction.java
+++
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/AbortTxnsFunction.java
@@ -129,6 +129,13 @@ public class AbortTxnsFunction implements
TransactionalFunction<Integer> {
prefix.append("DELETE FROM \"HIVE_LOCKS\" WHERE ");
TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids,
"\"HL_TXNID\"", false, false);
+ // add delete mv rebuild locks queries to query list
+ prefix.setLength(0);
+ suffix.setLength(0);
+ prefix.append("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE ");
+ TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix, txnids,
"\"MRL_TXN_ID\"", false, false);
+
+
//If this abort is for REPL_CREATED TXN initiated outside the
replication flow, then clean the corresponding entry
//from REPL_TXN_MAP and mark that database as replication incompatible.
if (!isReplReplayed) {