[
https://issues.apache.org/jira/browse/HIVE-30244?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Denys Kuzmenko updated HIVE-30244:
----------------------------------
Description:
*Problem*
When another writer commits between Hive reading an Iceberg table for ALTER
TABLE and HiveIcebergMetaHook loading it, the hook refreshes
{{metadata_location}} in the outgoing table to the current metadata
file (HiveIcebergMetaHook#assertNotCrossTableMetadataLocationChange) but
keeps the {{metadata_hash}} Hive read together with the old file. HMS stores
the new location with the old hash.
For an encrypted table every later load verifies the hash and fails, starting
with the DDL's own Iceberg commit in commitAlterTable:
{noformat}
The current metadata file .../metadata/00002-....metadata.json might have
been modified. Hash of metadata loaded from storage differs from HMS-stored
metadata hash.
{noformat}
The ALTER fails, and the table can no longer be read or committed to until
{{metadata_hash}} is repaired in HMS by hand. No snapshot is lost: the stored
location is the current one.
*Scope*
- Encrypted Iceberg tables ({{encryption.key-id}}) in the Hive catalog.
- DDL whose HMS alter runs: ALTER TABLE ... SET TBLPROPERTIES (for the Hive
catalog the other operation types skip the HMS alter).
- Reproduced with and without {{engine.hive.lock-enabled}}: Hive reads the
table, including {{metadata_hash}}, before the hook takes the lock.
- Pre-existing: the metadata_location CAS added by HIVE-30229 doesn't change
it (same failure with the CAS removed). HIVE-30229 fixed the same defect for
alters without an operation type (stats updates,
TOUCH) by reading location and hash together from HMS.
*Reproduce*
TestHiveCatalogEncryption, with the test storage handler running an action
right before the meta hook's preAlterTable:
# Create an encrypted table, INSERT one row.
# Arrange an Iceberg append (another writer) to commit right before
preAlterTable.
# ALTER TABLE t SET TBLPROPERTIES ('custom_prop'='1') -> fails with the error
above.
# SELECT * FROM t -> fails with the same error.
*Proposed fix*
In the stale-pointer branch, take location and hash together from HMS, as the
stats path does since HIVE-30229 (refreshMetadataLocation also puts the CAS on
that location), instead of overwriting only
metadata_location:
{code:java}
if (!currentMetadata.metadataFileLocation().equals(newMetadataLocation) &&
!context.getProperties().containsKey(MANUAL_ICEBERG_METADATA_LOCATION_CHANGE))
{
LOG.warn(...);
refreshMetadataLocation(hmsTable, context);
} else {
setExpectedMetadataLocation(currentMetadata.metadataFileLocation(),
context);
}
{code}
assertNotCrossTableMetadataLocationChange then takes the HMS table instead of
its parameters. Test: the reproducer above, asserting that the ALTER succeeds
and both rows are readable, for lock-enabled and
lock-disabled tables.
Also worth checking (not verified): a manual metadata_location change on an
encrypted table stores the requested file with the hash of the current one.
Depends on HIVE-30229.
> Iceberg: ALTER TABLE racing a concurrent commit leaves an encrypted table
> unreadable (stale metadata_hash)
> ----------------------------------------------------------------------------------------------------------
>
> Key: HIVE-30244
> URL: https://issues.apache.org/jira/browse/HIVE-30244
> Project: Hive
> Issue Type: Bug
> Reporter: Denys Kuzmenko
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
