deniskuzZ commented on code in PR #3089:
URL: https://github.com/apache/hive/pull/3089#discussion_r862863328
##########
ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java:
##########
@@ -3592,4 +3592,94 @@ public void testDropTableNonBlocking2() throws Exception
{
driver.getFetchTask().fetch(res);
Assert.assertEquals("No records found", 2, res.size());
}
-}
+
+ @Test
+ public void testReplaceColumnsNonBlocking() throws Exception {
+ //TODO: incorporate add new column via `REPLACE` inside of `ADD COLUMNS`
test case
+ testReplaceColumns(false);
+ }
+ @Test
+ public void testReplaceColumnsBlocking() throws Exception {
+ testReplaceColumns(true);
+ }
+ private void testReplaceColumns(boolean blocking) throws Exception {
+ testReplaceRenameColumns(blocking, "replace columns (c string, a bigint)");
+ }
+
+ @Test
+ public void testRenameColumnsNonBlocking() throws Exception {
+ testRenameColumns(false);
+ }
+ @Test
+ public void testRenameColumnsBlocking() throws Exception {
+ testRenameColumns(true);
+ }
+ private void testRenameColumns(boolean blocking) throws Exception {
+ testReplaceRenameColumns(blocking, "change column a c string");
+ }
+
+ private void testReplaceRenameColumns(boolean blocking, String
alterSubQuery) throws Exception {
+ dropTable(new String[] {"tab_acid"});
+
+ HiveConf.setBoolVar(conf,
HiveConf.ConfVars.HIVE_ACID_LOCKLESS_READS_ENABLED, !blocking);
+ driver = Mockito.spy(driver);
+
+ HiveConf.setBoolVar(driver2.getConf(),
HiveConf.ConfVars.HIVE_ACID_LOCKLESS_READS_ENABLED, !blocking);
+ driver2 = Mockito.spy(driver2);
+
+ driver.run("create table if not exists tab_acid (a int, b int) " +
+ "stored as orc TBLPROPERTIES ('transactional'='true')");
+ driver.run("insert into tab_acid (a,b) values(1,2),(3,4)");
+
+ driver.compileAndRespond("select * from tab_acid");
+ List<String> res = new ArrayList<>();
+
+ driver.lockAndRespond();
+ List<ShowLocksResponseElement> locks = getLocks();
+ Assert.assertEquals("Unexpected lock count", 1, locks.size());
+
+ checkLock(LockType.SHARED_READ,
+ LockState.ACQUIRED, "default", "tab_acid", null, locks);
+
+ DbTxnManager txnMgr2 = (DbTxnManager)
TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
+ swapTxnManager(txnMgr2);
+ driver2.compileAndRespond("alter table tab_acid "+ alterSubQuery);
+
+ if (blocking) {
+ txnMgr2.acquireLocks(driver2.getPlan(), ctx, null, false);
+ locks = getLocks();
+
+ ShowLocksResponseElement checkLock = checkLock(LockType.EXCLUSIVE,
+ LockState.WAITING, "default", "tab_acid", null, locks);
+
+ swapTxnManager(txnMgr);
+ Mockito.doNothing().when(driver).lockAndRespond();
+ driver.run();
+
+ driver.getFetchTask().fetch(res);
+ swapTxnManager(txnMgr2);
+
+ FieldSetter.setField(txnMgr2,
txnMgr2.getClass().getDeclaredField("numStatements"), 0);
Review Comment:
txnMgr.acquireLocks increments the number of statements and that prevents us
from calling it again - so doing a hard reset 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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]