KEMBAR78
feat: add AppendableUploadWriteableByteChannel#flush() by BenWhitehead · Pull Request #3261 · googleapis/java-storage · GitHub
Skip to content

Conversation

BenWhitehead
Copy link
Collaborator

Allows blocking the invoking thread until the number of bytes acknowledged by GCS matches the number of written bytes prior to calling flush().

@BenWhitehead BenWhitehead requested a review from a team as a code owner August 22, 2025 19:46
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/java-storage API. labels Aug 22, 2025
Allows blocking the invoking thread until the number of bytes acknowledged by GCS matches the number of written bytes prior to calling flush().

@Override
public void awaitAck(long writeOffset) throws InterruptedException {
lock.lock();

Choose a reason for hiding this comment

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

question: why are we using lock here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Condition confirmedBytesUpdated is tied to the lock instance.

Conditions (also known as condition queues or condition variables) provide a means for one thread to suspend execution (to "wait") until notified by another thread that some state condition may now be true. Because access to this shared state information occurs in different threads, it must be protected, so a lock of some form is associated with the condition. The key property that waiting for a condition provides is that it atomically releases the associated lock and suspends the current thread, just like Object.wait. [1]

When we await the condition on line 903, the lock will automatically be released while the invoking thread waits for the call of await to return.

@BenWhitehead BenWhitehead merged commit 950c56f into main Aug 25, 2025
25 checks passed
@BenWhitehead BenWhitehead deleted the app/flush branch August 25, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-storage API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants