Skip to content

fix(table): close underlying counter in manifest creation - #683

Merged
zeroshade merged 1 commit into
apache:mainfrom
ferhatelmas:more-closing
Jan 19, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
ferhatelmas:more-closing

Conversation

@ferhatelmas

Copy link
Copy Markdown
Contributor

related to #644, fixes #681

@ferhatelmas ferhatelmas changed the title table: close underlying counter in manifest creation fix(table): close underlying counter in manifest creation Jan 19, 2026
@zeroshade

Copy link
Copy Markdown
Member

Was the test able to confirm the case where it didn't close the file without this change?

@ferhatelmas

ferhatelmas commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes, by reverting source changes:

go test ./table/...
--- FAIL: TestCreateManifestClosesUnderlyingFile (0.00s)
    snapshot_producers_test.go:404:
                Error Trace:    /Users/ferhat/Dev/apache/iceberg-go/table/snapshot_producers_test.go:404
                Error:          Should be empty, but was [table-location/metadata/9aa08f09-4164-4a58-a6fa-82b5d7983517-m1.avro]
                Test:           TestCreateManifestClosesUnderlyingFile
                Messages:       all file writers should be closed after createManifest, but these are still open: [table-location/metadata/9aa08f09-4164-4a58-a6fa-82b5d7983517-m1.avro]
--- FAIL: TestOverwriteExistingManifestsClosesUnderlyingFile (0.00s)
    snapshot_producers_test.go:456:
                Error Trace:    /Users/ferhat/Dev/apache/iceberg-go/table/snapshot_producers_test.go:456
                Error:          Should be empty, but was [table-location/metadata/9ce8a0cd-26dd-462e-8998-34679265a621-m1.avro]
                Test:           TestOverwriteExistingManifestsClosesUnderlyingFile
                Messages:       all file writers should be closed after existingManifests, but these are still open: [table-location/metadata/9ce8a0cd-26dd-462e-8998-34679265a621-m1.avro]
FAIL
FAIL    github.com/apache/iceberg-go/table      0.287s
ok      github.com/apache/iceberg-go/table/internal     (cached)
ok      github.com/apache/iceberg-go/table/substrait    (cached)

Comment on lines 495 to 502
out, path, err := sp.newManifestOutput()
if err != nil {
return nil, "", nil, err
return nil, "", nil, nil, err
}

counter := &internal.CountingWriter{W: out}
wr, err := iceberg.NewManifestWriter(sp.txn.meta.formatVersion, counter, spec,
sp.txn.meta.CurrentSchema(), sp.snapshotID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, so the issue is that closing the manifest writer isn't sufficient to close the underlying output writer. Could modify the CountingWriter so that it is an io.WriteCloser and propagates a call to Close to the underlying writer, and then update the ManifestWriter to properly call close on the underlying writer when Close is called? That way we don't need to return the separate closer?

Is that worthwhile over this current solution?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked into that option, because it seems better at first but the way of CountingWriter usage in certain cases would require bigger refactoring. Since this approach was already used by manifests method, sticked to this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. sounds good. Thanks!

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for tracking this down and fixing this!

@zeroshade
zeroshade merged commit b7318e9 into apache:main Jan 19, 2026
11 checks passed
@ferhatelmas
ferhatelmas deleted the more-closing branch January 19, 2026 17:10
ferhatelmas added a commit to ferhatelmas/apache-iceberg-go that referenced this pull request Jan 19, 2026
* more straightforward resource management
* for loops don't accumulate defers
* runs on panics

related to apache#644, apache#683

Signed-off-by: ferhat elmas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning "blob.Writer ... .avro was never closed" followed by error "(code=NotFound)...StatusCode: 404...HostID: , NoSuchKey: "

2 participants