diff --git ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java index 998c05e37d..c3de9c78bb 100644 --- ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java +++ ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java @@ -3152,14 +3152,21 @@ public static void validateAcidPartitionLocation(String location, Configuration public static TxnType getTxnType(Configuration conf, ASTNode tree) { final ASTSearcher astSearcher = new ASTSearcher(); - return (HiveConf.getBoolVar(conf, ConfVars.HIVE_TXN_READONLY_ENABLED) && - tree.getToken().getType() == HiveParser.TOK_QUERY && - Stream.of( - new int[]{HiveParser.TOK_INSERT_INTO}, - new int[]{HiveParser.TOK_INSERT, HiveParser.TOK_TAB}) - .noneMatch(pattern -> - astSearcher.simpleBreadthFirstSearch(tree, pattern) != null)) ? - TxnType.READ_ONLY : TxnType.DEFAULT; + // check if read-only txn + if (HiveConf.getBoolVar(conf, ConfVars.HIVE_TXN_READONLY_ENABLED) && + tree.getToken().getType() == HiveParser.TOK_QUERY && + Stream.of(new int[]{HiveParser.TOK_INSERT_INTO}, + new int[]{HiveParser.TOK_INSERT, HiveParser.TOK_TAB}) + .noneMatch(pattern -> astSearcher.simpleBreadthFirstSearch(tree, pattern) != null)) { + return TxnType.READ_ONLY; + } + + // check if txn has a materialized view rebuild + if (astSearcher.simpleBreadthFirstSearch(tree, HiveParser.TOK_ALTER_MATERIALIZED_VIEW_REBUILD) != null) { + return TxnType.MATER_VIEW_REBUILD; + } + + return TxnType.DEFAULT; } public static List findBaseFiles( diff --git ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java index e91a7ed760..49dbf176d1 100644 --- ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java +++ ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java @@ -89,6 +89,10 @@ public TestParseUtils(String query, TxnType txnType) { "WHEN NOT MATCHED THEN " + " INSERT VALUES (src.col_a, src.col_b)", TxnType.DEFAULT}, + + {"CREATE MATERIALIZED VIEW matview AS SELECT * FROM b", TxnType.DEFAULT}, + {"ALTER MATERIALIZED VIEW matview REBUILD", TxnType.MATER_VIEW_REBUILD}, + {"ALTER MATERIALIZED VIEW matview DISABLE REWRITE", TxnType.DEFAULT} }); } @@ -101,10 +105,17 @@ public void testTxnTypeWithEnabledReadOnlyFeature() throws ParseException { @Test public void testTxnTypeWithDisabledReadOnlyFeature() throws ParseException { enableReadOnlyTxnFeature(false); - Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query)), TxnType.DEFAULT); + Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query)), readOnlyDisabledType(txnType)); } private void enableReadOnlyTxnFeature(boolean featureFlag) { conf.setBoolean(HiveConf.ConfVars.HIVE_TXN_READONLY_ENABLED.varname, featureFlag); } + + private TxnType readOnlyDisabledType(TxnType txnType) { + if (txnType == TxnType.READ_ONLY) { + return TxnType.DEFAULT; + } + return txnType; + } } diff --git standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/TxnType.java standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/TxnType.java index 349f37f914..7d050c567f 100644 --- standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/TxnType.java +++ standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/TxnType.java @@ -15,7 +15,8 @@ DEFAULT(0), REPL_CREATED(1), READ_ONLY(2), - COMPACTION(3); + COMPACTION(3), + MATER_VIEW_REBUILD(4); private final int value; @@ -44,6 +45,8 @@ public static TxnType findByValue(int value) { return READ_ONLY; case 3: return COMPACTION; + case 4: + return MATER_VIEW_REBUILD; default: return null; } diff --git standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/Types.php standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/Types.php index e4b0bc726c..a0862c5d8f 100644 --- standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/Types.php +++ standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/Types.php @@ -228,11 +228,13 @@ final class TxnType { const REPL_CREATED = 1; const READ_ONLY = 2; const COMPACTION = 3; + const MATER_VIEW_REBUILD = 4; static public $__names = array( 0 => 'DEFAULT', 1 => 'REPL_CREATED', 2 => 'READ_ONLY', 3 => 'COMPACTION', + 4 => 'MATER_VIEW_REBUILD', ); } diff --git standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py index 1a0fee319b..cf69cd818b 100644 --- standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py +++ standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py @@ -341,12 +341,14 @@ class TxnType: REPL_CREATED = 1 READ_ONLY = 2 COMPACTION = 3 + MATER_VIEW_REBUILD = 4 _VALUES_TO_NAMES = { 0: "DEFAULT", 1: "REPL_CREATED", 2: "READ_ONLY", 3: "COMPACTION", + 4: "MATER_VIEW_REBUILD", } _NAMES_TO_VALUES = { @@ -354,6 +356,7 @@ class TxnType: "REPL_CREATED": 1, "READ_ONLY": 2, "COMPACTION": 3, + "MATER_VIEW_REBUILD": 4, } class GetTablesExtRequestFields: diff --git standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb index e6224ec16f..76ee5f9be7 100644 --- standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb +++ standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb @@ -161,8 +161,9 @@ module TxnType REPL_CREATED = 1 READ_ONLY = 2 COMPACTION = 3 - VALUE_MAP = {0 => "DEFAULT", 1 => "REPL_CREATED", 2 => "READ_ONLY", 3 => "COMPACTION"} - VALID_VALUES = Set.new([DEFAULT, REPL_CREATED, READ_ONLY, COMPACTION]).freeze + MATER_VIEW_REBUILD = 4 + VALUE_MAP = {0 => "DEFAULT", 1 => "REPL_CREATED", 2 => "READ_ONLY", 3 => "COMPACTION", 4 => "MATER_VIEW_REBUILD"} + VALID_VALUES = Set.new([DEFAULT, REPL_CREATED, READ_ONLY, COMPACTION, MATER_VIEW_REBUILD]).freeze end module GetTablesExtRequestFields diff --git standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift index 8462b3d7a3..ae5e797a30 100644 --- standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift +++ standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift @@ -898,7 +898,8 @@ enum TxnType { DEFAULT = 0, REPL_CREATED = 1, READ_ONLY = 2, - COMPACTION = 3 + COMPACTION = 3, + MATER_VIEW_REBUILD = 4 } // specifies which info to return with GetTablesExtRequest diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java index 8fded608d0..7c3937520c 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java @@ -1590,7 +1590,9 @@ private void updateWSCommitIdAndCleanUpMetadata(Statement stmt, long txnid, TxnT queryBatch.add("DELETE FROM \"HIVE_LOCKS\" WHERE \"HL_TXNID\" = " + txnid); // DO NOT remove the transaction from the TXN table, the cleaner will remove it when appropriate queryBatch.add("UPDATE \"TXNS\" SET \"TXN_STATE\" = " + quoteChar(TXN_COMMITTED) + " WHERE \"TXN_ID\" = " + txnid); - queryBatch.add("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE \"MRL_TXN_ID\" = " + txnid); + if (txnType == TxnType.MATER_VIEW_REBUILD) { + queryBatch.add("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE \"MRL_TXN_ID\" = " + txnid); + } // execute all in one batch executeQueriesInBatchNoCount(dbProduct, stmt, queryBatch, maxBatchSize);