Skip to content

Commit e433b06

Browse files
committed
fixes
1 parent c5656c7 commit e433b06

File tree

9 files changed

+28
-173
lines changed

9 files changed

+28
-173
lines changed

ql/src/test/org/apache/hadoop/hive/ql/lockmgr/DbTxnManagerEndToEndTestBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hadoop.hive.conf.HiveConf;
2424
import org.apache.hadoop.hive.conf.HiveConfForTest;
2525
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
26+
import org.apache.hadoop.hive.metastore.txn.TxnHandler;
2627
import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
2728
import org.apache.hadoop.hive.metastore.txn.TxnStore;
2829
import org.apache.hadoop.hive.metastore.txn.TxnUtils;
@@ -78,7 +79,9 @@ public void setUp() throws Exception {
7879
HiveConf.setIntVar(conf, HiveConf.ConfVars.HIVE_LOCKS_PARTITION_THRESHOLD, -1);
7980
HiveConf.setBoolVar(conf, HiveConf.ConfVars.HIVE_ACID_LOCKLESS_READS_ENABLED, false);
8081
HiveConf.setBoolVar(conf, HiveConf.ConfVars.TXN_WRITE_X_LOCK, false);
81-
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_LEVEL, true);
82+
83+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, true);
84+
TxnHandler.ConfVars.setUseMinHistoryWriteId(true);
8285

8386
driver = new Driver(new QueryState.Builder().withHiveConf(conf).nonIsolated().build());
8487
driver2 = new Driver(new QueryState.Builder().withHiveConf(conf).build());

ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hadoop.hive.metastore.api.TxnType;
3838
import org.apache.hadoop.hive.metastore.api.CommitTxnRequest;
3939
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
40+
import org.apache.hadoop.hive.metastore.txn.TxnHandler;
4041
import org.apache.hadoop.hive.metastore.txn.service.CompactionHouseKeeperService;
4142
import org.apache.hadoop.hive.metastore.txn.service.AcidHouseKeeperService;
4243
import org.apache.hadoop.hive.ql.Context;
@@ -1235,6 +1236,9 @@ public void testWriteSetTracking4() throws Exception {
12351236
*/
12361237
@Test
12371238
public void testWriteSetTracking5() throws Exception {
1239+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, false);
1240+
TxnHandler.ConfVars.setUseMinHistoryWriteId(false);
1241+
12381242
dropTable(new String[] {"TAB_PART"});
12391243
Assert.assertEquals(0, TestTxnDbUtil.countQueryAgent(conf, "select count(*) from \"WRITE_SET\""));
12401244
driver.run("create table if not exists TAB_PART (a int, b int) " +
@@ -2109,6 +2113,9 @@ public void testMergeUnpartitionedConflictSharedWrite() throws Exception {
21092113
* @param causeConflict true to make 2 operations such that they update the same entity
21102114
*/
21112115
private void testMergeUnpartitioned(boolean causeConflict, boolean sharedWrite) throws Exception {
2116+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, false);
2117+
TxnHandler.ConfVars.setUseMinHistoryWriteId(false);
2118+
21122119
dropTable(new String[] {"target","source"});
21132120
conf.setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !sharedWrite);
21142121

@@ -2873,6 +2880,9 @@ public void testMergePartitionedConflictSharedWrite() throws Exception {
28732880
* @param causeConflict - true to make the operations cause a Write conflict
28742881
*/
28752882
private void testMergePartitioned(boolean causeConflict, boolean sharedWrite) throws Exception {
2883+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, false);
2884+
TxnHandler.ConfVars.setUseMinHistoryWriteId(false);
2885+
28762886
dropTable(new String[] {"target","source"});
28772887
conf.setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !sharedWrite);
28782888

@@ -3537,7 +3547,8 @@ public void testSkipAcquireLocksForExplain() throws Exception {
35373547

35383548
@Test
35393549
public void testInsertSnapshotIsolationMinHistoryDisabled() throws Exception {
3540-
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_LEVEL, false);
3550+
TxnHandler.ConfVars.setUseMinHistoryWriteId(false);
3551+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, false);
35413552
testInsertSnapshotIsolation();
35423553
}
35433554

@@ -3566,7 +3577,8 @@ public void testInsertSnapshotIsolation() throws Exception {
35663577

35673578
@Test
35683579
public void testUpdateSnapshotIsolationMinHistoryDisabled() throws Exception {
3569-
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_LEVEL, false);
3580+
TxnHandler.ConfVars.setUseMinHistoryWriteId(false);
3581+
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_WRITE_ID, false);
35703582
testUpdateSnapshotIsolation();
35713583
}
35723584

ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactionMetrics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class TestCompactionMetrics extends CompactorTest {
8686
public void setUp() throws Exception {
8787
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.METRICS_ENABLED, true);
8888
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TXN_USE_MIN_HISTORY_LEVEL, true);
89+
TxnHandler.ConfVars.setUseMinHistoryLevel(true);
8990
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.COMPACTOR_INITIATOR_ON, true);
9091
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.COMPACTOR_CLEANER_ON, true);
9192
// re-initialize metrics

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ public enum ConfVars {
16761676
TXN_OPENTXN_TIMEOUT("metastore.txn.opentxn.timeout", "hive.txn.opentxn.timeout", 1000, TimeUnit.MILLISECONDS,
16771677
"Time before an open transaction operation should persist, otherwise it is considered invalid and rolled back"),
16781678
@Deprecated
1679-
TXN_USE_MIN_HISTORY_LEVEL("metastore.txn.use.minhistorylevel", "hive.txn.use.minhistorylevel", false,
1679+
TXN_USE_MIN_HISTORY_LEVEL("metastore.txn.use.minhistorylevel", "hive.txn.use.minhistorylevel", true,
16801680
"Set this to false, for the TxnHandler and Cleaner to not use MIN_HISTORY_LEVEL table and take advantage of openTxn optimisation.\n"
16811681
+ "If the table is dropped HMS will switch this flag to false, any other value changes need a restart to take effect."),
16821682
TXN_USE_MIN_HISTORY_WRITE_ID("metastore.txn.use.minhistorywriteid", "hive.txn.use.minhistorywriteid", true,

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private void updateStatus(CompactionInfo ci) throws MetaException {
374374
String strState = CompactionState.fromSqlConst(ci.state).toString();
375375

376376
LOG.debug("Marking as {}: CompactionInfo: {}", strState, ci);
377-
CompactionInfo ciActual = jdbcResource.execute(new GetCompactionInfoHandler(ci.id, false));
377+
CompactionInfo ciActual = jdbcResource.execute(new GetCompactionInfoHandler(ci.id, false));
378378

379379
long endTime = getDbTime().getTime();
380380
if (ciActual != null) {
@@ -505,7 +505,7 @@ public long findMinOpenTxnIdForCleaner() throws MetaException {
505505
@RetrySemantics.Idempotent
506506
@Deprecated
507507
public long findMinTxnIdSeenOpen() {
508-
if (!ConfVars.useMinHistoryLevel() || ConfVars.useMinHistoryWriteId()) {
508+
if (!ConfVars.useMinHistoryLevel()) {
509509
return Long.MAX_VALUE;
510510
}
511511
try {

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private ConfVars() {}
205205
private boolean useMinHistoryWriteId;
206206

207207
public boolean useMinHistoryLevel() {
208-
return useMinHistoryLevel;
208+
return useMinHistoryLevel && !useMinHistoryWriteId;
209209
}
210210

211211
public void setUseMinHistoryLevel(boolean useMinHistoryLevel) {

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
import org.apache.hadoop.hive.metastore.api.MetaException;
2121
import org.apache.hadoop.hive.metastore.txn.TxnHandler;
22-
import org.apache.hadoop.hive.metastore.txn.entities.TxnStatus;
2322
import org.apache.hadoop.hive.metastore.txn.jdbc.MultiDataSourceJdbcResource;
2423
import org.apache.hadoop.hive.metastore.txn.jdbc.TransactionalFunction;
24+
import org.apache.hadoop.hive.metastore.txn.jdbc.queries.MinUncommittedTxnIdHandler;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -33,21 +33,6 @@ public class CleanTxnToWriteIdTableFunction implements TransactionalFunction<Voi
3333

3434
private static final Logger LOG = LoggerFactory.getLogger(CleanTxnToWriteIdTableFunction.class);
3535

36-
//language=SQL
37-
private static String minHistoryLevelSql = "SELECT MIN(\"RES\".\"ID\") AS \"ID\" FROM (" +
38-
" SELECT MAX(\"TXN_ID\") + 1 AS \"ID\" FROM \"TXNS\"" +
39-
" UNION" +
40-
" SELECT MIN(\"TXN_ID\") AS \"ID\" FROM \"TXNS\" WHERE \"TXN_STATE\" = :abortedState) \"RES\"";
41-
//language=SQL
42-
private static String noMinHistoryLevelSql = "SELECT MIN(\"RES\".\"ID\") AS \"ID\" FROM (" +
43-
" SELECT MAX(\"TXN_ID\") + 1 AS \"ID\" FROM \"TXNS\"" +
44-
" UNION" +
45-
" SELECT MIN(\"WS_TXNID\") AS \"ID\" FROM \"WRITE_SET\"" +
46-
" UNION" +
47-
" SELECT MIN(\"TXN_ID\") AS \"ID\" FROM \"TXNS\" WHERE \"TXN_STATE\" = " + TxnStatus.ABORTED +
48-
" OR \"TXN_STATE\" = " + TxnStatus.OPEN +
49-
" ) \"RES\"";
50-
5136
private final long minTxnIdSeenOpen;
5237

5338
public CleanTxnToWriteIdTableFunction(long minTxnIdSeenOpen) {
@@ -56,32 +41,18 @@ public CleanTxnToWriteIdTableFunction(long minTxnIdSeenOpen) {
5641

5742
@Override
5843
public Void execute(MultiDataSourceJdbcResource jdbcResource) throws MetaException {
59-
NamedParameterJdbcTemplate jdbcTemplate = jdbcResource.getJdbcTemplate();
60-
String sql = TxnHandler.ConfVars.useMinHistoryLevel() ? minHistoryLevelSql : noMinHistoryLevelSql;
61-
MapSqlParameterSource params = new MapSqlParameterSource()
62-
.addValue("abortedState", TxnStatus.ABORTED.getSqlConst(), Types.CHAR);
63-
if (!TxnHandler.ConfVars.useMinHistoryLevel()) {
64-
params.addValue("openState", TxnStatus.OPEN.getSqlConst(), Types.CHAR);
65-
}
66-
6744
// First need to find the min_uncommitted_txnid which is currently seen by any open transactions.
6845
// If there are no txns which are currently open or aborted in the system, then current value of
6946
// max(TXNS.txn_id) could be min_uncommitted_txnid.
70-
Long minTxnId = jdbcTemplate.query(sql, params, rs -> {
71-
if (rs.next()) {
72-
return rs.getLong(1);
73-
} else {
74-
return null;
75-
}
76-
});
77-
47+
Long minTxnId = jdbcResource.execute(
48+
new MinUncommittedTxnIdHandler(TxnHandler.ConfVars.useMinHistoryLevel()));
7849
if (minTxnId == null) {
7950
throw new MetaException("Transaction tables not properly initialized, no record found in TXNS");
8051
}
8152
long minUncommitedTxnid = Math.min(minTxnId, minTxnIdSeenOpen);
82-
8353
// As all txns below min_uncommitted_txnid are either committed or empty_aborted, we are allowed
8454
// to clean up the entries less than min_uncommitted_txnid from the TXN_TO_WRITE_ID table.
55+
NamedParameterJdbcTemplate jdbcTemplate = jdbcResource.getJdbcTemplate();
8556
int rc = jdbcTemplate.update("DELETE FROM \"TXN_TO_WRITE_ID\" WHERE \"T2W_TXNID\" < :txnId",
8657
new MapSqlParameterSource("txnId", minUncommitedTxnid));
8758
LOG.info("Removed {} rows from TXN_TO_WRITE_ID with Txn Low-Water-Mark: {}", rc, minUncommitedTxnid);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ public TxnType execute(MultiDataSourceJdbcResource jdbcResource) throws MetaExce
256256
assert true;
257257
}
258258

259-
260259
if (txnType != TxnType.READ_ONLY && !isReplayedReplTxn && !MetaStoreServerUtils.isCompactionTxn(txnType)) {
261260
moveTxnComponentsToCompleted(jdbcResource, txnid, isUpdateDelete);
262261
} else if (isReplayedReplTxn) {
@@ -575,7 +574,7 @@ private void updateWSCommitIdAndCleanUpMetadata(MultiDataSourceJdbcResource jdbc
575574
if (txnType == TxnType.MATER_VIEW_REBUILD) {
576575
queryBatch.add("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE \"MRL_TXN_ID\" = " + txnid);
577576
}
578-
if (txnType == TxnType.SOFT_DELETE || txnType == TxnType.COMPACTION) {
577+
if (txnType == TxnType.SOFT_DELETE || MetaStoreServerUtils.isCompactionTxn(txnType)) {
579578
queryBatch.add("UPDATE \"COMPACTION_QUEUE\" SET \"CQ_NEXT_TXN_ID\" = " + commitId + ", \"CQ_COMMIT_TIME\" = " +
580579
getEpochFn(jdbcResource.getDatabaseProduct()) + " WHERE \"CQ_TXN_ID\" = " + txnid);
581580
}

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

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)