Core, Hive: Fix NPE in commit status check when a create commit fails - #17464
Core, Hive: Fix NPE in commit status check when a create commit fails#17464superdiaodiao wants to merge 2 commits into
Conversation
uros-b
left a comment
There was a problem hiding this comment.
No Hive integration test drives the actual create-commit-failure path end-to-end. The predecessor PR #6499 included a TestHiveCommits integration test that mocked persistTable to throw when base==null and asserted no NPE plus correct CommitStatus. The new TestBaseMetastoreTableOperations uses a minimal stub that bypasses the real HiveTableOperations.doRefresh() entirely, so the NoSuchObjectException-swallow-then-refreshFromMetadataLocation(null) wiring is not directly verified. A Hive integration test would cover the full end-to-end path and guard against a future doRefresh refactor silently breaking the fix.
|
Also, no corresponding test in TestHiveViewCommits for the create-view-commit-fails path. The HiveViewOperations null guard is only transitively covered by the base-class stub; a parallel view test would pin the view-specific doRefresh wiring against future refactors. |
Change-Id: Ida46b3caa2ae3c40c99a86df89c36b1442952f2f
|
Added a |
Which issue does this PR close?
What changes are included in this PR?
When a CREATE TABLE commit fails with a non-specific exception (e.g. a Thrift socket timeout from HMS),
HiveTableOperations#doCommitcallscheckCommitStatus(...)to determine whether the commit landed. For a table that was never persisted,doRefresh()swallowsNoSuchObjectException(expected for creates) and refreshes from anullmetadata location, leavingcurrent()asnull.checkCurrentMetadataLocationthen dereferences the null metadata and throws an NPE on every status-check attempt. The NPEs are suppressed (suppressFailureWhenFinished), the status staysUNKNOWN, and the user gets aCommitStateUnknownExceptionrecommending manual intervention - even though the outcome was knowable.This PR null-guards the commit status supplier in two places:
BaseMetastoreTableOperations#checkCurrentMetadataLocation: ifrefresh()yields no metadata, the table does not exist in the catalog, so the new metadata location cannot be current or in history - returnfalse.HiveViewOperations#checkCurrentMetadataLocation: same pattern and null-guard for the view counterpart.With the guard in place:
checkCommitStatusStrictnow correctly resolves toFAILUREfor failed create commits (previously: NPE -> suppressed ->UNKNOWN), so the concurrent-modification branch inHiveTableOperations#doCommitthrowsCommitFailedExceptioninstead ofCommitStateUnknownException.checkCommitStatuscleanly resolves the supplier tofalseand maps it toUNKNOWNper its documented semantics (Core, Hive: Double check commit status in case of commit conflict for NoLock #12637), with no NPE spam in the logs. Whether failed creates should hard-fail in the relaxed path as well is a semantics question intentionally left out of this PR (see the review discussion on AWS, Core, Hive: FixcheckCommitStatuswhen create table commit fails #6499).This revives the core part of #6499, which diagnosed and fixed the same problem in Dec 2022 but was closed by the stale bot without a decision. The code has since moved (the status check was refactored into
BaseMetastoreOperationsby #12637), so the guard now lives incheckCurrentMetadataLocation.Are these changes tested?
Yes - a new core unit test,
TestBaseMetastoreTableOperations, with a minimalBaseMetastoreTableOperationssubclass whosedoRefresh()mimicsHiveTableOperationsfor a never-persisted table (missing table is not an error when no metadata location is known -> refresh fromnull-> current metadata staysnull):strictStatusCheckIsFailureWhenTableWasNeverPersisted- fails without the fix (the NPE is suppressed and the status staysUNKNOWN) and passes with it.statusCheckIsUnknownWhenTableWasNeverPersisted- pins the relaxed-check semantics for the same scenario.Verified locally: the strict test fails on
mainwithout the fix and passes with it;:iceberg-core:testand:iceberg-hive-metastore:testboth pass with the change.