Hive: Fix lock selection during table creation to respect table properties#14236
Conversation
26188b6 to
e67954d
Compare
…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.
e67954d to
2ff05d8
Compare
|
@pvary @singhpk234 can you take a look ? |
| boolean updateHiveTable = false; | ||
|
|
||
| HiveLock lock = lockObject(base); | ||
| HiveLock lock = lockObject(base != null ? base : metadata); |
There was a problem hiding this comment.
looks reasonable to me, we do similar thing in glue
https://github.com/apache/iceberg/blob/main/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java#L154-L156
…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>
@singhpk234 Thanks for the comments, I have addressed them, can you take another look ? |
| SCHEMA, | ||
| PartitionSpec.unpartitioned(), | ||
| catalog.defaultWarehouseLocation(newTableIdentifier), | ||
| lockEnabled ? ImmutableMap.of() : ImmutableMap.of(HIVE_LOCK_ENABLED, "false")); |
There was a problem hiding this comment.
minor, why not be explicit: ImmutableMap.of(HIVE_LOCK_ENABLED, String.valueOf(lockEnabled)
There was a problem hiding this comment.
specifically wanted to test the default behavior where lock is enabled.. Ideally there are 3 scenarios
- Default - no property - lock is set ( falls back to global conf )
- Lock is explicitly disabled
- 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..
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
why do you need to drop, when there is no table create here?
There was a problem hiding this comment.
commit ends up creating a new table... so dropping it here
… and Lock property missing ( which can implicitly mean lock is enabled ), unless disabled via global property
|
Merged to main. |
Summary
HIVE_LOCK_ENABLEDtable 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 propertyBackground
PR #10016 changed
lockObject()to usebasemetadata for lock decisions to ensure concurrent comitters agree on the lock. However, when creating a new table,baseisnull, which caused the lock decision to fall back to configuration defaults instead of using the table's property set in the SQL.Changes
doCommit()to passbase != null ? base : metadatatolockObject(), 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
testCreateTableWithNoLockEndToEnd: End-to-end test for table creation withHIVE_LOCK_ENABLED=falsetestCreateTableWithLockEndToEnd: End-to-end test for table creation withHIVE_LOCK_ENABLED=truetestCreateTableWithNoLock: Unit test verifying NoLock is used during table creation with the property set to falsetestCreateTableWithLock: Unit test verifying MetastoreLock is used during table creation with default/true settingtestChangeLockWithAlterTablecontinues to verify that lock changes on existing tables use base metadata