Skip to content

Fix OOM by closing writer immediately in one-record-per-file mode - #651

Merged
aindriu-aiven merged 4 commits into
mainfrom
tanbt/gcs-connector-one-writer-per-file-FLEET-6932
Nov 25, 2026
Merged

aindriu-aiven merged 4 commits into
mainfrom
tanbt/gcs-connector-one-writer-per-file-FLEET-6932

Conversation

@tanbt

@tanbt tanbt commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Currently, writers in activeBlobWriters are only closed afterwards, in the loop at the end of flush(). At that point all N writers are open at once, which gives N × ~16 MB of buffers. This usually causes OOM for example with file.name.template={{key}} which is one record per file.

Solution:
Since a one-record file is complete as soon as its single write finishes, the writer can be closed right away, so that only one 16 MB buffer is alive at a time.

Skip:
A topic with huge amount of partitions could also hit this OOM. For example, a node of 4GB memory has ~2GB heap could hit it with a topic of ~128 partitions (2*1024/16).

@tanbt
tanbt requested a review from a team as a code owner November 19, 2026 09:32
@tanbt
tanbt marked this pull request as draft November 19, 2026 09:32
@tanbt
tanbt force-pushed the tanbt/gcs-connector-one-writer-per-file-FLEET-6932 branch from f114f7b to 57d7a95 Compare November 19, 2026 22:12
@tanbt
tanbt requested a balanced review from Copilot November 20, 2026 07:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A failed write skips cleanup and discards the writer, leaking upload and formatting resources while processing continues; failure-safe cleanup and a multi-file failure test are needed.

1 open issue
What changed in this PR

This PR reduces upload-buffer memory pressure in the GCS sink connector by closing completed file writers immediately rather than retaining them until flush ends.

Changes:

  • Close writers after each write for key-based one-record-per-file grouping and positive record-limit configurations.
  • Add channel-counting tests for both modes, including file contents and rotation across intermediate writes.
File Description
gcs-sink-connector/​src/​test/​java/​io/​aiven/​kafka/​connect/​gcs/​GcsSinkTaskTest.java Adds writer-lifetime and record-limit rotation tests.
gcs-sink-connector/​src/​main/​java/​io/​aiven/​kafka/​connect/​gcs/​GcsSinkTask.java Adds immediate writer closure for eligible grouping modes.

Review effort: Balanced

@tanbt
tanbt force-pushed the tanbt/gcs-connector-one-writer-per-file-FLEET-6932 branch 2 times, most recently from 6463d10 to f9707b2 Compare November 20, 2026 10:39
@tanbt tanbt changed the title Fix GCS OOM by closing writer immediately in one-record-per-file mode Fix OOM by closing writer immediately in one-record-per-file mode Nov 23, 2026
@tanbt
tanbt force-pushed the tanbt/gcs-connector-one-writer-per-file-FLEET-6932 branch from f9707b2 to 15a8f0c Compare November 23, 2026 09:17
Avoids holding one upload buffer per file until flush, which could
cause OOM with key-based file name templates. Also close the previous
writer when file.max.records is set and a new file is started, ensuring
one writer at a time.
Avoids holding one upload buffer per file until flush, which could
cause OOM with key-based file name templates. Also close the previous
writer when file.max.records is set and a new file is started, ensuring
one writer at a time.
Avoids holding one upload buffer per file until flush, which could
cause OOM with key-based file name templates. Also close the previous
writer when file.max.records is set and a new file is started, ensuring
one writer at a time.
@tanbt
tanbt force-pushed the tanbt/gcs-connector-one-writer-per-file-FLEET-6932 branch from 15a8f0c to 5cb4caa Compare November 24, 2026 16:46
@tanbt
tanbt marked this pull request as ready for review November 25, 2026 07:07

@aindriu-aiven aindriu-aiven 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 thanks @tanbt

Still only sends them on flush but makes sure we keep the memory in check with the number of active clients for single file writes 👍

@aindriu-aiven
aindriu-aiven merged commit 585b873 into main Nov 25, 2026
10 checks passed
@aindriu-aiven
aindriu-aiven deleted the tanbt/gcs-connector-one-writer-per-file-FLEET-6932 branch November 25, 2026 15:09
aindriu-aiven added a commit that referenced this pull request Dec 2, 2026
Proposed changelog:
  
# Changes
- [fix(s3-sink-connector): sse algorithm properties
](#648)
- [fix(s3-sink-connector) close S3 client on task stop
](#649)
- [Fix offset position for s3 source
connector](75ab69c)
- [Part size configuration to allow users to define the part size used
in s3 sink
connector](fb275fe)
- [Fix OOM by closing writer immediately in one-record-per-file mode
](#651)
- [Upgrade schema registry container to 6.2.4
](#654]

# First Time Contributers
- [avoidik](https://github.com/avoidik)
[Viacheslav Vasilyev](https://github.com/avoidik)
- [binshuohu](https://github.com/binshuohu)
[Binshuo Hu](https://github.com/binshuohu)
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.

3 participants