Conversation
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
|
not stale |
|
|
||
| private static long metadataLength(PositionOutputStream stream, String location) { | ||
| try { | ||
| return stream.storedLength(); |
There was a problem hiding this comment.
This might be called on a closed stream since writeMetadata closes the PositionOutputStream via
try-with-resources and then returns it.
There was a problem hiding this comment.
I've reworked writeMetadata to return the length
directly, with the close scoped in a nested try so the ordering is explicit and commented,
and dropped the metadataLength helper.
| } | ||
|
|
||
| @Test | ||
| public void testCommitReportContainsMetadataFileSizeInBytes() { |
There was a problem hiding this comment.
avoid using test prefix in test names.
There was a problem hiding this comment.
Renamed to commitReportContainsMetadataFileSizeInBytes. Thanks.
| * number of added/removed data/delete files | ||
| * number of added/removed equality/positional delete files | ||
| * number of added/removed equality/positional deletes | ||
| * metadata file size in bytes for the committed table metadata file (optional, may be null depending on catalog implementation) |
There was a problem hiding this comment.
"null" is a Java detail; "may be absent" reads better in docs
There was a problem hiding this comment.
Agreed — reworded to "size in bytes of the table metadata file written by the commit,
when available (some catalogs do not write metadata files directly)".
| private String currentMetadataLocation = null; | ||
| private boolean shouldRefresh = true; | ||
| private int version = -1; | ||
| private volatile Long metadataFileSizeInBytes; |
There was a problem hiding this comment.
the size is mutable per-ops-instance state, read later in notifyListeners(). If the same ops instance sees interleaved commits, the reported size can belong to a different metadata file than the reported snapshot
There was a problem hiding this comment.
Agreed, this was the weakest part of the change. Reading shared ops state at report time
meant the value wasn't bound to the snapshot being reported, and it also left a stale size
in place on any commit path that doesn't write a metadata file.
I've moved the capture into the producer, following the newSnapshotId pattern already in
SnapshotProducer#commit:
AtomicReference<Long> metadataFileSizeInBytes = new AtomicReference<>();
...
taskOps.commit(base, updated.withUUID());
metadataFileSizeInBytes.set(taskOps.metadataFileSizeInBytes());
...
notifyListeners(metadataFileSizeInBytes.get());The size is now read in the same thread immediately after the commit attempt that produced
it, and it's scoped to a single producer. A concurrent commit through a shared ops instance
can no longer be attributed to this snapshot at report time, and stale values from earlier
commits are gone. Added eachCommitReportsTheMetadataFileSizeItWrote to cover the
per-commit scoping.
This still routes the value through a field on the ops instance, which I kept because
TableOperations#commit returns void and the write happens inside subclass doCommit
implementations.
Add an optional metadata-file-size-bytes metric to CommitMetricsResult so MetricsReporter implementations can observe the size of the metadata.json written by a commit. Metadata bloat is otherwise invisible through the metrics reporting API, and some catalogs enforce a hard limit on metadata file size. The size is captured at write time from the PositionOutputStream rather than by re-reading the file after the commit, avoiding an extra metadata read on the commit path. SnapshotProducer captures the value per commit attempt so it stays bound to the snapshot being reported, and the metric is omitted when a TableOperations implementation cannot report a write-time size. Co-authored-by: Cursor <cursoragent@cursor.com>
8ea3149 to
1a165e9
Compare
|
All four of your comments are addressed:
Still happy to thread the value through the commit path explicitly instead if you'd prefer |
Summary
metadata-file-size-bytesmetric toCommitMetricsResultand JSON serde.TableMetadataParserand expose it throughTableOperations#metadataFileSizeInBytes().CommitReportwith this metric inSnapshotProducerwhen the table operations implementation provides the value.Why
MetricsReporterconsumers.Compatibility
TableMetadataParser.write/overwrite/internalWritebehavior remains intact.writeAndReturnLength,overwriteAndReturnLength).nullfor table operations that cannot provide write-time size.Test plan
./gradlew :iceberg-core:test --tests org.apache.iceberg.metrics.TestCommitMetricsResultParser./gradlew :iceberg-core:test --tests org.apache.iceberg.metrics.TestCommitReportParser./gradlew :iceberg-core:test --tests org.apache.iceberg.hadoop.TestHadoopCommits./gradlew :iceberg-core:spotlessCheck