Skip to content

fix(client): release vectored read buffers on failure - #313

Open
arnabnandy7 wants to merge 12 commits into
GoogleCloudPlatform:mainfrom
arnabnandy7:feature/vectored-read-api
Open

fix(client): release vectored read buffers on failure#313
arnabnandy7 wants to merge 12 commits into
GoogleCloudPlatform:mainfrom
arnabnandy7:feature/vectored-read-api

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jun 21, 2026

Copy link
Copy Markdown

Type of Change

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

Description

What?

Related to #174

Add backward-compatible readVectored(..., allocate, release) overloads and thread the release callback through the core and client vectored read implementations.

Buffers allocated during vectored reads are now released when a read fails before the range futures are completed exceptionally. Tests cover release-on-failure, no release on successful reads, no release when allocation itself fails, and cached small-object vectored read failures.

Why?

This prevents leaked pooled or direct ByteBuffer instances when vectored reads fail after allocation, aligning the API with newer Hadoop vectored read behavior.

Checklist

  • PR title follows Conventional Commits (e.g., feat(core): ...)
  • All files include the Apache License 2.0 header
  • Documentation has been updated to reflect changes

Generated/Assisted by Agent? Yes

@arnabnandy7
arnabnandy7 requested a review from a team as a code owner June 21, 2026 10:19
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability of vectored read operations by ensuring that allocated buffers are properly released when a read operation fails. By threading a release callback through the core and client implementations, the system prevents potential memory leaks associated with pooled or direct ByteBuffers, aligning the API with modern Hadoop vectored read standards.

Highlights

  • API Enhancement: Introduced backward-compatible readVectored overloads that accept a Consumer<ByteBuffer> release callback, allowing for proper resource cleanup.
  • Resource Management: Implemented buffer release logic in both GcsReadChannel and GoogleCloudStorageInputStream to ensure pooled or direct ByteBuffer instances are released when vectored reads fail.
  • Testing: Added comprehensive test cases to verify that buffers are released on failure, not released on success, and handled correctly when allocation itself fails.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new overload for the readVectored method across several classes and interfaces, including VectoredSeekableByteChannel, GcsReadChannel, SeekableInputStream, and GoogleCloudStorageInputStream, to support a buffer release callback on failure. It also implements the corresponding release logic and adds comprehensive unit tests. The reviewer identified a critical issue in GoogleCloudStorageInputStream.readVectored where the buffer allocation is performed outside of the try-catch block; if the allocator throws an exception, it will propagate immediately and leave subsequent futures uncompleted, potentially causing threads to hang.

…nside the try block, only releases when a buffer was actually allocated, and completes the range future exceptionally on allocator failure. Added a regression test covering allocator failures across multiple cached ranges to ensure no futures are left incomplete.
@arnabnandy7

Copy link
Copy Markdown
Author

@gemini-code-assist initiate re-scan

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Hello @arnabnandy7, I do not have a specific "re-scan" command. However, if you would like me to perform a fresh code review of the current state of your pull request, you can simply use the /gemini review command in a new comment. Let me know if you have any other questions!

@arnabnandy7

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces an overloaded readVectored method across several classes (including GcsReadChannel and GoogleCloudStorageInputStream) to support a Consumer<ByteBuffer> release callback, ensuring allocated buffers are properly cleaned up on failure. It also adds comprehensive unit tests to validate this behavior. The review feedback recommends avoiding hardcoded magic numbers like 1024 in the new test cases, suggesting the use of named constants instead to improve readability and maintainability.

@arnabnandy7

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new overload for the readVectored method across VectoredSeekableByteChannel, GcsReadChannel, SeekableInputStream, and GoogleCloudStorageInputStream that accepts a Consumer release callback. This callback is used to release allocated ByteBuffer instances on failure, preventing potential memory leaks. The changes also include corresponding unit tests to verify the release behavior under various success and failure scenarios, as well as refactoring hardcoded size constants in tests. There are no review comments, and I have no additional feedback to provide.

@prudhvimaharishi

Copy link
Copy Markdown
Contributor

Several pull requests have recently been merged into main. Could you please sync your branch with main and resolve any outstanding conflicts?

@arnabnandy7

Copy link
Copy Markdown
Author

Several pull requests have recently been merged into main. Could you please sync your branch with main and resolve any outstanding conflicts?

Sure I see there's a conflict, I'll resolve it.

…ad-api

# Conflicts:
#	core/src/main/java/com/google/cloud/gcs/analyticscore/core/optimizer/SmallObjectOptimizer.java
@arnabnandy7

Copy link
Copy Markdown
Author

@prudhvimaharishi please review. I've fixed the conflict

@prudhvimaharishi

Copy link
Copy Markdown
Contributor

Can you please sync again.

@arnabnandy7

Copy link
Copy Markdown
Author

@prudhvimaharishi done

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.

2 participants