Skip to content

HIVE-29642: Remove racy test-only counters from PartitionManagementTask#6520

Open
konstantinb wants to merge 2 commits into
apache:masterfrom
konstantinb:HIVE-29642
Open

HIVE-29642: Remove racy test-only counters from PartitionManagementTask#6520
konstantinb wants to merge 2 commits into
apache:masterfrom
konstantinb:HIVE-29642

Conversation

@konstantinb
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

HIVE-29642: Remove racy test-only counters from PartitionManagementTask

Remove the test-only static counters (completedAttempts, skippedAttempts) and their @VisibleForTesting accessors from PartitionManagementTask. Rewrite
TestPartitionManagement.testPartitionDiscoveryTransactionalTable (renamed to testPartitionDiscoveryTransactionalTableConcurrent to highlight the contention scenario) to verify the same properties
via a Log4j2 ListAppender that observes the existing skip and discovery log messages emitted by PartitionManagementTask.run().

Why are the changes needed?

The current test asserts that exactly 2 of 3 concurrent tasks are skipped, using test-only static counters in PartitionManagementTask. The assertion is flaky for two reasons. First, the JVM may
schedule the 3 tasks so they do not actually overlap, in which case no skips happen at all. Second, the counters themselves are racy: the skippedAttempts = 0 reset inside the lock can clear the
value while other threads are running skippedAttempts++ outside the lock. The counters were added in HIVE-20707 for this test and nothing in production reads them.

Does this PR introduce any user-facing change?

No. The only change in production source besides removing the counter fields is dropping the trailing "..#N" counter format from one INFO log message; the message prefix is unchanged.

How was this patch tested?

Ran TestPartitionManagement locally (11 tests, all pass). The counter race was empirically reproduced before the fix by inserting a short Thread.sleep right after lock.tryLock() in production,
which caused the original assertion to fail deterministically; the refactored test does not depend on this timing.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

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.

2 participants