Skip to content

HIVE-30026: (ACID Compaction) Extend the query for finding potential compactions with ordering - #6768

Open
kuczoram wants to merge 1 commit into
apache:masterfrom
kuczoram:HIVE-30026
Open

kuczoram wants to merge 1 commit into
apache:masterfrom
kuczoram:HIVE-30026

Conversation

@kuczoram

@kuczoram kuczoram commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

I propose to extend the SQL queries which are fetching the potential compaction with an oder by CTC_TXNID. Since the TXNID is an always increasing number, this way we can be sure that the older entries in the COMPLETED_TXN_COMPONENTS tables are fetched first. This way we can make sure that all tables will get into the compaction cycle at once.
Also propose to apply separate limit for the aborted txn cleaup. If the fetch limit is smaller then the compaction candidates, the aborted txns will never be fetched.

Why are the changes needed?

After HIVE-27444, if the number of candidates is bigger than the compactor.fetch.size value, it can happen that the Initiator doesn't schedule all tables for compaction.

For example: we have 4 tables, which are all eligible for compaction, but the fetch size is 2.
In the first initiator run, it will pick two of these tables. It would be expected that during the second run of the initiator it would pick the other two tables, so all 4 tables have been scheduled for compaction.

Since there is no ordering when selecting the tables for compaction, this was not always the case. It could happen that some tables never got compacted.

Also if the number of candidates is bigger than the compactor.fetch.size limit, the aborted txn candidates will never be picked up by the initiator. Because the "remaining budget" will always be 0 in the FindPotentialCompactionsFunction.

Set candidates = new HashSet<>(jdbcResource.execute(new CompactionCandidateHandler(lastChecked, fetchSize)));
int remaining = fetchSize - candidates.size();
if (collectAbortedTxns && remaining > 0) {
candidates.addAll(jdbcResource.execute(new AbortedTxnHandler(abortedTimeThreshold, abortedThreshold, remaining)));
}
This affects only the cases when the aborted txn clean-up is done by the compaction cycle and not just the cleaner.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Unit test

Comment thread ql/src/test/org/apache/hadoop/hive/metastore/txn/TestCompactionTxnHandler.java Outdated
Comment on lines +1077 to +1079
/** Opens two txns against (table), aborts both — leaves two aborted rows in
* TXN_COMPONENTS so the group's COUNT(*) exceeds an abortedThreshold of 1. */
private void abortTwoTableUpdates(String table) throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can abortedThreshold be set to 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can. We can use 0 and in this case one aborted transaction would be enough. I changed a code like this.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants