Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Iceberg] Fix bugs in Iceberg statistics caching #24480

Merged

Conversation

ZacBlanco
Copy link
Contributor

@ZacBlanco ZacBlanco commented Feb 3, 2025

Description

This PR has two commits which fixes two minor bugs in statistics file caching. The first is related to returning wrong statistics on partial cache misses. The second as to do with missing stats in the reported JMX statistics on the StatisticsFileCache object.

Motivation and Context

Bug fixes. See commit messages for details

Impact

  • New JMX metrics now appear for the StatisticsFileCache bean

Test Plan

  • Added test for partial miss bug fix. It fails without the fix.

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

== RELEASE NOTES ==

Iceberg Connector Changes
* Fix bug with missing statistics when the statistics file cache has a partial miss

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Feb 3, 2025
@ZacBlanco ZacBlanco marked this pull request as ready for review February 4, 2025 01:13
@ZacBlanco ZacBlanco requested review from hantangwangd and a team as code owners February 4, 2025 01:13
@ZacBlanco ZacBlanco requested a review from presto-oss February 4, 2025 01:13
hantangwangd
hantangwangd previously approved these changes Feb 6, 2025
Copy link
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

Thanks for this fix, LGTM. Just one little nit.

hantangwangd
hantangwangd previously approved these changes Feb 6, 2025
tdcmeehan
tdcmeehan previously approved these changes Feb 6, 2025
Copy link
Member

@imjalpreet imjalpreet left a comment

Choose a reason for hiding this comment

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

LGTM, just a small nit.

In the case of partial miss on the StatisticsFileCache, the loaded
statistics were not combined with the cached statistics, causing
discrepancies in query planning
Previously, only the cache stats were available through the JMX plugin
because only the CacheStatsMBean was exported. The file size and
column count distributions were not available. This fixes the issue by
problem by exporting the StatisticsFileCache object instead and
embedding the cache stats object
@ZacBlanco ZacBlanco dismissed stale reviews from tdcmeehan and hantangwangd via 723d643 February 6, 2025 23:06
@ZacBlanco ZacBlanco force-pushed the upstream-iceberg-fix-statcache-bug branch from 0a1a136 to 723d643 Compare February 6, 2025 23:06
@ZacBlanco ZacBlanco merged commit 16b447b into prestodb:master Feb 7, 2025
54 checks passed
@@ -658,6 +658,7 @@ private Map<Integer, ColumnStatistics> loadStatisticsFile(IcebergTableHandle tab
statisticsFileCache.put(new StatisticsFileCacheKey(file, key), value);
finalResult.put(key, value);
});
finalResult.putAll(cachedStats);
Copy link
Contributor

@aaneja aaneja Feb 6, 2025

Choose a reason for hiding this comment

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

nit: Let's add a comment // Include already cached stats (those that were not missing)

statistics = getTableStatistics(queryRunner, session, "lineitem");
RuntimeMetric partialMiss = runtimeStats.getMetrics().keySet().stream().filter(name -> name.contains("PartialMiss")).findFirst()
.map(runtimeStats::getMetric)
.orElseThrow(() -> new RuntimeException("partial miss on statistics cache should have occurred"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead lets use Assert.fail and log the runtimeStats

TransactionId txid = getQueryRunner().getTransactionManager().beginTransaction(false);
Session txnSession = session.beginTransactionId(txid, getQueryRunner().getTransactionManager(), new AllowAllAccessControl());
Map<String, ColumnHandle> columnHandles = getColumnHandles(table, txnSession);
Metadata meta = queryRunner.getMetadata();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use full variable name metadata

.ifPresent(stat -> assertEquals(32, runtimeStats.getMetric(stat).getSum()));
runtimeStats.getMetrics().keySet().stream().filter(name -> name.contains("PuffinFileSize")).findFirst()
.ifPresent(stat -> assertTrue(runtimeStats.getMetric(stat).getSum() > 1024));
// get them again to trigger retrieval of _some_ cached statistics
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert that eviction count was more than 0 ? This proves that the cache was maxed out and not all read statistics have been cached

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.

6 participants