Skip to content

feat: Add Bidi write feature - #2343

Merged
JesseLovelace merged 16 commits into
mainfrom
bidi
Feb 21, 2024
Merged

feat: Add Bidi write feature#2343
JesseLovelace merged 16 commits into
mainfrom
bidi

Conversation

@JesseLovelace

Copy link
Copy Markdown
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 review from a team, frankyn and sydney-munro 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 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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2024

}
}

static class BidiObserver implements ApiStreamObserver<BidiWriteObjectResponse> {

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.

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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.

return b.build();
}

private static BidiWriteObjectRequest possiblyPairDownBidiRequest(

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.

Please add unit tests for this helper.

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.

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
Copy Markdown
Contributor

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
Copy Markdown
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

@frankyn frankyn 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.

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

@JesseLovelace
JesseLovelace merged commit 47fde85 into main Feb 21, 2024
@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.

3 participants