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

changefeedccl: Cleanup resources when closing file #106795

Merged
merged 2 commits into from
Jul 14, 2023

Conversation

miretskiy
Copy link
Contributor

Ensure resources acquired by cloud storage files are released when the sink is closed.

As of #88635, cloud storage uses faster implementation of gzip compression algorithm (along with zstd). This new implementation is sufficiently different from the standard gzip implementation in that it requires the compression codec to be closed, even when the caller is terminating. Failure to do so results in the memory as well as the goroutine leakage.

This resource leakage may become sufficiently noticable if the changefeed experiences many repeated errors.

This PR modifies Close() call to make sure that the underlying compression codecs are also closed (Note: we rely on the high level logic in distSQL to ensure that the processor gets orderly shut down, and the shutdown code calls Close() method; However, there is still exists a possiblity that the shutdown might not be orderly, and in those cases resource leakage may still occur. This possiblity will need to be revisited in the follow on PR).

Fixes #106774

Release note (enterprise change): Fix an issue where the changefeeds emitting to cloud sink with compression may experience resource leakage (memory and go routines) when experiencing transient errors.

Ensure resources acquired by cloud storage files are released
when the sink is closed.

As of cockroachdb#88635,
cloud storage uses faster implementation of gzip compression
algorithm (along with zstd).  This new implementation
is sufficiently different from the standard gzip implementation
in that it requires the compression codec to be closed, even
when the caller is terminating.  Failure to do so results in the
memory as well as the goroutine leakage.

This resource leakage may become sufficiently noticable
if the changefeed experiences many repeated errors.

This PR modifies Close() call to make sure that the underlying
compression codecs are also closed (Note: we rely on the high level
logic in distSQL to ensure that the processor gets orderly shut down,
and the shutdown code calls Close() method; However, there is still
exists a possiblity that the shutdown might not be orderly, and in those
cases resource leakage may still occur.  This possiblity will need
to be revisited in the follow on PR).

Fixes cockroachdb#106774

Release note (enterprise change): Fix an issue where the changefeeds
emitting to cloud sink with compression may experience resource leakage
(memory and go routines) when experiencing transient errors.
@miretskiy miretskiy added backport-22.1.x backport-23.1.x Flags PRs that need to be backported to 23.1 labels Jul 13, 2023
@miretskiy miretskiy requested a review from a team as a code owner July 13, 2023 23:22
@miretskiy miretskiy requested review from HonoreDB and removed request for a team July 13, 2023 23:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@miretskiy miretskiy requested a review from jayshrivastava July 13, 2023 23:23
@shermanCRL shermanCRL requested a review from dt July 13, 2023 23:50
Proactively close compression codecs if an error occurs
when writing to cloud storage file.

While we always call Close on the sink object, this PR
ensures that even if this doesn't happen, the resources used
by compression code are released as soon as an error (during write)
occurs.

Informs cockroachdb#106774

Release note: None
Copy link
Contributor

@jayshrivastava jayshrivastava left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @dt and @HonoreDB)

@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 14, 2023

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Jul 14, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 8d0a804 to blathers/backport-release-22.1-106795: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@miretskiy
Copy link
Contributor Author

22.1 didn't have this functionality; so ignore backport failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

*: Investigate memory/go routine leaks in klauspost/pgzip library
3 participants