Skip to content

Hive: Fix lock selection during table creation to respect table properties#14236

Merged
pvary merged 6 commits into
apache:mainfrom
s-sanjay:fix-hive-lock-table-creation
Oct 20, 2025
Merged

Hive: Fix lock selection during table creation to respect table properties#14236
pvary merged 6 commits into
apache:mainfrom
s-sanjay:fix-hive-lock-table-creation

Conversation

@s-sanjay

@s-sanjay s-sanjay commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Summary

HIVE_LOCK_ENABLED table property was not respected during table creation. When creating a new table, the lock type was falling back to configuration defaults regardless of what is set in table property

Background

PR #10016 changed lockObject() to use base metadata for lock decisions to ensure concurrent comitters agree on the lock. However, when creating a new table, base is null, which caused the lock decision to fall back to configuration defaults instead of using the table's property set in the SQL.

Changes

  • HiveTableOperations.java: Changed the caller in doCommit() to pass base != null ? base : metadata to lockObject(), ensuring new tables use their metadata properties for lock decisions and only falling back to conf defaults when this is not set ( preserving the same behavior as existing tables )

Test plan

  • Added comprehensive unit and end-to-end tests covering both NoLock and MetastoreLock scenarios during table creation
  • TestHiveCommits.java: Added four test cases:
    • testCreateTableWithNoLockEndToEnd: End-to-end test for table creation with HIVE_LOCK_ENABLED=false
    • testCreateTableWithLockEndToEnd: End-to-end test for table creation with HIVE_LOCK_ENABLED=true
    • testCreateTableWithNoLock: Unit test verifying NoLock is used during table creation with the property set to false
    • testCreateTableWithLock: Unit test verifying MetastoreLock is used during table creation with default/true setting
  • Existing test testChangeLockWithAlterTable continues to verify that lock changes on existing tables use base metadata

Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
@s-sanjay s-sanjay force-pushed the fix-hive-lock-table-creation branch 2 times, most recently from 26188b6 to e67954d Compare October 4, 2025 16:19
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
…rties

When creating a new table passed metadata is null, the lock decision now uses the
new metadata parameter ( since old version is null for creation )
instead of falling back to configuration defaults. Configuration default is still
used when the table property is not set. This ensures the HIVE_LOCK_ENABLED
table property is respected during table creation.
@s-sanjay s-sanjay force-pushed the fix-hive-lock-table-creation branch from e67954d to 2ff05d8 Compare October 7, 2025 05:05
@s-sanjay

Copy link
Copy Markdown
Contributor Author

@pvary @singhpk234 can you take a look ?

Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java Outdated
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java Outdated
boolean updateHiveTable = false;

HiveLock lock = lockObject(base);
HiveLock lock = lockObject(base != null ? base : metadata);

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.

Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
s-sanjay and others added 3 commits October 14, 2025 16:36
…ommits.java


Adressing typo

Co-authored-by: Prashant Singh <35593236+singhpk234@users.noreply.github.com>
…ommits.java

Co-authored-by: Yuya Ebihara <ebyhry@gmail.com>
@s-sanjay

Copy link
Copy Markdown
Contributor Author

@pvary @singhpk234 can you take a look ?

@singhpk234 Thanks for the comments, I have addressed them, can you take another look ?

@deniskuzZ deniskuzZ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm +1

SCHEMA,
PartitionSpec.unpartitioned(),
catalog.defaultWarehouseLocation(newTableIdentifier),
lockEnabled ? ImmutableMap.of() : ImmutableMap.of(HIVE_LOCK_ENABLED, "false"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor, why not be explicit: ImmutableMap.of(HIVE_LOCK_ENABLED, String.valueOf(lockEnabled)

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.

specifically wanted to test the default behavior where lock is enabled.. Ideally there are 3 scenarios

  1. Default - no property - lock is set ( falls back to global conf )
  2. Lock is explicitly disabled
  3. Lock is explicitly enabled
    The test is testing 1 and 2. 3 is being tested in the other test
    We can add 1,2,3 in both these tests..

@s-sanjay s-sanjay Oct 17, 2025

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.

Done.. Added @NullSource so we test all 3 cases for both

.as("Lock mechanism should use (%s)", expectedLockClass.getSimpleName())
.isInstanceOf(expectedLockClass);
} finally {
catalog.dropTable(newTableIdentifier, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do you need to drop, when there is no table create here?

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.

commit ends up creating a new table... so dropping it here

@s-sanjay s-sanjay requested review from ebyhr and singhpk234 October 17, 2025 03:46
… and Lock property missing ( which can implicitly mean lock is enabled ), unless disabled via global property
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java Outdated
Comment thread hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java Outdated
@s-sanjay s-sanjay requested a review from pvary October 18, 2025 03:39
@pvary pvary merged commit c0250c7 into apache:main Oct 20, 2025
42 checks passed
@pvary

pvary commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Merged to main.
Thanks for the PR @s-sanjay and @singhpk234, @ebyhr, @deniskuzZ for the review!

thomaschow pushed a commit to thomaschow/iceberg that referenced this pull request Jan 19, 2026
talatuyarer pushed a commit to talatuyarer/iceberg that referenced this pull request Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants