Skip to content

Commit 587aa5a

Browse files
committed
HIVE-28988: Handle materialized view commit txn during hive acid repl
* Details: * Commit txn of alter mv command was getting populated by write event infos. * This was causing a repl failure on load. * This is now fixed. * Testing: * Added itest.
1 parent ba1b83d commit 587aa5a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,9 @@ public void testMaterializedViewsReplication() throws Exception {
32453245
run("CREATE MATERIALIZED VIEW " + dbName + ".mat_view_boot2 disable rewrite stored as textfile AS SELECT t1.a FROM " + dbName + ".unptned as t1 join " + dbName2 + ".unptned as t2 on t1.a = t2.a", driver);
32463246
verifySetup("SELECT a from " + dbName + ".mat_view_boot2", unptn_data, driver);
32473247

3248+
run("CREATE MATERIALIZED VIEW " + dbName + ".mat_view_rebuild disable rewrite stored as textfile AS SELECT a FROM " + dbName + ".unptned", driver);
3249+
verifySetup("SELECT a from " + dbName + ".mat_view_rebuild", unptn_data, driver);
3250+
32483251
Tuple bootstrapDump = bootstrapLoadAndVerify(dbName, replDbName);
32493252

32503253
verifyRun("SELECT * from " + replDbName + ".unptned", unptn_data, driverMirror);
@@ -3253,6 +3256,7 @@ public void testMaterializedViewsReplication() throws Exception {
32533256
//verify source MVs are not on replica
32543257
verifyIfTableNotExist(replDbName, "mat_view_boot", metaStoreClientMirror);
32553258
verifyIfTableNotExist(replDbName, "mat_view_boot2", metaStoreClientMirror);
3259+
verifyIfTableNotExist(replDbName, "mat_view_rebuild", metaStoreClientMirror);
32563260

32573261
//test alter materialized view with rename
32583262
run("ALTER TABLE " + dbName + ".mat_view_boot RENAME TO " + dbName + ".mat_view_rename", driver);
@@ -3261,12 +3265,22 @@ public void testMaterializedViewsReplication() throws Exception {
32613265
verifyIfTableNotExist(dbName, "mat_view_boot", metaStoreClient);
32623266
verifyIfTableExist(dbName, "mat_view_rename", metaStoreClient);
32633267

3268+
String[] unptn_incr_data = new String[]{ "twenty", "thirty" };
3269+
String[] unptn_total_data = new String[]{ "twenty", "thirty", "eleven", "twelve" };
3270+
// Rebuild mv mat_view_rebuild after inserting some more data
3271+
run("INSERT INTO TABLE " + dbName + ".unptned values('" + unptn_incr_data[0] + "')", driver);
3272+
run("INSERT INTO TABLE " + dbName + ".unptned values('" + unptn_incr_data[1] + "')", driver);
3273+
3274+
run("ALTER MATERIALIZED VIEW " + dbName + ".mat_view_rebuild REBUILD" , driver);
3275+
verifyRun("SELECT a from " + dbName + ".mat_view_rebuild", unptn_total_data, driver);
3276+
32643277
// Perform REPL-DUMP/LOAD
32653278
Tuple incrementalDump = incrementalLoadAndVerify(dbName, replDbName);
32663279

32673280
//verify source MVs are not on replica
32683281
verifyIfTableNotExist(replDbName, "mat_view_rename", metaStoreClientMirror);
32693282
verifyIfTableNotExist(replDbName, "mat_view_boot2", metaStoreClientMirror);
3283+
verifyIfTableNotExist(replDbName, "mat_view_rebuild", metaStoreClientMirror);
32703284

32713285
//test alter materialized view rebuild
32723286
run("ALTER MATERIALIZED VIEW " + dbName + ".mat_view_boot2 REBUILD" , driver);

ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/events/CommitTxnHandler.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.hadoop.hive.metastore.api.NotificationEvent;
2828
import org.apache.hadoop.hive.metastore.api.WriteEventInfo;
2929
import org.apache.hadoop.hive.metastore.messaging.CommitTxnMessage;
30+
import org.apache.hadoop.hive.metastore.messaging.MessageBuilder;
3031
import org.apache.hadoop.hive.metastore.utils.StringUtils;
3132
import org.apache.hadoop.hive.ql.exec.repl.util.ReplUtils;
3233
import org.apache.hadoop.hive.ql.metadata.HiveFatalException;
@@ -43,6 +44,7 @@
4344
import java.io.IOException;
4445
import java.util.ArrayList;
4546
import java.util.List;
47+
import java.util.stream.Collectors;
4648

4749
class CommitTxnHandler extends AbstractEventHandler<CommitTxnMessage> {
4850

@@ -128,6 +130,20 @@ private List<WriteEventInfo> getAllWriteEventInfo(Context withinContext) throws
128130
})));
129131
}
130132

133+
private List<WriteEventInfo> getAllWriteEventInfoExceptMV(List<WriteEventInfo> writeEventInfoList) {
134+
return writeEventInfoList.stream().filter(writeEventInfo -> {
135+
try {
136+
if (writeEventInfo.getTableObj() != null) {
137+
Table table = new Table((org.apache.hadoop.hive.metastore.api.Table) MessageBuilder.getTObj(writeEventInfo.getTableObj(), org.apache.hadoop.hive.metastore.api.Table.class));
138+
return !table.isMaterializedView();
139+
}
140+
return true;
141+
} catch (Exception e) {
142+
throw new RuntimeException(e);
143+
}
144+
}).collect(Collectors.toList());
145+
}
146+
131147
@Override
132148
public void handle(Context withinContext) throws Exception {
133149
if (!ReplUtils.includeAcidTableInDump(withinContext.hiveConf)) {
@@ -168,6 +184,10 @@ public void handle(Context withinContext) throws Exception {
168184
}
169185
}
170186

187+
// Filtering out all write event info related to materialized view
188+
if (writeEventInfoList != null) {
189+
writeEventInfoList = getAllWriteEventInfoExceptMV(writeEventInfoList);
190+
}
171191
int numEntry = (writeEventInfoList != null ? writeEventInfoList.size() : 0);
172192
if (numEntry != 0) {
173193
eventMessage.addWriteEventInfo(writeEventInfoList);

0 commit comments

Comments
 (0)