Skip to content

[iceberg] Disallow in-memory hive metastore caching#24326

Merged
ZacBlanco merged 1 commit into
prestodb:masterfrom
imjalpreet:disableMetastoreCacheIceberg
Jan 9, 2025
Merged

[iceberg] Disallow in-memory hive metastore caching#24326
ZacBlanco merged 1 commit into
prestodb:masterfrom
imjalpreet:disableMetastoreCacheIceberg

Conversation

@imjalpreet

@imjalpreet imjalpreet commented Jan 7, 2025

Copy link
Copy Markdown
Member

Description

This PR introduces a check to disallow metastore caching for the Iceberg connector. As outlined in the linked issue, this serves as an immediate solution to address the problem. I will follow up with another PR to redesign the metastore cache, enabling caching for specific metadata that does not violate the ACID contract.

Motivation and Context

Fixes #24325

Impact

Presto users will encounter an exception if metastore caching is enabled for the Iceberg connector.

Test Plan

Verified by enabling cache

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

Iceberg Connector Changes
* Remove in-memory hive metastore cache in Iceberg connector. :pr:`24326`

@imjalpreet imjalpreet requested review from a team, ZacBlanco and hantangwangd as code owners January 7, 2025 06:38
@imjalpreet imjalpreet requested a review from presto-oss January 7, 2025 06:38
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 7, 2025
@prestodb-ci prestodb-ci requested review from a team, agrawalreetika and psnv03 and removed request for a team January 7, 2025 06:38
@imjalpreet imjalpreet self-assigned this Jan 7, 2025
@steveburnett

Copy link
Copy Markdown
Contributor

Thanks for the release note entry! Nit in phrasing - suggest following the wording in the Order of Changes in the Release Notes Guidelines. Two suggestions follow, choose the one that best describes your work, or write one yourself.

== RELEASE NOTES ==

Iceberg Connector Changes
* Remove in-memory hive metastore cache in Iceberg connector. :pr:`24326`

or

== RELEASE NOTES ==

Iceberg Connector Changes
* Improve Iceberg connector by disabling in-memory hive metastore. :pr:`24326`

@ZacBlanco

Copy link
Copy Markdown
Contributor

Can you help me understand why this is a problem in the Iceberg connector, but not Hive? Does hive have an additional check to ignore the cache TTL on external updates?

@imjalpreet

Copy link
Copy Markdown
Member Author

Since we store pointers to the metadata files in HMS for Iceberg, having a stale version can corrupt Iceberg tables and violate ACID properties. In contrast, this is not a concern with general Hive tables.

For example, in the case of Iceberg, if a new snapshot is created or a rollback is performed by an external engine, having stale metadata in Presto can lead to issues. Any new operation executed by Presto may corrupt the Iceberg table because Presto will not be operating on the latest version of the table.

I hope this explains the issue.

ZacBlanco
ZacBlanco previously approved these changes Jan 8, 2025
hantangwangd
hantangwangd previously approved these changes Jan 8, 2025
@agrawalreetika

Copy link
Copy Markdown
Member

#24325

@imjalpreet I have a quick question: Even if the external engine is moving forward with the snapshot, it would also change the pointer for metadata location in HMS.
So, in this case, if we need to access the latest snapshot, shouldn't it wait for the cache to expire or until we have an explicit procedure to invalidate the cache like other connectors like Hive?

@imjalpreet imjalpreet force-pushed the disableMetastoreCacheIceberg branch from ed2f71a to 30e76ad Compare January 8, 2025 21:18
@imjalpreet

Copy link
Copy Markdown
Member Author

@agrawalreetika You’re right that when an external engine commits a new snapshot, it updates the metadata pointer in HMS. However, there’s a critical difference between Iceberg and Hive connectors. Iceberg uses a metadata pointer in HMS to track the current snapshot, ensuring strict ACID guarantees. Every query must operate on the latest snapshot to maintain atomicity and consistency. With metastore caching enabled, Presto might use an outdated pointer, querying stale snapshots, and violating Iceberg’s guarantees. This can result in partial data visibility or conflicting and incorrect query results. The example I provided yesterday is one such scenario that can lead to a corrupted table.

Whereas, Hive doesn’t depend on snapshot isolation, so stale cache leads to temporary inconsistencies, not contract violations. Even if operations are performed on the data while the cache is stale, queries will eventually see the updated partitions or data after the cache expires.

agrawalreetika
agrawalreetika previously approved these changes Jan 9, 2025
@agrawalreetika

Copy link
Copy Markdown
Member

@imjalpreet Should we also put a note of this in documentation as well?
https://prestodb.io/docs/current/connector/iceberg.html#metastore-cache

@steveburnett steveburnett left a comment

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.

LGTM! (docs)

Pull branch, local doc build, looks good. Thanks!

@yingsu00

Copy link
Copy Markdown
Contributor

@ZacBlanco Hi Zac, we remember that the perf runs you did earlier this year show Iceberg and Hive performance gap was closed to be within 8%. Was that before or after this PR was merged? We just observed big regression in Iceberg query planning time caused by IcebergHiveMetadata.getTableStatistics() was not able to retrieve table stats from the in memory cache. Did you see that before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metastore caching hides Iceberg table updates when they are performed by another engine

7 participants