Skip to content

Commit 15c61e6

Browse files
committed
refactor
1 parent e433b06 commit 15c61e6

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,7 @@ public void testCleanerForTxnToWriteId() throws Exception {
23732373
txnHandler.compact(new CompactionRequest("default", Table.ACIDTBL.name().toLowerCase(), CompactionType.MAJOR));
23742374
runWorker(hiveConf);
23752375
runCleaner(hiveConf);
2376+
txnHandler.performWriteSetGC();
23762377
txnHandler.cleanTxnToWriteIdTable();
23772378

23782379
// After compaction/cleanup, all entries from TXN_TO_WRITE_ID should be cleaned up as all txns are committed.
@@ -2416,6 +2417,7 @@ public void testCleanerForTxnToWriteId() throws Exception {
24162417
// aborted txn would be removed from TXNS only after the compaction. Also, committed txn > open txn is retained.
24172418
// As open txn doesn't allocate writeid, the 2 entries for aborted and committed should be retained.
24182419
txnHandler.cleanEmptyAbortedAndCommittedTxns();
2420+
txnHandler.performWriteSetGC();
24192421
txnHandler.cleanTxnToWriteIdTable();
24202422
Assert.assertEquals(TestTxnDbUtil.queryToString(hiveConf, "select * from TXN_TO_WRITE_ID" + acidTblWhereClause),
24212423
3, TestTxnDbUtil.countQueryAgent(hiveConf, "select count(*) from TXN_TO_WRITE_ID" + acidTblWhereClause));
@@ -2428,6 +2430,7 @@ public void testCleanerForTxnToWriteId() throws Exception {
24282430
runWorker(hiveConf);
24292431
runCleaner(hiveConf);
24302432
txnHandler.cleanEmptyAbortedAndCommittedTxns();
2433+
txnHandler.performWriteSetGC();
24312434
txnHandler.cleanTxnToWriteIdTable();
24322435
Assert.assertEquals(TestTxnDbUtil.queryToString(hiveConf, "select * from TXN_TO_WRITE_ID"),
24332436
3, TestTxnDbUtil.countQueryAgent(hiveConf, "select count(*) from TXN_TO_WRITE_ID"));
@@ -2439,6 +2442,7 @@ public void testCleanerForTxnToWriteId() throws Exception {
24392442
// The txn opened after the compaction commit should not effect the Cleaner
24402443
runCleaner(hiveConf);
24412444
txnHandler.cleanEmptyAbortedAndCommittedTxns();
2445+
txnHandler.performWriteSetGC();
24422446
txnHandler.cleanTxnToWriteIdTable();
24432447

24442448
Assert.assertEquals(TestTxnDbUtil.queryToString(hiveConf, "select * from TXN_TO_WRITE_ID"),

ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommands3.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void testRenameTable() throws Exception {
110110
"select count(*) from COMPLETED_TXN_COMPONENTS where CTC_TABLE='s'"));
111111
Assert.assertEquals(1, TestTxnDbUtil.countQueryAgent(hiveConf,
112112
"select count(*) from COMPACTION_QUEUE where CQ_TABLE='s'"));
113-
Assert.assertEquals(1, TestTxnDbUtil.countQueryAgent(hiveConf,
113+
Assert.assertEquals(2, TestTxnDbUtil.countQueryAgent(hiveConf,
114114
"select count(*) from WRITE_SET where WS_TABLE='s'"));
115115
Assert.assertEquals(3, TestTxnDbUtil.countQueryAgent(hiveConf,
116116
"select count(*) from TXN_TO_WRITE_ID where T2W_TABLE='s'"));
@@ -125,7 +125,7 @@ public void testRenameTable() throws Exception {
125125
"select count(*) from COMPLETED_TXN_COMPONENTS where CTC_TABLE='bar'"));
126126
Assert.assertEquals(1, TestTxnDbUtil.countQueryAgent(hiveConf,
127127
"select count(*) from COMPACTION_QUEUE where CQ_TABLE='bar'"));
128-
Assert.assertEquals(1, TestTxnDbUtil.countQueryAgent(hiveConf,
128+
Assert.assertEquals(2, TestTxnDbUtil.countQueryAgent(hiveConf,
129129
"select count(*) from WRITE_SET where WS_TABLE='bar'"));
130130
Assert.assertEquals(4, TestTxnDbUtil.countQueryAgent(hiveConf,
131131
"select count(*) from TXN_TO_WRITE_ID where T2W_TABLE='bar'"));

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/functions/CommitTxnFunction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public TxnType execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExce
189189
Object undoWriteSetForCurrentTxn = context.createSavepoint();
190190
jdbcResource.getJdbcTemplate().update(
191191
writeSetInsertSql + (TxnHandler.ConfVars.useMinHistoryLevel() ? conflictSQLSuffix :
192-
"FROM \"TXN_COMPONENTS\" WHERE \"TC_TXNID\"= :txnId AND \"TC_OPERATION_TYPE\" <> :type"),
192+
"FROM \"TXN_COMPONENTS\" WHERE \"TC_TXNID\"= :txnId" + (
193+
(txnType != TxnType.REBALANCE_COMPACTION) ? "" : " AND \"TC_OPERATION_TYPE\" <> :type")),
193194
new MapSqlParameterSource()
194195
.addValue("txnId", txnid)
195196
.addValue("type", OperationType.COMPACT.getSqlConst()));
@@ -236,10 +237,9 @@ public TxnType execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExce
236237
}
237238
}
238239
} else if (!TxnHandler.ConfVars.useMinHistoryLevel()) {
239-
jdbcResource.getJdbcTemplate().update(writeSetInsertSql + "FROM \"TXN_COMPONENTS\" WHERE \"TC_TXNID\" = :txnId AND \"TC_OPERATION_TYPE\" <> :type",
240+
jdbcResource.getJdbcTemplate().update(writeSetInsertSql + "FROM \"TXN_COMPONENTS\" WHERE \"TC_TXNID\" = :txnId",
240241
new MapSqlParameterSource()
241-
.addValue("txnId", txnid)
242-
.addValue("type", OperationType.COMPACT.getSqlConst()));
242+
.addValue("txnId", txnid));
243243
commitId = jdbcResource.execute(new GetHighWaterMarkHandler());
244244
}
245245
} else {

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/queries/LatestTxnIdInConflictHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public String getParameterizedQueryString(DatabaseProduct databaseProduct) throw
5858
" ) \"CUR\"" +
5959
" ON \"COMMITTED\".\"WS_DATABASE\" = \"CUR\".\"TC_DATABASE\"" +
6060
" AND \"COMMITTED\".\"WS_TABLE\" = \"CUR\".\"TC_TABLE\"" +
61-
(TxnHandler.ConfVars.useMinHistoryLevel() ? "" :
62-
" AND \"COMMITTED\".\"WS_OPERATION_TYPE\" != :wsType") +
6361
// For partitioned table we always track writes at partition level (never at table)
6462
// and for non partitioned - always at table level, thus the same table should never
6563
// have entries with partition key and w/o
6664
" AND (\"COMMITTED\".\"WS_PARTITION\" = \"CUR\".\"TC_PARTITION\" OR" +
6765
" \"CUR\".\"TC_PARTITION\" IS NULL) " +
6866
// txns overlap
69-
" WHERE \"CUR\".\"TC_TXNID\" <= \"COMMITTED\".\"WS_COMMIT_ID\"";
67+
" WHERE \"CUR\".\"TC_TXNID\" <= \"COMMITTED\".\"WS_COMMIT_ID\"" +
68+
(TxnHandler.ConfVars.useMinHistoryLevel() ? "" :
69+
" AND \"COMMITTED\".\"WS_OPERATION_TYPE\" != :wsType");
7070
}
7171

7272
@Override

0 commit comments

Comments
 (0)