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

feat: Add Bidi write feature #2343

Merged
merged 16 commits into from
Feb 21, 2024
Merged

feat: Add Bidi write feature #2343

merged 16 commits into from
Feb 21, 2024

Conversation

JesseLovelace
Copy link
Contributor

This adds a new BlobWriteSessionConfig which uses the Bidi streaming feature. It's largely the same as our normal resumable upload flow, with two key differences:

-Instead of closing and re-opening a stream on each flush, we keep a stream open for the life of the upload
-On each flush, it sends a signal to GCS with the "flush" and "state_lookup" flags (which are exclusive to bidi writes) set to true

I still need to run a formal profiling test, but basic profiling in IntelliJ is consistent with the 10-15% increase we're expecting

@JesseLovelace JesseLovelace requested a review from a team as a code owner January 2, 2024 19:14
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: storage Issues related to the googleapis/java-storage API. labels Jan 2, 2024
@JesseLovelace JesseLovelace requested a review from a team as a code owner January 2, 2024 19:17
* {@code 262144 (256 KiB)}
* @return The new instance
* @see #getBufferSize()
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this version needs to be updated to whichever version is used at time of release? (same goes for other occurences).

@@ -0,0 +1,180 @@
/*
* Copyright 2023 Google LLC
Copy link
Member

Choose a reason for hiding this comment

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

2024

@@ -315,4 +456,66 @@ void await() {
}
}
}

static class BidiObserver implements ApiStreamObserver<BidiWriteObjectResponse> {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comments on what this Observer does to support Bidi?

IIUC, this is how you close the stream.

}

if (message.getWriteOffset() > 0 && !message.getFinishWrite()) {
b.clearObjectChecksums();
Copy link
Member

Choose a reason for hiding this comment

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

Does this remove checksums for every message after initial / ignoring last? I would expect checksums to be supplied for intermediate messages as well.

Copy link
Member

Choose a reason for hiding this comment

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

Ignore my understanding was incomplete.

@@ -121,6 +146,27 @@ private static WriteObjectRequest possiblyPairDownRequest(
return b.build();
}

private static BidiWriteObjectRequest possiblyPairDownBidiRequest(
Copy link
Member

Choose a reason for hiding this comment

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

Please add unit tests for this helper.

Copy link
Member

Choose a reason for hiding this comment

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

My original intention was to introduce @VisibleForTesting for the specific comment thread around removing checksum in intermediate messages which is a misunderstanding on my part after talking with Jesse.

image

States that checksum can only be provided in first or last message sent to API so this comment and the one below are obsolete.

}
BidiWriteObjectRequest message =
BidiWriteObjectRequest.newBuilder().setFlush(true).setStateLookup(true).build();
stream.onNext(message);
Copy link
Member

Choose a reason for hiding this comment

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

IIUC the main difference between bidi and non-bidi is that stream.onComplete() is not called until the Observer observes onCompleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, current flow calls onComplete on each flush. Bidi will only call onComplete once, at the end of the upload

Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

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

Remaining comments are nits; PR LGTM, thanks for the offline discussion @JesseLovelace

@JesseLovelace JesseLovelace merged commit 47fde85 into main Feb 21, 2024
22 checks passed
@JesseLovelace JesseLovelace deleted the bidi branch February 21, 2024 18:28
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: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants