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 89ddccbbda..e3041327b7 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 @@ -702,6 +702,7 @@ public OpenTxnsResponse openTxns(OpenTxnRequest rqst) throws MetaException { */ LOG.error("OpenTxnTimeOut exceeded commit duration {}, deleting transactionIds: {}", elapsedMillis, txnIds); deleteInvalidOpenTransactions(dbConn, txnIds); + dbConn.commit(); /* * We do not throw RetryException directly, to not circumvent the max retry limit */ diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/txn/TestAcidTxnCleanerService.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/txn/TestAcidTxnCleanerService.java index 99c045d0c3..cb5b583446 100644 --- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/txn/TestAcidTxnCleanerService.java +++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/txn/TestAcidTxnCleanerService.java @@ -82,7 +82,8 @@ public void cleansEmptyAbortedTxns() throws Exception { // always leaves the MAX(TXN_ID) in the TXNS table Assert.assertEquals(1, getTxnCount()); - Assert.assertEquals(5, getMaxTxnId()); + // The max TxnId might be greater id the openTxns failes with slow commit and retries + Assert.assertTrue("The max txnId shoul be at least 5", getMaxTxnId() >= 5); } @Test @@ -97,7 +98,7 @@ public void doesNotCleanAbortedTxnsThatAreNonEmpty() throws Exception { // deletes only the initial (committed) TXNS record Assert.assertEquals(5, getTxnCount()); - Assert.assertEquals(5, getMaxTxnId()); + Assert.assertTrue("The max txnId shoul be at least 5", getMaxTxnId() >= 5); } @Test @@ -113,7 +114,7 @@ public void cleansAllCommittedTxns() throws Exception { // always leaves the MAX(TXN_ID) in the TXNS table Assert.assertEquals(1, getTxnCount()); - Assert.assertEquals(5, getMaxTxnId()); + Assert.assertTrue("The max txnId shoul be at least 5", getMaxTxnId() >= 5); } @Test @@ -135,7 +136,7 @@ public void cleansCommittedAndEmptyAbortedOnly() throws Exception { // kept only the 5 non-empty aborted ones Assert.assertEquals(5, getTxnCount()); - Assert.assertEquals(15, getMaxTxnId()); + Assert.assertTrue("The max txnId shoul be at least 15", getMaxTxnId() >= 15); } @Test @@ -148,16 +149,16 @@ public void cleansEmptyAbortedBatchTxns() throws Exception { TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50); OpenTxnsResponse resp = txnHandler.openTxns(new OpenTxnRequest( TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50, "user", "hostname")); + txnHandler.setOpenTxnTimeOutMillis(1); txnHandler.abortTxns(new AbortTxnsRequest(resp.getTxn_ids())); GetOpenTxnsResponse openTxns = txnHandler.getOpenTxns(); Assert.assertEquals(TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50 + 1, openTxns.getOpen_txnsSize()); - txnHandler.setOpenTxnTimeOutMillis(1); underTest.run(); openTxns = txnHandler.getOpenTxns(); Assert.assertEquals(2, openTxns.getOpen_txnsSize()); - Assert.assertEquals(TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50 + 1, getMaxTxnId()); + Assert.assertTrue("The max txnId shoul be at least", getMaxTxnId() >= TxnStore.TIMED_OUT_TXN_ABORT_BATCH_SIZE + 50 + 1); } private void openNonEmptyThenAbort() throws MetaException, NoSuchTxnException, TxnAbortedException {