deniskuzZ opened a new pull request, #6984:
URL: https://github.com/apache/hive/pull/6984
### What changes were proposed in this pull request?
- `MetadataCachingFileIO` (iceberg-catalog): a `HadoopFileIO` that serves
files in a table's metadata directory from a
process-wide Iceberg `ContentCache`, keyed by location:
- metadata JSON
- manifest lists and manifests
- Puffin statistics (Iceberg's `.stats`, Hive's `column-stats-*.puffin`)
- partition statistics (`partition-stats-*`)
Data and delete files are never cached. Neither are a Hadoop catalog's
`v<N>.metadata.json` (those names come back
when a table is created again at the same location) or
`version-hint.text`. "Metadata directory" means a directory
named `metadata`, Iceberg's default: a table whose `write.metadata.path`
points elsewhere is read uncached.
- `HiveCatalog.initialize` creates it in place of `HadoopFileIO` when the
catalog sets `io.manifest.cache-enabled` and
uses the default `FileIO` (`io-impl` unset or `HadoopFileIO`).
- As a subclass it keeps everything `HadoopFileIO` is:
`HadoopConfigurable`, so serialized tables still skip the
FileIO's Hadoop configuration (HIVE-25843), and `DelegateFileIO`, for
bulk and prefix operations.
- The cache is a transient field, looked up again by its bounds after
deserialization. A table serialized into the
Tez AM and the tasks therefore uses the same cache as the rest of the
process.
- Bounds: `io.manifest.cache.expiration-interval-ms` (default here 1 h,
Iceberg's 60 s expires entries between the
queries of a session), `max-total-bytes` and `max-content-length`
(Iceberg's defaults, 100 MB and 8 MB). One cache
per distinct bounds; one INFO line when it is created.
- The `FileIO` hides `io.manifest.cache-enabled` from Iceberg, which would
otherwise wrap the same manifests in a
second, per-instance cache.
- `IcebergColStatsReader` opens Puffin files with their known size, as it
already did in one place. A cached file is
then served without asking the file system for its length.
### Why are the changes needed?
Every query re-reads its tables' metadata from object storage several times.
HiveServer2 reads the metadata JSON and
the statistics files at compile time. The Tez AM reads the metadata JSON,
manifest lists and manifests again during
split planning.
Measured on a 40-node LLAP cluster (r5d.4xlarge, 12 executors; 1TRC part2,
an Iceberg table with 21 manifests,
4.3 MiB): cache off / on / on / off, 3 runs each, same image, results
identical in every run. With the cache on,
HiveServer2 and the Tez AM that planned the query each held the same 23
files; with it off, no process held a cache.
| mean of 6 runs | off | on | per mirrored half |
|---|---|---|---|
| split planning (Map 1 vertex init, Tez AM) | 2.04 s | 1.63 s (-20 %) |
-0.49 / -0.34 s |
| HiveServer2 compile | 3.04 s | 2.95 s | -0.11 / -0.09 s |
Query time did not change (the halves disagree: -4.4 / -0.2 s on ~95 s). The
saving grows with the number of
manifests and with object-store latency, so tables with frequent small
commits gain more. This is parity with Trino
and StarRocks.
On a hit, a file opened with its length (manifests, Puffin files) costs no
storage request. A file opened without it
still costs one length request, because `ContentCache.tryCache` asks for the
length before it looks in the cache; the
read itself is saved. Those are the manifest lists (Iceberg does not track
their length outside their key metadata),
the metadata JSON and partition statistics. For the same reason the first
read of such a file in a process costs one
length request more than today (`tryCache`, then `FileSystem.open`).
apache/iceberg#16787 lets `tryCache` look in
the cache first (closed without review); it would remove both.
### Does this PR introduce _any_ user-facing change?
Only when `io.manifest.cache-enabled` is set for a Hive catalog that uses
the default `FileIO`. Table metadata files
are then cached across queries in every process that reads them:
HiveServer2, the Tez AM, and the LLAP daemons, which
open metadata files only for metadata-table scans. The default expiry is 1 h
instead of 60 s when
`io.manifest.cache.expiration-interval-ms` is unset. Nothing changes with
the property unset (the default) or with a
custom `io-impl`.
### How was this patch tested?
- `TestMetadataCachingFileIO`:
- every kind of metadata file is read once per process, by any instance,
with its length or without it
- data and delete files (including Puffin deletion vectors and a table
named `metadata`) are read as they are
- Hadoop-catalog version files and `version-hint.text` are read as they are
- a deserialized `FileIO` uses the same cache
- Iceberg builds no second cache
- default and catalog-set bounds; a file over the per-file bound is read
as it is
- `TestHiveCatalog`: the catalog's tables get the caching `FileIO` with the
property (also with `io-impl` set to
`HadoopFileIO`) and a plain `HadoopFileIO` without it. A second catalog
loads a table whose metadata file was made
unreadable, from the cache.
- Each was checked by mutation (11, all caught):
- either read overload not cached
- the metadata-directory check, the Hadoop version-name exclusion or
`.avro` admission dropped
- a cache per instance instead of per process
- the flag passed on to Iceberg
- Iceberg's 60 s default
- the cache field serialized
- the catalog never using the caching `FileIO`, or not when `io-impl`
names `HadoopFileIO`
- A serialized table stays as small as before: 3,616 B with `HadoopFileIO`,
3,648 B with `MetadataCachingFileIO`
(Hive's `serializeTable`, a ~130 KB vertex configuration).
- `TestIcebergColStatsFormat`, `TestHiveIcebergStatistics`.
- Cluster: 40 x r5d.4xlarge, 1TRC part2, cache off / on / on / off, 3 runs
each: results identical; with the cache on,
HiveServer2 and the Tez AM hold the cached files (heap histogram), with it
off no process holds a cache.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]