deniskuzZ commented on code in PR #4384:
URL: https://github.com/apache/hive/pull/4384#discussion_r1337025667
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -444,136 +175,15 @@ public void markCompacted(CompactionInfo info) throws
MetaException {
@Override
@RetrySemantics.ReadOnly
public List<CompactionInfo> findReadyToClean(long minOpenTxnWaterMark, long
retentionTime) throws MetaException {
- try {
- List<CompactionInfo> rc = new ArrayList<>();
-
- try (Connection dbConn =
getDbConn(Connection.TRANSACTION_READ_COMMITTED, connPoolCompaction);
- Statement stmt = dbConn.createStatement()) {
- /*
- * By filtering on minOpenTxnWaterMark, we will only cleanup after
every transaction is committed, that could see
- * the uncompacted deltas. This way the cleaner can clean up
everything that was made obsolete by this compaction.
- */
- String whereClause = " WHERE \"CQ_STATE\" = " +
quoteChar(READY_FOR_CLEANING) +
- " AND \"CQ_TYPE\" != " + quoteChar(TxnStore.ABORT_TXN_CLEANUP_TYPE) +
- " AND (\"CQ_COMMIT_TIME\" < (" + getEpochFn(dbProduct) + " -
\"CQ_RETRY_RETENTION\" - " + retentionTime + ") OR \"CQ_COMMIT_TIME\" IS NULL)";
-
- String queryStr =
- " \"CQ_ID\", \"cq1\".\"CQ_DATABASE\", \"cq1\".\"CQ_TABLE\",
\"cq1\".\"CQ_PARTITION\"," +
- " \"CQ_TYPE\", \"CQ_RUN_AS\", \"CQ_HIGHEST_WRITE_ID\",
\"CQ_TBLPROPERTIES\", \"CQ_RETRY_RETENTION\", " +
- " \"CQ_NEXT_TXN_ID\"";
- if (useMinHistoryWriteId) {
- queryStr += ", \"MIN_OPEN_WRITE_ID\"";
- }
- queryStr +=
- " FROM \"COMPACTION_QUEUE\" \"cq1\" " +
- "INNER JOIN (" +
- " SELECT MIN(\"CQ_HIGHEST_WRITE_ID\") \"MIN_WRITE_ID_HWM\",
\"CQ_DATABASE\", \"CQ_TABLE\", \"CQ_PARTITION\"" +
- " FROM \"COMPACTION_QUEUE\""
- + whereClause +
- " GROUP BY \"CQ_DATABASE\", \"CQ_TABLE\", \"CQ_PARTITION\") \"cq2\"
" +
- "ON \"cq1\".\"CQ_DATABASE\" = \"cq2\".\"CQ_DATABASE\""+
- " AND \"cq1\".\"CQ_TABLE\" = \"cq2\".\"CQ_TABLE\""+
- " AND (\"cq1\".\"CQ_PARTITION\" = \"cq2\".\"CQ_PARTITION\"" +
- " OR \"cq1\".\"CQ_PARTITION\" IS NULL AND
\"cq2\".\"CQ_PARTITION\" IS NULL)" +
- " AND \"CQ_HIGHEST_WRITE_ID\" = \"MIN_WRITE_ID_HWM\" ";
-
- if (useMinHistoryWriteId) {
- queryStr +=
- "LEFT JOIN (" +
- " SELECT MIN(\"MH_WRITEID\") \"MIN_OPEN_WRITE_ID\",
\"MH_DATABASE\", \"MH_TABLE\"" +
- " FROM \"MIN_HISTORY_WRITE_ID\"" +
- " GROUP BY \"MH_DATABASE\", \"MH_TABLE\") \"hwm\" " +
- "ON \"cq1\".\"CQ_DATABASE\" = \"hwm\".\"MH_DATABASE\"" +
- " AND \"cq1\".\"CQ_TABLE\" = \"hwm\".\"MH_TABLE\"";
-
- whereClause += " AND (\"CQ_HIGHEST_WRITE_ID\" <
\"MIN_OPEN_WRITE_ID\" OR \"MIN_OPEN_WRITE_ID\" IS NULL)";
-
- } else if (minOpenTxnWaterMark > 0) {
- whereClause += " AND (\"CQ_NEXT_TXN_ID\" <= " + minOpenTxnWaterMark
+ " OR \"CQ_NEXT_TXN_ID\" IS NULL)";
- }
-
- queryStr += whereClause + " ORDER BY \"CQ_ID\"";
-
- queryStr = dbProduct.addLimitClause(MetastoreConf.getIntVar(conf,
ConfVars.COMPACTOR_FETCH_SIZE), queryStr);
- LOG.debug("Going to execute query <{}>", queryStr);
-
- try (ResultSet rs = stmt.executeQuery(queryStr)) {
- while (rs.next()) {
- CompactionInfo info = new CompactionInfo();
- info.id = rs.getLong(1);
- info.dbname = rs.getString(2);
- info.tableName = rs.getString(3);
- info.partName = rs.getString(4);
- info.type =
TxnUtils.dbCompactionType2ThriftType(rs.getString(5).charAt(0));
- info.runAs = rs.getString(6);
- info.highestWriteId = rs.getLong(7);
- info.properties = rs.getString(8);
- info.retryRetention = rs.getInt(9);
- info.nextTxnId = rs.getLong(10);
- if (useMinHistoryWriteId) {
- info.minOpenWriteId = rs.getLong(11);
- }
- LOG.debug("Found ready to clean: {}", info);
- rc.add(info);
- }
- }
- return rc;
- } catch (SQLException e) {
- LOG.error("Unable to select next element for cleaning, " +
e.getMessage());
- checkRetryable(e, "findReadyToClean");
- throw new MetaException(DB_FAILED_TO_CONNECT + e.getMessage());
- }
- } catch (RetryException e) {
- return findReadyToClean(minOpenTxnWaterMark, retentionTime);
- }
+ return jdbcResource.execute(new ReadyToCleanHandler(useMinHistoryWriteId,
minOpenTxnWaterMark, retentionTime,
+ MetastoreConf.getIntVar(conf, ConfVars.COMPACTOR_FETCH_SIZE)));
Review Comment:
MetastoreConf.getIntVar(conf, ConfVars.COMPACTOR_FETCH_SIZE) is repeating in
multiple handlers, should we pass conf a create function to getFetchSize from
conf?
--
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]